How can I perform multi-browser testing using Selenium TestNG?

0 votes
How can I perform multi-browser testing using Selenium TestNG?
Jul 22 in Selenium by Nutan
50 views

1 answer to this question.

0 votes

Hi Nutan, you can use TestNG to perform multi-browser testing, though you have to execute selenium web driver through testing.xml only. You first need to create a test script to test facebook login page:

public class TestCase1 {

// Here Browser parameter we will take from testng.xml

@Test
@Parameters("Browser")
public void test1(String browser) {

if(browser.equalsIgnoreCase("FF")){
System.setProperty("webdriver.gecko.driver", "./drivers/geckodriver.exe");
WebDriver driver=new FirefoxDriver();
driver.manage().window().maximize();
driver.get("http://www.facebook.com");
driver.quit();
}

else if(browser.equalsIgnoreCase("IE")){
System.setProperty("webdriver.ie.driver", "./drivers/iedriver.exe");
WebDriver driver=new InternetExplorerDriver();
driver.manage().window().maximize();
driver.get("http://www.facebook.com");
driver.quit();
}

else if(browser.equalsIgnoreCase("GC")){
System.setProperty("webdriver.chrome.driver", "./drivers/chromedriver.exe");
WebDriver driver=new InternetExplorerDriver();
driver.manage().window().maximize();
driver.get("http://www.facebook.com");
driver.quit();
}
}
}

Now, create a TestNG.xml file to pass the parameters:

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

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

<---Here parallel is an attribute which specify the mode of execution and thread-count specify how many browser should open--->

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

<test name="Test">
<parameter name="Browser" value="FF" />
<classes>
<class name="SampleTestcases.TestCase1"/>
</classes>
</test>

<test name="Test1">
<parameter name="Browser" value="IE" />
<classes>
<class name="SampleTestcases.TestCase1"/>
</classes>
</test>

<test name="Test2">
<parameter name="Browser" value="GC" />
<classes>
<class name="SampleTestcases.TestCase1"/>
</classes>
</test>

</suite>

And that's it, run the testng.xml file and it will run 3 test cases, testing all 3 browsers.

answered Jul 22 by Abha
• 27,180 points

Related Questions In Selenium

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

Finding WebDriver element with Class Name in java

The better way to handle this element ...READ MORE

answered Apr 10, 2018 in Selenium by nsv999
• 5,110 points
1,012 views
0 votes
1 answer
0 votes
1 answer

What is the role of TestNG & JUnit frameworks in Selenium?

Well TestNG and JUnit are test frameworks ...READ MORE

answered Apr 18, 2018 in Selenium by king_kenny
• 3,650 points
344 views
0 votes
1 answer

Geo-location microphone camera pop up

To Allow or Block the notification, access using Selenium and you have to ...READ MORE

answered May 11, 2018 in Selenium by Samarpit
• 5,130 points
1,155 views
0 votes
1 answer
0 votes
1 answer

How can I send some data to a Prompt Alert box using Selenium Webdriver?

Hey Abhishek, you can use sendKeys() method ...READ MORE

answered Jul 2 in Selenium by Abha
• 27,180 points
86 views