Software Qustions
Software Qustions

Reputation: 221

Run selenium grid test in 2 browsers on one machine (Chrome and Firefox)

I have few tests, i want to run the tests on both Chrome and firefox.

How can i do that?

My code is:

@Test   //Test1
public  void logInFaildTest() {
    GridTest gridTest = new GridTest();
    WebDriver webDriver = gridTest.getWebDriver();//get driver 
    LoginPage logIn = new LoginPage(webDriver, url);
    String userName = "user";
    String pass="pass";
    ...
    webDriver.close();
}

Upvotes: 1

Views: 746

Answers (1)

Sentient07
Sentient07

Reputation: 1290

Create an xml file, testing.xml with the desired parameters and add a Parameters annotation (@Parameters) over your loginfailed method. That would pass all the desired parameters required for your tests

Your testing.xml might look like :

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">

<suite name="TestSuite" thread-count="2" parallel="tests" >

<test name="ChromeTest">

<parameter name="browser" value="Chrome" />

<classes>

<class name="<your class name here>">

</class>

</classes>

</test>

<test name="FirefoxTest">

<parameter name="browser" value="Firefox" />

<classes>

<class name="<Your class name here>">

</class>

</classes>

</test>

<test name="IETest">

<parameter name="browser" value="IE" />

<classes>

<class name="<Your class name here>">

</class>

</classes>

</test>

</suite>

The above xml runs tests in parallel threads across all the three given browsers. In your java code, you should pass the parameters from testing.xml like

@Parameters("browser")

Upvotes: 1

Related Questions