Integration of Two open Source Test Automaiton Tools: Watir and Selenium

Selenium and Watir
Selenium and Watir are both open source and well-known automation tools. The power of Selenium is great but sometimes it may lead some insufficient result for executing test cases, or some difficulties can be achieved by Watir easily, surely or wise verse. Therefore we can use Selenium and Watir together for automating web applications. In this post, I want to show a sample to illustrate how to use both of them in the same automation framework. Possibly you maybe find something more accurate than what I did, fell free to post your thoughts.

I have used Selenium with Pyhton as a base automation framework and call Watir in Ruby which Watir can be just only implemented by it. If you use another language than Python, you should use its features. In the sample, sign up for MYHABIT is implemented as Watir function in the name sign_up() and it is called by Selenium.

 To call the Watir, Python module must import Popen, PIPE, STDOUT from Subprocess like as following:
from subprocess import Popen, PIPE, STDOUT 
then create a Popen object to communicate the Ruby file by the following:
case = Popen(["ruby", "watir/myhabit_sign_up_watir.rb"], stdin=PIPE, stdout=PIPE, stderr=STDOUT)
then if you want to pass just one argument, you can use directly communite function but if you want to send more than one argument you must use something different, like an array or more safely send the arguments as a JSON data. The following lines shows how it can be:
#if you have only one paremeter to send the watir you can use the following
#we have 4 parameters as test data so they are sent as a Json
ruby_par = { "name":name, "email": email, "url": self.url, "password": password}
then execute the Watir by calling _init_ function:
From the Watir function, you must import JSon like as require "json" and then parse the arguments which is taken by STDIN like as following:

ruby_par =
ruby_par = STDIN.gets

python_json = JSON.parse(ruby_par)
test_url = python_json['url']
test_name = python_json['name']
test_email = python_json['email']
test_password = python_json['password']

You can see the full code below.


Popular posts from this blog

Testing WEB Sevices and Automating SOAP Services

Performance Testing on CI: Locust is running on Jenkins

Change Default Timeout and Wait Time of Capybara

Performance Testing on CI: Integration of Locust and Jenkins

Create an Alias for Interactive Console Work: Selenium and Capybara