Call to Sikuli script from Python (Selenium)

When running Selenium tests on a website, I have some Flash elements that I cannot test with Selenium / Python. I wanted to call in a separate terminal window, run the Sikuli OCR tests, and then return to testing Selenium / Python. I could not figure it out exactly. I put XXX where I don't know the arguments for the new terminal to open and run the Sikuli script.

def test_05(self): driver = self.driver driver.get(self.base_url + "/") driver.find_element_by_link_text("Home").click() driver.find_element_by_id("open_popup").click() driver.find_element_by_id("screen_name").send_keys("user") driver.find_element_by_id("password").send_keys("pwd") driver.find_element_by_id("login_submit").click() driver.find_element_by_id("button").click() time.sleep(120) os.system('XXX') os.system('./Sikuli/sikuli-script -r test.sikuli') 

I'm sure there are a couple of things here. Any help would be greatly appreciated. I searched and read what I can find on this already, but I can not get it all to work together.

+4
source share
3 answers

I had a similar problem, so I wrote a CPython module for Sikuli. The module is hosted on GitHub and is accessible via pip install sikuli . It can access the included Sikuli bank using pyjnius , so you don't need to use Jython or even install Sikuli (although I would recommend it for writing). The module currently covers most of the simpler functions of Sikuli, so it should cover many use cases.

After installation, a simple from sikuli import * will start working, but as a best practice, I suggest importing only those functions that you want to use. This is particularly important for this module because Siculo has a function type , which redefines its own function type the Python.

+2
source

To call Sikuli code from Selenium, my first choice would be to offer TestAutomationEngr using Java, since Selenium and Sikuli have their own Java bindings.

Since you want to use Python, you should try running Selenium under Jython. It is important to remember that Sikuli is Jython, so you probably cannot import it. (Another reason is that you do not have it in the path to the Jython module.) I have not tried this myself, but last year a bug was fixed in Selenium, which indicates that this should be good in Jython.

Please note that if you call Sikuli code directly from Jython, you need to add

 from sikuli.Sikuli import * 

up. This is because the Sikuli IDE implicitly adds this to the entire Sikuli code.

Finally, in the latter case, you must call Sikuli from the command line. There is a FAQ for . You probably need a "no IDE" version where you call Java and pass the sikuli- script JAR file.

+1
source

If your sikuli script is completely independent, and you just want to run it once, then return control to your python script. Then you can create a batch file that calls your sikuli script, and instead call that batch file from your python script. After the batch file is launched, it exits and returns control back to your python script.

Example batch file:

 @echo off call C:\Sikuli\runIDE.cmd -r C:\Automation\Test1.sikuli exit 

code snippet for calling Sikuli script from inside python:

 import subprocess def runSikuliScript(path): filepath = path p = subprocess.Popen(filepath, shell=True, stdout = subprocess.PIPE) stdout, stderr = p.communicate() print "Done Running Sikuli" p = "C:\\Automation\\Test1\\test1.bat" runSikuliScript(p) // You can carry on writing your python code from here on 
0
source

Source: https://habr.com/ru/post/1496686/


All Articles