Calling to a Sikuli script from Python (Selenium)

Dave picture Dave · Aug 13, 2013 · Viewed 17.3k times · Source

While running Selenium tests on a website, I have some Flash elements that I cannot test with Selenium/Python. I wanted to call out for a separate terminal window, run the Sikuli OCR tests, and then back into the Selenium/Python testing. I've not been able to figure this out exactly. I put XXX where I do not know the arguments for a 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 am sure there are a couple items wrong here. Any help would be greatly appreciated. I've searched and read what I can find on this already, but can't get it all to work together.

Answer

kevlened picture kevlened · Dec 4, 2013

I ran into a similar issue, so I wrote a CPython module for Sikuli. The module is hosted on GitHub and available via pip install sikuli. It's able to access an included Sikuli jar using pyjnius, so you don't have to use Jython or even install Sikuli itself (although I'd recommend it for recording purposes). The module currently covers most of the simpler Sikuli functions, so it should cover a lot of use cases.

After installing, a simple from sikuli import * will get you started, but as a best practice, I'd suggest only importing the functions you want to use. This is particularly important for this module, because sikuli has a type function which overrides Python's own type function.