Cross Browser Testing in Selenium

Cross Browser testing is the very important concept for Web Application Testing. In Cross browser testing we perform our Test Cases on Multiple Browser to ensure that Website behavior is same across all browser applications.

 

Now the question is how can we perform this in Automation Testing using Selenium API. We have already seen in last tutorials ‘How to Invoke Chrome or IE‘ browsers. Now we will see, How we can invoke the browsers dynamically without changing the code.

 

To perform this we will parameterize our test case. (We have seen ‘How to Parameterize the Test case as well).

 

Video Tutorial:

If you liked this video, then please subscribe to our YouTube Channel for more video tutorials.

 

Test case — Verify that FaceBook browser compatibility.

Solution —  To perform this Test case we need to open the facebook in all browsers and verify that we are landing on the correct page or not.

 

Call Browser Dynamically using Selenium

The above code will run the test case on defined browser in testng.xml file. So here we are performing cross-browser Testing without changing the code.

 

Let’s understand the above code. In the @BeforeTest method, we are invoking the target browser(Which is declared in testng.xml).

@Test annotation will execute the test in invoked method. In Test Method we are verifying the page title as well, Here we are using getTitle() method. This method returns the title of currently open page. Using Assertion we are performing the verification step. 

 

We have seen how to invoke Chrome or IE  , But here we are not calling browser’s exe from local.

You noticed We are using getProperty() method. To invoke Chrome or IE like this you need to Copy your chromedriver.exe and IEDriverServer.exe files in your project. After pasting these exe files you can execute these code.

 

Note- It is good to keep chromedriver.exe and IEDriverServer.exe in your project and use them using getProperty() method. Because when you will check-in your code on the server you don’t need to change the code to execute over the server. If you place your local path in code then it will fail over server because the server is unknown to your local directories.

 

Let’s see the testng.xml structure as well.

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

<suite name=”YahooTestSuite”>

    <listeners>

        <listener class-name=”org.uncommons.reportng.HTMLReporter” />
        <listener class-name=”org.uncommons.reportng.JUnitXMLReporter” />
    </listeners>

    <test name=”Verify the Title of Facebook.com”>

        <!– Declare Parameters –>
        <parameter name=”Browser” value=”Chrome” />

        <classes>
            <class name=”com.Seleniumbix.WebDriver.FacebookMultiBrowserTest” />
        </classes>
    </test>

</suite>

 

Now you can copy this code and execute this on your local machine. It’s highly recommended to practice each and every tutorial to make perfect in automation using Selenium.

You can change the parameter value and execute the above code in other browsers as well.

0 Comment

Leave a Reply