Take the 2-minute tour ×
Software Quality Assurance & Testing Stack Exchange is a question and answer site for software quality control experts, automation engineers, and software testers. It's 100% free, no registration required.

I want my test case to run once and test n number of inputs at various positions. Suppose If I want to check a login screen for different members like manager,user,admin,e.t.c then instead of running multiple test case for each category with specific input credentials, How can I parameterize the test so that in just one run it would evaluate all cases.

share|improve this question
1  
What unit testing framework are you using? Most of them have ways of doing this –  Yamikuronue May 6 at 13:22

3 Answers 3

up vote 2 down vote accepted

Selenium has no built in support to execute a test case, or collection of test cases, or ability to execute a parameterized test case. Selenium is simply a framework to interact with a web UI. The test execution engine you use to actually kick off your selenium tests varies depending on which language you are using, and even for a specific language there are often multiple competing test execution engines. For example, with Java some popular choices are JUnit and TestNG. For C#, popular choices are Nunit and MSTest. There are other options for ruby, python, etc.

Each one of these test execution engines handles parameterized or data driven test cases differently. You would need to refer to the documentation for whichever tool you are using.

share|improve this answer
    
It was quite helpful. –  razizcool4all May 7 at 4:50
    
Funny that correct answer is considered helpful by OP, but different incorrect answer is accepted. Such is life of experts... –  Peter Masiar May 12 at 23:32

I'm not sure if I get the question correctly, but I would do login function that takes login and password as parameters, and some role-checking function that takes role as parameter. Then I would make list of dicts like

users = [{'login':'login1','pass':'password1', 'role':'admin'},{'login':'login2','pass':'password2', 'role':'user'},(...)]

And finally create tes-case which iterates through users list and calls login and role-checking function for each. It would be something like

for i in users: login(i['login,],i['password']) check_role(i['role'])

Tricky thing is making good role-checking function. This depends on how you can distinguish roles. I would use some element that is diffrent for each role (e.g. role written under username, or some links that are present to certain roles only) and check if it is in the right state.

share|improve this answer

Using TestNG's Dataprovider annotation is a very good way of doing this

This link gives a simple example of how the dataprovider annotation can be used using hardcoded values. You could also have the @dataprovider read an external file, store, and pass the values to your tests.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.