Pages

Friday, December 27, 2013

Selenium in 3 days – day 2 – Getting started with Selenium - Robot Framework

Today you will write your first selenium script. before that, you have to install Python, Selenium and all the supportive tools.






Selenium Robot Framework installation on Python

Step 1: Install supported Python version. (I prefer Python 2.6.6) -http://www.python.org/download/releases/2.6.6/


Step 3: Add Python installation directory and scripts directory (example -C:\Python26; C:\Python26\Scripts) to path variable. That will allow you direct execution.

Step 4: Execute command in command prompt   “pybot --version”.  If you have done all correctly up to now, you will see the robot framework and python versions.

Step 5: In addition, you may install ‘setuptools’ or ‘distribute’.  That will help you to install PIP.
Once installation is complete, you will find an easy_install.exe program in your Python Scripts subdirectory.

Step 6: Install PIP using “easy_install.exe pip” command.

Step 7: Install selenium2library using “pip install robotframework-selenium2library” command.

Optional : Install suitable selenium editor, which is convenient option to customize your script. I prefer RIDE or Ninja IDE.

Install Robot-IDE (RIDE) - RIDE is an editor for Robot Framework
Install Ninja IDE (http://ninja-ide.org/)

TIP 1 : Install firefox addon – “element locator for web driver”. That will help you to find locators (xpaths). Later, you will realize what is a locator and its usages. For now, just install it.

Tip 2: Install firefox addon – “firepath “. This will helps you to customize xpaths. 

TIP 3 : If you suppose to run your selenium test in various browsers you need to install relevant web driver. Just download the correct web driver and place it inside the C:\Python26\Scripts folder. (example – download Chrome web driver from https://code.google.com/p/chromedriver/downloads/list)

Congrats! Now you are ready to write your first selenium script. Here we go!

What are we going to do is,
·         Open firefox browser.
·         Load google site.
·         Search the word given by variable.
·         Validate the page title of the search result page.

There are 5 easy steps to do it.

Step 1: Create a folder named “helloworld” in your python installation directory.

Step 2: Create two sub-folders “resource” and “script” inside the “helloworld” folder.

Step 3: Inside the resource folder, create two files ‘resource.txt’ and ‘objectmap.py’ with below content. (Click on the image to enlarge)
You can see three keywords (‘Open Browser’, ‘Maximize Browser Window’, ‘Set Selenium Speed’) written under test template – ‘Open Browser To Google Home Page’. All these three keywords belong to selenium2library.
Is there any other libraries? 
Yes. There are several selenium libraries display here - http://robotframework.org/#test-libraries You can import relevant library and use it’s keywords.
'objectmap.py' include locators of the search buttons and input field. you can find these locators using the firefox addon – “element locator for web driver”.

Step 4: Now, the most important step of the flow. Create a file ‘helloworld.txt’ inside the script folder with below content.
I think you can easily understand this script. You can find the keywords ‘Input Text’, ‘Click Button’, and ‘Title Should Be’ at the selenium2library. ‘Wait Until Keyword Succeeds’ is a keyword from BuiltIn library.



Step 5: In the final step you are going to run the script in command prompt. Open CMD and navigate the location where ‘helloworld.txt’ placed. Run the script using pybot command.







That’s it! Now you know all the basics to develop any complex script. 
On day-3, I suppose to discuss about some common selenium libraries and their behaviors, working with windows dialog box, working with oracle database using python database library, logs/reporting and some more complex mechanisms. Bye for now and see you soon!
{ Read More }


Blogger news

Blogroll

What's Hot