Earn Money in 10 days

Selenium Videos

Protractor In Selenium

Livechat

Sunday, 4 January 2015

How to run your Script on Multiple Browsers In Selenium

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

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
   }}

5 comments:

  1. Mam can you please provide the video lecture for the above......

    ReplyDelete
  2. The 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
    Selenium Training in Chennai

    ReplyDelete
  3. 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.
    hadoop training in chennai

    ReplyDelete
  4. 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

    ReplyDelete
  5. 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 interesting blogs.
    dot net training in chennai

    ReplyDelete

Popular Posts

 
subscribe
Subscribe Us
emailSubscribe to our mailing list to get the updates to your email inbox... We can't wait more to have your email in our subscribers email list. Just put your nice email in below box: