In our last post we have seen on how we can start our selenium standalone server using gulp. In order to perform cross browser testing it is needed to run our protractor script in different browser. Here we will see how we can do that by running our protractor script in different browser.
Protractor support four major browsers (Chrome, Firefox, IE and Safari).
If we use conf.js file to run our protractor script then we need to add Selenium capabilities object to our conf.js file.
Here capabilities is a json object to add browser name. Note that we have to change the browser name here to run our protractor script to our desired browser. If we use ‘chrome’ in place of ‘firefox’ then it starts running our script in chrome browser. Same for ‘safari’ and ‘internet explorer’. We can use two other keys with ‘version’ and ‘platform’.
Example : We use our previous project that we have developed in our previous post. Here we modify the conf.js file
Step 1 : Open the project and open conf.js file.
Step 2 : Add the following code for firefox browser. Note that chrome browser is by default for protractor. So we don’t need to mention it. If we implement firefox browser, we can add the following code in our conf.js file.
Now conf.js file looks like the following,
Step 3 : Now run the script by using the following command,
Note that we have to run Selenium standalone server before that.
When it starts running, opens the firefox browser and execute the steps.
If we want to run our scripts in multiple browsers at a time then we use multicapabilities object. For this we add the following code.
Now the conf.js file will be,
Now run the script. We see two browser window opens and execute the script. Note that we must have chrome and firefox installed on our machine.
In case of internet explorer, things are different.
Step 1 : Open the terminal and type the following to install IE driver
Step 2 : Add multicapabilities object to conf.js file like the following where browser name is ‘internet explorer’.
Step 3 : Run selenium standalone server.
Step 4 : Now run the script by using the following command,
We see IE browser window opens and execute the script.
In our next posts we will show how we can manage it other ways.
Happy UI Testing with Protractor!!!
No comments:
Post a Comment