How can I perform multi-browser testing using Selenium TestNG

0 votes
How can I perform multi-browser testing using Selenium TestNG?
Jul 22, 2019 in Selenium by Nutan
2,064 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, 2019 by Abha
• 28,140 points

Related Questions In Selenium

0 votes
1 answer

How can I travel forward and back in a browser using selenium?

You can use the Navigate interface to ...READ MORE

answered Dec 31, 2018 in Selenium by Nabarupa
12,143 views
0 votes
1 answer

How can I refresh a browser window in different ways using Selenium Webdriver?

Hello Piyush, you can refresh a browser ...READ MORE

answered May 29, 2019 in Selenium by Anvi
• 14,150 points
3,185 views
–1 vote
1 answer
0 votes
1 answer

How can I perform multiple selection of options in a dropdown using Select class in Selenium?

Hey Priyansh, you can select multiple options ...READ MORE

answered Jul 8, 2019 in Selenium by Anvi
• 14,150 points
3,130 views
0 votes
2 answers

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,500 points
13,421 views
0 votes
2 answers

Problem while using InternetExplorerDriver in Selenium WebDriver

enable trusted connection  in internet explorer by ...READ MORE

answered Aug 31, 2020 in Selenium by Sri
• 3,190 points
8,998 views
0 votes
2 answers

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

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

answered Sep 4, 2020 in Selenium by Sri
• 3,190 points
2,771 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,910 points
7,110 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 3, 2019 in Selenium by Abha
• 28,140 points
9,325 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP