Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6712061
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T08:12:55+00:00 2026-05-26T08:12:55+00:00

We were writing a Selenium test core by using Python webdriver. The main idea

  • 0

We were writing a Selenium test core by using Python webdriver. The main idea is to read from a CSV file with the format:

method_name,parameter 1,parameter 2, parameter 3, ..., parameter n

And then by using reflection, the test core will call the method based on the “method name” and parameters.

def runTest(self):
        try:
            test_case_reader = csv.reader(open(self.file_path, 'rb'), delimiter=',')
            self.logger.info("Running test case %s" % self.file_path)
            for row in test_case_reader:
                if (len(row) > 1):
                    method_name, parameters = row[0], row[1:]
                    parameters = filter(None, parameters)
                    method = getattr(self, method_name)
                    self.logger.info("executing method %s parameters %s" % (method_name, parameters))
                    method(*parameters)
                    self.wait()
        except AssertionError, e:
            self.logger.error(e)
            self.fail("Test case failed: %s" % self.file_path)

The main idea of this script is to provide a better productivity and ease of usage, since QA won’t have to interact with python code to write automation test cases.

But due to human error, sometimes there will be a typo or parameter mismatched.

So I’m going to add a method to verify all CSV files if method names and parameters are correct. Is there any built-in reflection to do this kind of checking?

Update:

For the parameters I’d like to check if parameters count match the required parameters of the method. Some of the methods has optional parameters too.

Example:

method_1 (parameter1, parameter2, parameter3, parameter4 = None, parameter5 = None)

For method_1, valid parameters count are: 3, 4, and 5.

Answer:

Not the perfect & tidy solution but this is the method for now and it’s working:

def verifyFile(self):
    test_case_reader = csv.reader(open(self.file_path, 'rb'), delimiter=',')
    for row in test_case_reader:
        if (len(row) <= 1):
            break

        method_name, parameters = row[0], row[1:]
        if (method_name == ''):
            break

        parameters = filter(None, parameters)
        if not hasattr(self, method_name):
            self.logger.error("test case '%s' method name '%s': Method not found" % (self.file_path, method_name))
            break
        t = inspect.getargspec(getattr(self, method_name))
        max = len(t.args)
        if (type(t.defaults) == NoneType):
            min = max
        else:
            min = max - len(t.defaults)
        if not min <= len(parameters) + 1 <= max:
            self.logger.error("test case '%s' method name '%s': Parameter count not matches (%d - %d)" % (self.file_path, method_name, min, max))
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T08:12:56+00:00Added an answer on May 26, 2026 at 8:12 am

    For the method, you can easily call hasattr to see if it exists. In your case, it’s just :

    for row in test_case_reader:
        method_name = get_method_name() # Your code here
        if not hasattr(self, method_name):
            self.logger.error("No method name %s", method_name)
    

    For the parameter, it’s a little more complex, as python is a dynamic language. You may want to use a parameter checking or a contract library. If the parameter problem is simple enough, there may be a simpler solution. What do you want to check about parameters ?

    EDIT :

    For the parameter, you can use inspect.getargspec to get the number of arguments of the function and check if it’s correct.

    def check_args(func, n):
        args, varargs, keywords, defaults = inspect.getargspec(func)
        max = len(arg)
        min = max - len(defaults)
        if not min <= n <= max:
            # error
    

    This don’t take into account the use of *args and **kwargs but you can easily change it to do so.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm writing an auto testing framework using Selenium. I am trying to test our
I recorded an action using the Selenium IDE and used the File->Export Test Cases
I'm writing a selenium test using the Play! Framework and some tests have common
I am writing a Selenium test in PHP to check the performance of a
I'm writing a selenium grid test suite which is going to be run on
I am writing some UI tests using Selenium and i have a JavaScript Tree
Writing a test app to emulate PIO lines, I have a very simple Python/Tk
I am writing a selenium test and I need to assert that the page
My test uses Selenium to loop through a CSV list of URLs via an
I'm using Selenium RC with chrome-mode for Firefox to automate test cases for a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.