Now a Days it has now become crucial to test web applications on multiple browsers. On different browsers, client components like Javascript, AJAX requests, Applets, Flash, Flex etc.applications on multiple browsers. Also for different browsers you may have different handling on how requests are processed on server side based on the user-agent received from client browser. So just testing your web application on single web browser is not enough. You need to make sure that your web application works fine across multiple browser.So here I will tell you how to test a web application using selenium on multiple Browser.
Four simple steps you need to follow:
Step 1: Create your Script. Using TestNG annotations. Define parameters (using @Parameters) for taking input value i.e, which browser should be used for Running the Test
Step 2: Create a TestNG XML for running your script
Step 3: Configure the TestNG XML for passing parameters i.e, to tell which browser should be used for Running the Test
Step 4: Run the TestNG XML which can pass the appropriate browser name to the Script such that the Test Case is executed in a specified browser
Four simple steps you need to follow:
Step 1: Create your Script. Using TestNG annotations. Define parameters (using @Parameters) for taking input value i.e, which browser should be used for Running the Test
Step 2: Create a TestNG XML for running your script
Step 3: Configure the TestNG XML for passing parameters i.e, to tell which browser should be used for Running the Test
Step 4: Run the TestNG XML which can pass the appropriate browser name to the Script such that the Test Case is executed in a specified browser
Parallel Test in Selenium
Create a TestNG XML for running your test. Configure the TestNG XML for passing parameters
This is the Testng.xml.By this you can test you application on multiple browser mention in testng.xml
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Myparalleltest" verbose="1" parallel="tests" thread-count="2">
<test name="chrometest">
<parameter name = "browser" value ="chrome"/>
<classes>
<class name="paralleltest.CrossBrowsertest"></class> cop
</classes>
</test>
<test name="firefoxtest">
<parameter name = "browser" value ="firefox"/>
<classes>
<class name="paralleltest.CrossBrowsertest"></class>
</classes>
</test>
<test name="internetexplorertest">
<parameter name = "browser" value ="ie"/>
<classes>
<class name="paralleltest.CrossBrowsertest"></class>
</classes>
</test>
</suite>
//You need to add a annotation in you java class.By using @Parameters("browser") you can run your test on multiple browser.
Create a ‘New Class’ file and refer the name to the actual page from the test object, by right click on the above created Package and select New > Class. In our case it as CrossBrowsertest
package paralleltest;import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Parameters;
import org.testng.annotations.Test;
public class CrossBrowsertest {
WebDriver driver;
@Parameters("browser")
@BeforeTest
public void openBrowser(String browser){
if(browser.equals("chrome")){
//If browser is equal to chrome
System.setProperty("webdriver.chrome.driver","C:\\Users\\Hp\\Desktop\\Chromepth\\ChromeDriver.exe");
driver = new ChromeDriver();
}else if(browser.equals("firefox")){
//If browser is equal to firefox
driver = new FirefoxDriver();
}
else if(browser.equals("ie")){
//If browser is equal to ie System.setProperty("webdriver.ie.driver","C:\\Users\\Hp\\Desktop\\ie32bit\\IEDriverServer.exe");
driver = new InternetExplorerDriver();
driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);
}}
@Test
public void doLogin() throws InterruptedException{
driver.get("http://gmail.com");
//Open url
driver.findElement(By.id("Email")).sendKeys("selemiumgyan");
//Enter email id
driver.findElement(By.id("Passwd")).sendKeys("password");
// Enter password
}}






Mam can you please provide the video lecture for the above......
ReplyDeleteThe blog gave me idea to run script on mulitple Browser in Selenium My sincere Thanks for sharing this post and please continue to share this post
ReplyDeleteSelenium Training in Chennai
really nice blog has been shared by you. before i read this blog i didn't have any knowledge about this but now i got some knowledge. so keep on sharing such kind of an interesting blogs.
ReplyDeletehadoop training in chennai
This is my first time i visit here. I found so many interesting stuff in your blog especially its discussion. Thanks for sharing with us. Cloud Computing Training in Chennai | Salesforce Training in Chennai
ReplyDeletenice blog has been shared by you. before i read this blog i didn't have any knowledge about this but now i got some knowledge. so keep on sharing such kind of interesting blogs.
ReplyDeletedot net training in chennai