26.7.15

Cross Browser Testing with Selenium

When it comes to CBT [ or Browser Compatability Testing], there are 2 broad aspects

1. Ensuring that functional features of your web site work
2. Ensuring that the layout of your web site is consistent across browsers

If its an internal app and only needs to be tested for a few major browsers and limited versions, then we can easily do this with Selenium; by running our automated functional tests on these different browsers by using the driver of each browser. See my earlier post on how to run tests on different browsers.
In most cases, this should suffice, because it will easily uncover any glaring issues - and they are mostly with JavaScript and IE. The other thing that you would notice is that the same website, runs fastest in Chrome, then Firefox and slowest in IE.

This still leaves out the layout part though. For that, we can use the free library called FighthingLayoutBugs from Google, but even that project is dead as of May 2015 because the only contributor on this project quit!

I still tried to use it though, but its a little flaky and gives large false negatives - you can still try and run it and see what results it gives for your website. But now since its dead, there is no point in using it any more, because future browser versions will not be supported.

Here is a code snippet for playing around with FighthingLayoutBugs. 
Also, remember to download the jar with all the dependencies, and not just the standalone jar [even if you have selenium jars already] because FLB has some additional dependencies that are not documented, and are only available in the 'full' version. 
Also, you will not  be able to download it via maven dependency, since the project is defunct, so add the jar to your class path manually.

import com.googlecode.fightinglayoutbugs.FightingLayoutBugs;
import com.googlecode.fightinglayoutbugs.LayoutBug;
import com.googlecode.fightinglayoutbugs.WebPage;
import org.openqa.selenium.WebDriver;
import org.testng.annotations.Test;
import java.util.Collection;

public class CrossBrowserTestDemo {

    @Test
    public void cbtDemo() {

        WebDriver driver;
        Drivers allDrivers = new Drivers("chrome");
        driver = allDrivers.getDriver();

        String baseURL = "http://www.goolge.com";

        driver.get(baseURL);

        WebPage webPage = new WebPage(driver);

        FightingLayoutBugs fightingLayoutBugs = new FightingLayoutBugs();

        final Collection<LayoutBug> allLayOutBugs = fightingLayoutBugs.findLayoutBugsIn(webPage);

        System.out.println("Number of LayoutBugs found = " + allLayOutBugs.size());

        for (LayoutBug bug : allLayOutBugs) {
            System.out.println(bug);
        }
    }
}   //end of class CrossBrowserTestDemo



Now to deal with the item #2 - If its an external customer facing web site, then the scope of CBT increases drastically - by one account there 260 different browser versions being used globally, and across 3 different OS-es. If you want to certify your website even on 10% of the browsers, across 2 OS-es, it would be a herculean task to get this kind of infrastructure setup in house - no company has such a budget, and specially not for testing! Even if you had someone bankrolling you on this, the effort required to manage such an infrastructure would be prohibitive - you just cannot do this in-house!

But luckily, there are various companies that provide this infrastructure on pay-per-use basis, for as low as 20$/month, and this looks like a more pragmatic approach. Read this for more info.

No comments:

Post a Comment