Muhammad Khan
Muhammad Khan

Reputation: 11

how to pass a value from one test case to another in selenium webdriver

I am working on Automation at my work using selenium webdriver. The situation that i'm stuck at is that how can I transfer a value from my TestCase1 to TestCase2. Below is my scenario.

TestCase1 is about creating a account for a new user. When the account is created, a unique account id is created for that user that he can use to login to his account. I can see that unique account id in the logs (unix) and in the confirmation email that the user gets in his email.

TestCase2 is about customer logging into his account and making whatever changes he needs to make e.g. change password, contact info etc.

So the questions is that how can I pass the value of the id that got generated from when the account was created(TestCase1) to my second test case and login as a user.

Earliest reply will be highly appreciated! Thanks!!

Upvotes: 0

Views: 4049

Answers (2)

Subh
Subh

Reputation: 4424

If you are running those two testcases sequentially and you have a way to fetch that account ID then you can have a static variable which you can initialize with that ID in Testcase 1. And, while running Testcase 2, use it as it suits your requirement.

Upvotes: 0

Zoette
Zoette

Reputation: 1291



It's usually considered a good practice to isolate test cases, because if your first test fails for any reason (actual bug or random crash), you don't want your second test (login test) to be stuck.

1st alternative: in your 2nd test, create a setup phase where you send a database query (for instance, if you're using Java, with JDBC) to create a new user. Quite short, but I doubt the id will be sent by mail to your user. Worth trying though.

2nd alternative: create a new user from your GUI in your 2nd test. Quite long, and will fail if you have an actual bug in your sign up form, but looks like a real user action, and you'll be able to retrieve the id by checking the user's mail.

If you really want to share data between tests (you may have a good reason...) you may store test data dynamically in a separate file that your tests will access if needed.

Upvotes: 1

Related Questions