Selenium and Watir |
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:
You can see the full code below.
To call the Watir, Python module must import Popen, PIPE, STDOUT from Subprocess like as following:
from subprocess import Popen, PIPE, STDOUTthen 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 #case.communicate(email #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:
case.__init__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 = String.new() 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.