Currently, I'm running a selenium script in one environment (on-premise) with separate login credentials. There are 5 different users and they have separate login credentials. Suppose there are 50 testcases and login screen will be displaying 50 times while running the script. for an example, first log in to the page and create account and then log out, and again log into the page, edit an existing account then logout. I need to run the same project in a different environment with different URL and login credentials (cloud environment).
will I have to update all 50 testcases to run same script in two different environment since login page is displaying before running each and every test cases? what will be the easiest way to handle this situation?

2 Answers 2


If you already have a script with hardcoded credentials you will have to rework it in any way. Will it be either changing one hardcoded logins to another hardcoded logins or refactoring in order to support some kind of parameterization.

I would create some CredentialsProvider class that would have static method providing the credentials to each of your test (probably an array of credentials so that you would be able to take new piece of creds several times in a test).

What logic would be incorporated in that provider depends on the specific of your test project and your business actions.

  • Credentials are not hardcoded. There is a csv test data file created already for the existing script. will I have to create a separate test data file for new credentials? and then how can I read both data files in the same script ?
    – Anu
    Jan 14, 2019 at 18:21
  • @Anu I'm not getting you then. If you have creds in file already then what is the issue? Could you add code snippets from your project showing your current appraoch?
    – Alexey R.
    Jan 14, 2019 at 19:30
  • @Alexy: Test data file is already available for on-premise environment. I have to run the same script in a different environment (cloud) with a different URL and login credentials. My question is when I run the script in a different environment should I create a separate test data file for new login credentials (cloud env.) or I can add new credentials to the existing (on-premise) test data file. I'm sorry that I'm not able add code snippet since it's in a real time project with a huge framework.
    – Anu
    Jan 14, 2019 at 19:45
  • Separate login credentials file per environment is a valid approach. so is adding a column to your csv that you check in the credentials manager. What's your question exactly?
    – Nat Bowman
    Jan 14, 2019 at 23:36
  • 2
    @Anu please edit this question instead, if you have further information to give.
    – anonygoose
    Jan 15, 2019 at 15:30

A hopefully generic enough approach:

  • If you have credentials stored as string literals/anonymous strings, set up a handler class and make functions to return the correct user based on type and environment. - I find it helpful to store the data in a file and read it from there at runtime, but there are a lot of ways to do this.
  • Call the handler class with the user type (or whatever it is that makes your 5 users different) and the environment under test.

Setting your environment and base URL at runtime should now use the correct environment and users.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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