1

I have a set of test cases for different scenarios like login, registration, forgot password etc. I want to execute those test cases against different urls. Currently I have configured in a base page with one url -

public void ARMAppLogin() 
{ 
    try 
    { 
        DriverSetup driversetup = DriverSetup.GetDriverInstance();
        driver = driversetup.IntializeBrowserDriver(); 
        pages = new ArrayList(); 
        String Username = ""; 
        String Password = ""; 
        driver.get("http"); 
        loginpageobject = getPageFactoryObject(LoginPage.class); 
        loginpageobject.LoginAPP(Username, Password); 
    } 
    catch (Exception ex) 
    { 
        ex.printStackTrace(); 
    } 
    finally 
    { 
        System.out .println("Finally block of " + Thread.currentThread().getStackTrace()[1] .getMethodName()); 
    } 
}

I need to run my test cases with different urls. If I want to run the test cases with different urls, such as:

how do I do this?

  • Can you please provide more context as to what you have and what you want to do? This question is not clear. – Chris Kenst Feb 20 '17 at 5:45
  • The use case is the basic use case of proper testing. I create, say, 100 tests that I want to run at the development site e.g. dev.example.com and then later I want to run exactly the same tests at the staging version of the site, e.g. stag.example.com and finally, of course, I want to run the same tests at the production version of the site. – karthikeyan rajendran Feb 20 '17 at 8:44
  • You make sure each setup defines the host to use, e.g. localhost:3000, staging.your-company.com, your-company.com, etc. – Michael Durrant Feb 20 '17 at 11:32
1

Most xUnit testing frameworks support parameterization. This means running a test with different inputs in a loop. I guess you use Java, so here are some idea's, but this should be language and test-framework independent, each should supports something similar.

Parameterized-tests

For jUnit you can find an example in their documentation: https://github.com/junit-team/junit4/wiki/Parameterized-tests

In your case you want to remove the URL from the base-class to a @Parameters Collection which contains different urls.

Config file

Put the URL in a config-file, each environment should have their own config file which defines the URL.

You can use a properties file as described here: https://stackoverflow.com/questions/1318347/how-to-use-java-property-files

Command-line parameters:

I would prefer adding a parameter from the command-line. Each xUnit run would receive a different url. In your base class you would retrieve the URL with something like: System.getProperty("url")

This way you can run them better in parallel.

For a full example check: https://stackoverflow.com/questions/19529849/how-to-add-arguments-to-junit-test-triggered-from-command-line

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