Write First Selenium script

 

Pre-Requisites:

You have completed Ruby, selenium, cucumber installation steps described at the beginning of the tutorial. You have also downloaded the template project, imported in RubyMine. Please go through first basic cucumber scenario 

 

 

Agenda:

  1. Create a new feature file “first_selenium.feature”
  2. Write a Feature and then a scenario
  3. Open www.seleniumframework.com website
  4. Print the title, URL and page source for the website
  5. At the end of this page, a video will be posted

 

 

1. Right click “features” folder and add a new feature file “first_selenium.feature”

selenium_feature

 

selenium_feature_name

 

 

2. Lets describe the behavior of our scenario as follows

 

 

 

 

3. In RubyMine the file first_selenium.feature looks as below

first_selenium_added

4. Now right-click on step_definitions folder and add “first_selenium.rb” file

first_selenium_steps

first_selenium_steps1

 

5. Copy and paste the below code in first_selenium.rb file

 

 

6. Right click on any line on the Scenario and Run as below

first_selenium_run

 

 

7. Browser should pop up, hit http://www.seleniumframework.com and print title, url and page source as in below screenshot

 

selenium_feature_success

 

Note: You might have to scroll up in the right bottom scroll window to see pagetitle and url

 

output

 

FAQ

1. My browser doesn’t launch¬†

Ans: Please check that you have completed the pre-requisites section

2. I get “Empty test suite” error

Ans: The most likely cause of this is a typo in your cucumber script

3. I need more help

Ans: Please write back to us on the Contact page if you are interested in tutorials

First Selenium Based Script