Click here to Skip to main content
15,886,055 members
Articles / Programming Languages / C#

Selenium Series: Chapter 3 - Test Using Internet Explorer, Chrome, Edge and Firefox

Rate me:
Please Sign up or sign in to vote.
3.67/5 (2 votes)
16 Mar 2017CPOL4 min read 9.4K   1  
Testing using Chrome, Internet Explorer, Edge, and Firefox!

Introduction

The age old question of we've written an automated test and it runs perfectly in Firefox, and we're proud of that test, however your audience use Chrome and / or Internet Explorer, so how can I run it on those browsers?

Let's answer this golden question in Web Automation!

Series Links

Background

Historically, WebDriver and Selenium have been interwoven with Firefox, however Selenium 3.0 has changed that. WebDriver has abstracted away from Firefox first strategy as a rule of thumb now, giving us, the QA tester, the choice to download and use the driver we want which I think is a great change. So what does that mean for us?

In order for Selenium to execute against a browser, we have this thing called a RemoteWebDriver, and they are the following found in the below location:

URL: http://www.seleniumhq.org/download/
Section: Third Party Drivers

What I tend to do and you'll see in the solution is the following drivers are downloaded from the URL above on the SeleniumHq site and added in the test suite solution shown quickly below, showing the 4 drivers Chrome, Firefox, Internet Explorer, and Microsoft Edge.

Let's Test in Many Browsers!

First thing first is attached to the article is the source code of Chapters 1, 2 and 3 of the Selenium Series, so this will be required to be downloaded and we can work through examples and you can use the source code to run across multiple browsers, pretty cool place to begin! Download can be used from the SourceFile in Chapter 2.

Once downloaded and opened, you need to build the project and in the Test Explorer as we're using MsTest search for the trait as shown below Trait: "CHAPTER-3". There, you will see 4 tests and each execute on a different browser Window.

Note: It should be said if you need all Chrome, Firefox, Internet Explorer and Edge installed for all 4 tests to work, but let's say you have just Chrome and Internet Explorer installed, you'd just run those two tests. Simple right?

Let the fun begin, so we have 4 tests, 4 browsers and the only difference really in our tests is one line of code right now in each test as shown below.

In the solution, if you look through the tests, you'll notice how we call the browser differs such as:

C#
// Chrome
var driver = new ChromeDriver();

// Microsoft Edge
var driver = new EdgeDriver();

// Internet Explorer
var driver = new InternetExplorerDriver();

// Firefox
var driver = new FirefoxDriver();

The above code snippets of how we create our webdriver, driver, to control the browser is done by saying new {BrowserType}. Once we've done this and we initialize the driver to be Internet Explorer, Edge, Chrome or Firefox, our test will use that browser for the whole duration of the test, pretty awesome!

So what you can do now is execute the tests in Chapter 3 as shown in the Test Explorer for the browsers you have installed on your machine. So fingers crossed all of them, if not, that's no worries do the subsection, i.e., Chrome and Firefox if those are the only ones you have installed.

....... Hoping for a full Green Pass test explorer similar to mine and that you've seen the test suite opening different browsers and executing tests successfully!

What Next?

So we've successfully executed tests in multiple browsers and seeing the code snippet above, we know this is actually really easy to do in Selenium and not maybe as hard or scary as we thought, right?! So why not change the Internet Explorer Test yourself and try to make it run in Chrome without my help here?

Successful run of Internet Explorer Test in Chrome as you've modified the driver? Of course, as it's pretty easy and you've got this!

Not so scary to execute tests against multiple browsers now which is what I'm hoping you've gotten out of this article and I would love to hear your comments.

Quick Tip

I'd go and produce some tests in Internet Explorer, Chrome and Firefox and what you may find is they pass in Chrome but not Internet Explorer in certain instances. The reason being?

We need to remember not all browsers are the same and treat the user / tests the same. An example is in Internet Explorer vs Chrome the way JavaScript is rendered and used is different as both Microsoft and Google have their own JavaScript engines. This means drop down values, and sending of values into fields can sometimes differ and in general.... Internet Explorer is a little bit slower so we need our tests to have WebDriver waits in there at times to cope with a Cross Browser Test suite. More to come on this but I wanted to mention if you see failures due to your test suite implementation.

Hope this has been an informative and fun article and gets you testing cross browser in Selenium!

Any questions or feedback, as always please let me know.
Cheers,
Sean

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Tester / Quality Assurance
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
-- There are no messages in this forum --