6

I am a newbie to Automated Testing using WebDriver, so I have a few questions just to clear some things in my head. On a few pages, I saw the samples of executing WebDriver tests on different platforms by just targeting these for the capabilities of the browser or OS.

capability= DesiredCapabilities.firefox();
capability.setBrowserName("firefox"); 
capability.setPlatform(org.openqa.selenium.Platform.ANY);

or

capability= DesiredCapabilities.internetExplorer();
capability.setBrowserName("iexplore"); 
capability.setPlatform(org.openqa.selenium.Platform.WINDOWS);

As mentioned in: Executing tests Concurrently on different OS and Browsers with WebDriver using Java and TestNG

So, if I understand that correctly, actually it is possible to run tests and verify those on the different OS and Browsers just by using the libraries provided by the Selenium?

If so, how accurate are these tests for typical cross browser/platform html/JavaScript issues?

Thank you

Community
  • 1
  • 1
vukovicb
  • 85
  • 2
  • 6
  • You need to actually have those machines and browsers (or use a Grid) to make it work. However, if you can get it set up, they are quite accurate. – Nathan Merrill Nov 21 '13 at 17:13
  • Thank you. Could you point me to the right direction. Where to look for the instructions on this subject? – vukovicb Nov 21 '13 at 17:21

1 Answers1

6

This is a great question. I'm going to try to break this down into smaller packets of information so that it hopefully makes sense for old pros and newbies alike.

Without Selenium Grid:

For starters, it is possible to use individual drivers for all the different browser/OS combinations you wish to run the tests on. The drawback is you have to make some (though usually minimal) code adjustments for each browser's driver. This also means breaking the DRY principle. To learn more about writing these kinds of tests check out this documentation. (Also note that if you wanted to run these tests on each build via CI on something like Jenkins you need to have the actual browsers running on a slave on your own hardware, but these are more the DevOps concerns.)

Using Selenium Grid:

More commonly used for the sort of goals you mentioned (and referenced in the other post you linked to), Selenium Grid is a server that allows multiple instances of tests to run in different web browsers on remote machines. The more intro oriented docs for this are here and more forward looking docs are here.

Running Local or in the Cloud: With Selenium Grid you are going to go one of two ways.

  1. Run on your own hardware locally (or wherever your company has machines to remote into)
  2. Use an online service like Sauce Labs or Testing Bot

A nice "what this might look like in Java" for having an online service provide the browsers is shown in this Sauce Labs page and for Testing Bot here.

Selenium Can be Written in a Ton of Languages: Selenium follows the WebDriver API and for C#, Java, Perl, PHP, Python, Ruby, JavaScript (Node) or other languages, you still can write test scripts in any of these (and they provide the “frameworks” for some of these officially, while others are community driven) and still have the run tests run solidly in all modern browsers.

Concerning Mobile Devices There is some good discussion over here that discusses how "close to the real thing" you want your mobile browser tests to be, since the iPhoneDriver and AndroidDriver are largely based on use through WebView, which is less close to the real thing. They are now finding themselves being replaced by ios-driver, Selendroid, and Appium.

To Sum It Up

So to answer what I think you’re getting at with,

... is possible to run tests and verify those on the different OS and Browsers just by using the libraries provided by the Selenium

the answer is that you can use Selenium Grid and an online service or you will have to use base Selenium/Selenium Server along with a number of other libraries to test all modern browser and OS combinations, but I'm sure many shops do just that because they have the experience and expertise to pull it off.


Alternate (Non-Selenium) Option to Write Once and Test Across Browsers: If you have a team with JavaScript experience and you're looking to hit the same goal of testing across browsers without the overhead of Selenium, Automates JavaScript Unit Testing with Sauce Labs (formerly Browser Swarm) would be a good option.

Community
  • 1
  • 1
Eric D. Johnson
  • 10,219
  • 9
  • 39
  • 46
  • Good question and excellent answer. Just to confirm one thing, that Browser Swarm (http://browserswarm.com/) has gone, right? All I see now is a Russian torrent discussion board. – xpt Jan 05 '15 at 16:32
  • Yup, they have up the Domain, but are now at http://swarm.jquery.org/ so I'll update the link in my answer. – Eric D. Johnson Jan 05 '15 at 19:57
  • Hmm...no, after further investigation, they (Browser Swarm and jQuery's TestSwarm) are actually two different things. From http://www.i-programmer.info/news/167-javascript/6433-browser-swarm-an-easy-way-to-test-javascript.html, *"Microsoft has got together with appendTo and Sauce Labs to create BrowserSwarm, an open source, cloud-based automatic testing tool for JavaScript... BrowserSwarm owes a lot to Mozilla's TestSwarm, which does the same job but isn't open for public use unless you set up a server yourself. BrowserSwarm on the other hand lets you sign up and use its testing facilities."* – xpt Jan 05 '15 at 20:42
  • Thanks @xpt and good digging! I had intended to point to the Sauce Labs solution, you are right, and I mistakenly thought it had trades hands to jQuery, but it's just a similar open source project kicked off by John Resig. – Eric D. Johnson Jan 06 '15 at 19:19