📢 Are you a TestProject user looking to migrate to an open source alternative?

Learn more
Cross Browser Testing using Selenium WebDriver

Cross Browser Testing using Selenium WebDriver – Testsigma

When you build a web application, it must work well across various OS platforms and browsers. In simple terms, verifying the web application’s performance and compatibility is necessary. In recent trends, automation testing is a top-notch framework that automates the effort of manual testing. Selenium is one such tool that fits well in this scenario. In this blog post, let’s understand how to perform cross browser testing using Selenium WebDriver.

Overview of Cross Browser Testing using Selenium

It’s not fair to ask users to access your application with a specific browser. To reach out to the maximum number of users, you need to cater to all the devices and platforms they use. Since there are various web browsers in the market, the choice of usage should be left to the user. Different users use different browsers based on their comfort. It’s the job of the test engineer to ensure that the application works well on all the widely used browsers. This urges the need for testing the application code on different platforms. This is where cross browser testing comes into the picture.

The type of testing which verifies that a website works accurately in all browsers is cross-browser testing. The main goal is to verify that the website you’re developing runs perfectly on all targeted browsers and operating systems. Testers can either run manual tests or use automated tools like Selenium WebDriver. It helps save you time, as you need not reinstall your browsers multiple times.

Why is Cross Browser Testing important?

Consider a scenario where you’re trying to access an e-commerce website. Let’s assume you’re doing it for the first time from your MacBook. Next, you open the Safari web browser, enter the URL, hit Enter, and wait for it to load. But, the website doesn’t show up. You check your connectivity and reload, just to see the same screen.

Finally, you assume the website has a bug or believe that the website is broken, and try to find an alternative.

Browser vendors usually follow Open Web Standards, but they have their interpretations of them. Since they render HTML, CSS, and JavaScript uniquely, thoroughly debugging your website’s source code is not enough to ensure that your website will behave as expected on different browsers.

Thus, it falls to web developers to abstract browser differences. Cross browser testing helps by pointing out browser-specific compatibility errors for you to debug them quickly. It helps ensure that you’re not alienating a significant part of your target audience–simply because your website does not work on their browser-OS configuration.

Learn More – Cross Browsing Testing Alternatives

Introduction to Selenium

Selenium is an open-source framework for browser automation. The prime focus of Selenium is to simulate the actions of users within the application. This helps you execute test cases on the applications. These test results help you identify the bugs in your application. Selenium is not just a single software program; it’s a suite. It comes with varied options like:

  • WebDriver: A collection of language-specific bindings to drive a browser.
  • IDE: Add-on that will do a simple record and playback of interactions with the browser.
  • Grid: To run the tests against a vast combination of browsers/OS.

In this blog post, let’s see how Selenium benefits Cross browser testing.

How to Go About Testing?

Cross-browser testing is part of application testing but a little more work than regular testing. You can actually run the cross-browser tests manually. However, manual testing is time consuming. Therefore, including cross-browser testing multiplies that time. This is because of the manual effort to test the application on different browsers and operating systems.

Even if you consider writing code for this, you’ll have to add lines for different combinations of browsers. You should also install all the browsers and browser drivers to run the code on a wide range of operating systems to ensure confidence in your test results. Either way, it’s a chore. Fortunately, cross-browser testing tools make this easy.

Thus, this provides a consistent and high-quality user experience across all the devices and browsers that the customers use.

Cross Browser Testing using Selenium

As mentioned earlier, Selenium is the most popular automated testing tool for various functions. Cross-browser testing is one of the many features supported by Selenium.

  1. Selenium WebDriver enables you to automate test cases on Internet Explorer, Firefox, Chrome, and Safari browsers.
  2. You can integrate the TestNG framework with Selenium WebDriver to run your test cases on different browsers.
  3. You can analyze performance for cross-browser compatibility.

Read on Selenium Based Automation Testing to gain deeper insights into the various components of Selenium.

Next, let’s see how to perform cross browser testing using Selenium.

How to Perform Cross Browser Testing using Selenium?

Let’s write a simple code to understand how it works.

Requirements:

  1. Java Installation
  2. Integrated Development Environment (IDE) installed. In this case, let’s use Eclipse IDE
  3. Selenium Server Configuration
  4. TestNG integration
  5. Browser Drivers for Chrome, Firefox, Edge, etc.

Flow:

In the below program, let’s log in to the Testsigma website.

The task here is to check for cross-browser compatibility on 3 different browsers. They are Google Chrome, Mozilla Firefox, and Microsoft Edge. To do this, let’s set the system properties for all the 3 browsers as shown below. Finally, using locators allows you to perform actions on the website.

Code:

package test;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.edge.EdgeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Parameters;
import org.testng.annotations.Test;
public class TestScript {
WebDriver driver;

@BeforeTest
@Parameters("browser")
public void create(String browser) throws Exception{
//Checking for 'firefox' parameters
if(browser.equalsIgnoreCase("firefox")){
//creating firefox instance
System.setProperty("Add the path to the firefox/gecko driver");
driver = new FirefoxDriver();
}
//Checking for 'chrome' parameters
else if(browser.equalsIgnoreCase("chrome")){
//Creating chrome instance
System.setProperty("Add the path to chrome driver");
driver = new ChromeDriver();
}
else if(browser.equalsIgnoreCase("Edge")){
//Creating edge instance
System.setProperty("Add the path to edge driver”);
driver = new EdgeDriver();
}
else{
//If the browser is not passed then throw the below exception
throw new Exception("Invalid browser");
}
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
}
@Test
public void testParameterWithXML() throws InterruptedException{
driver.get("https://www.testsigma.com");
WebElement Signin = driver.findElement(By.linkText("Login"));
//Hit login button
Signin.click();
Thread.sleep(4000);
WebElement uname = driver.findElement(By.id("loginUsername"));
//Fill user name
uname.sendKeys("your email id");
Thread.sleep(4000);
WebElement pwd = driver.findElement(By.name("password"));
//Fill password
pwd.sendKeys("your password");
Thread.sleep(6000); 
WebElement  = driver.findElement(By.linkText("SIGN IN));
//Hit search button
Next.click();
}
@AfterTest
public void quit(){
driver.close();
}
}

To execute the above test script, you need a TestNG XML file that contains the dependencies of the above class file. In this case, I have created an XML file to reference the above parameters.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="TestSuite" thread-count="2" parallel="tests" >
<test name="ChromeBrowser_Test">
<parameter name="browser" value="Chrome"/>
<classes>
<class name="test.TestScript">
</class>
</classes>
</test>
<test name="FirefoxBrowser_Test">
<parameter name="browser" value="Firefox" />
<classes>
<class name="test.TestScript">
</class>
</classes>
</test>
<test name="EdgeBrowser_Test">
<parameter name="browser" value="Edge" />
<classes>
<class name="test.TestScript">
</class>
</classes>
</test>
</suite>

Now, on executing this code as TestNG Test, browser drivers will instantiate the respective browsers and perform the login action on the Testsigma website.

This is how it works. Now let us understand how Testsigma eases the process of writing automated test code.

Click here to gain deeper insights into the cross browser testing aspects.

Testsigma to the Rescue

Modern teams need automation testing to build and deploy bug free applications efficiently. Achieving test automation is complicated due to multiple framework setups, complex coding, etc.

Testsigma, a unified test automation platform on a cloud, simplifies and accelerates automation testing for web applications, mobile applications, and APIs. With Testsigma, test engineers, QA team, and business users can create, run and maintain automated tests easily. Simply put, anyone can test high-quality software with zero coding skills.

Using simple English commands powered by NLP (Natural Language Processing) engine, you can write tests in minutes. With NLP and Integrated API testing capabilities, teams can achieve in-sprint test automation with minimum effort. With Testsigma, maintaining different servers, operating systems, and mobile devices is no longer a problem.

It comes in two versions. One is free for a lifetime and meant for basic apps. The second one is the pro version which is free for 30 days and later charges a monthly fee.

Quick Read: Selenium vs. Testsigma

Testsigma and Cross Browser Testing

One can run tests in parallel on different operating systems, browsers, and browser versions. Testsigma offers more than 200 Android and iOS operating systems to run tests. This is how the platform replaces the effort of coding with simple English instructions and built-in functionality.

Since Testsigma offers over 200 operating systems and browsers, you can perform cross-browser testing with just a few clicks. This reduces time consumption and increases performance.

Why wait? Signup for a trial version of Testsigma to explore the features it provides.

Wondering what makes Testsigma an ideal tool for automated testing? Do take a look at this post to find out.

Conclusion

Cross browser testing lets you check for website compatibility. Selenium is one such automated testing tool, which serves this purpose. It’s up to the developers to deliver an end-user experience that’s consistently delightful across a multitude of browsers and devices.

Testsigma is a fully-managed test automation platform that includes all the core features of the open-source platform, without any infra-requirements. It offers enhanced security, extensive test lab, project and review management, powerful reporting capabilities, etc. Organizations can therefore consider using Testsigma to have a hassle-free and extensive testing process, especially for cross browser testing.

Thus, this brings us to the end of our post on Cross Browser Testing using Selenium WebDriver. If you have any questions or suggestions, drop them in the comment section below.


Test automation made easy

Start your smart continuous testing journey today with Testsigma.

SHARE THIS BLOG

RELATED POSTS