Showing posts with label gulp. Show all posts
Showing posts with label gulp. Show all posts

Sunday, April 24, 2016

Protractor : How to run protractor script in different browsers

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.

image

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.

image

Now conf.js file looks like the following,

image

Step 3 : Now run the script by using the following command,

image

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.

image

Now the conf.js file will be,

image

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

image

Step 2 : Add multicapabilities object to conf.js file like the following where browser name is ‘internet explorer’.

image

Step 3 : Run selenium standalone server.

[image71.png]

Step 4 : Now run the script by using the following command,

image

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!!!

Thursday, March 31, 2016

Protractor : How to start selenium server using gulp

In our previous post we see how we can run multiple javascript file. There we have started our selenium server by typing the following command at the terminal and pressing enter button. Every time we have to run it manually when executing our protractor script.

[image71.png]

Gulp can handle the problem and it can run automatically when our protractor scripts start executing.

We have to add the following code in our gulpfile.js file.

Step 1 : At first add two variables like the following,

image

First one is for updating webdriver and second one is for starting Selenium server.

Step 2 : Now add this two task like the following,

image

Step 3 : Now modify default gulp.task() method.

image

Note that we have added two variables ‘webdriver_update’ and ‘webdriver_standalone’ as gulp.task() argument so that it runs first and then run the default task that means protractor script.

Step 4 : Now gulpfile.js file looks like the following,

image

Step 5 : Now run the protractor script using only gulp command and do not need to run selenium standalone server using manual command.

image

It first update selenium webdriver and then start the selenium standalone server. After that it starts executing protractor script.

image

That’s all from here. We will discuss more on gulp and protractor in future.

Happy UI Testing with Protractor!!!

Monday, February 29, 2016

Protractor : How to run multiple protractor script Files using Gulp

In our last post we have discussed on running protractor script using gulp. In this post we will show how we can run multiple JavaScript files that contains protractor script.

For this purpose we will use our previous project that we have developed to implement gulp on protractor script.

Step 1 : Open the project using webstorm editor and add a new folder by right clicking on Project name and going to File>New>Directory

image

Step 2 : Enter the folder name as “test” and click Ok button.

image

Step 3 : Now move the test.js file to “test” folder by dragging the file and drop it to test folder. Move window is displayed and click OK button. Now test.js file is moved to test folder.

image

Step 4 : Rename the test.js file as testadd.js by right clicking on file name and going to Refactor>Rename.

image

Enter the file name “testadd.js” and click Refactor button.

image

Step 5 : Add another js file in the test folder by right clicking on folder and going to File>New>JavaScript File.

image

Step 6 : Enter file name as “testsub.js” and click on Ok button.

image

Step 7 : Open testsub.js file for subtraction and write the following code,

image

Note that above scripts subtract two numbers.

Step 8 : Now there are two files to run in the test folder. We can handle it by modifying gulpfile.js.

Step 9 : Open gulpfile.js and modify gulp.src() method by writing the following code,

image

Note that above expression means include all files as source files in the “test” folder that has .js extension. So it will execute all the .js extension files in the “test” folder.

Step 10 : Now gulpfile.js looks like the following,

image 

Step 11 : Now go to terminal and start selenium server using the command,

[image71.png]

Run the following command to run our protractor script.

gulp

image

Note that scripts run and at first it execute testadd.js file and then execute testsub.js files. It opened chrome browser and execute addition first and then subtraction. We get the following result.

image

That’s all from here. We will discuss more on gulp and protractor in future.

Happy UI Testing with Protractor!!!

Friday, January 1, 2016

Protractor : How to run Protractor script using gulp runner

In our last post we have seen how we can automate AngularJS application using protractor. Here we will show how we can run our protractor script using gulp. Gulp is a tool that helps to run our JavaScript files. We can write our protractor script in separate JS files and instruct gulp to run all the js files one by one.

Here we will use our previous protractor test project and run our protector test using Gulp.

Step 1 : Open the test project that was developed our previous post

image

Step 2 : Open a new terminal and run the following command to install gulp globally.

npm install --global gulp
image
Step 3 : Install gulp in our project locally (project devDependencies) by running following command.
npm install --save-dev gulp

image

Note that a new folder node_module is created and all the gulp files are there.

image

Step 4 : Create a gulpfile.js at the root of our project.

  • Right click on the project and go to File>New>JavaScript File.

image

  • Enter file name as “gulpfile.js” and click on OK button.

image

  • New File “gulpfile.js” is created.

image

  • Open “gulpfile.js” file and write the following code.

image

Note that using gulp.task() API we can run any JavaScritpt file.

  • Now our project is ready to use gulp. To verify it just open a new terminal and write the following command.
gulp
image
  • The default task will run and do nothing.

image

Note that if we use different task name instead of “default” we need to change the task name. 
Step 5 : In order to run our protractor script we need to install  gulp-protractor plugin. 
  • Open a terminal and run the following command as a development dependency.
npm install --save-dev gulp-protractor

image

  • Now gulp-protractor plugin is installed.

Step 6 : Open “gulpfile.js” again and add the following variable.

image

Now add the following code at gulp.task() function.

image

Here gulp.src() takes the script file name as argument. In our case test.js is the file name. We can run multiple js files. We will show you in our future post.

In the configFile we assign our conf.js file.

In the args we assign base URL and address.

Now “gulpfile.js” looks like the following.

image

Step 7 : Now go to terminal and start selenium server using the command,

[image71.png]

Note that it can be handled using gulp and I will show you in next post.

Run the following command to run our protractor script.

gulp

image

Note that we use only the command name “gulp” in case of task name “default” as it can automatically detects the task by default. If we mention task name at gulp.task() function then we need to mention it after gulp command.

Step 8 : Scripts will start and execute the test.

image

That’s all from here. We will discuss more on gulp and protractor in future.

Happy UI Testing with Protractor!!!

Cypress: How to handle browser-based authentication pop up dialog in Cypress

Five years ago I have written a blog on how to handle browser-based authentication for selenium webdriver.   Now it is for cypress. Cypress...