← Back to team overview

sikuli-driver team mailing list archive

Re: [Question #177227]: Sikuli IDE support open python

 

Question #177227 on Sikuli changed:
https://answers.launchpad.net/sikuli/+question/177227

    Status: Answered => Open

jeromy is still having a problem:
Sorry, I still can't get it running, and I can't figure out where I'm
wrong.

Thanks in advance.


*Here's the output.*
----------------------------------------
F:\automation>java -jar "%SIKULI_HOME%\sikuli-script.jar" Site.sikuli
[info] Sikuli vision engine loaded.
[info] Windows utilities loaded.
[info] VDictProxy loaded.
FirefoxSettings
[error] Can't run this Sikuli script: Site.sikuli
Traceback (most recent call last):
  File "F:\automation\Site.sikuli\Site.py", line 165, in <module>
    NAVIGATE_RES = BrowserRes(BROWSER_PATH, IMG_NAV, IMG_URL)
NameError: name 'BROWSER_PATH' is not defined
---------------------------------------

*Diretory:*
F:\automation>tree
Folder PATH listing
Volume serial number is 00000200 8681:45B4
F:.
├─checkbox.sikuli
├─FirefoxSettings.sikuli
├─helloworld.sikuli
├─JAVA
├─logwatcher.sikuli
├─meetingtest.sikuli
├─Site.sikuli
│  ├─FirefoxSettings
│  └─IE9Settings
└─unittest.sikuli


*Files:*
----------------------------------------------
#Sites.py
from FirefoxSettings import *

#run from cmd, java -jar "%SIKULI_HOME%\sikuli-script.jar" Site.sikuli

from sikuli import *

#from org.sikuli.script.natives import Vision
#Vision.setParameter("MinTargetSize", 6)

#############navigator settings---------------------------
class BrowserRes(object):
    def __init__(self, apppath, navbtn, urlbar):
        self.apppath = apppath
        self.navbtn = navbtn
        self.urlbar = urlbar

class Browser(object):
    LAUNCH_TIMEOUT = 10
    BROWSER_TIMEOUT = 10

    def __init__(self, browserRes):
        self.res = browserRes
        self.app = App(self.res.apppath)

    def open(self):
        self.app.open()
        try:
            wait(self.res.navbtn,Browser.LAUNCH_TIMEOUT)#make sure the app
is running
        except FindFailed:
            popup('timeout in open browser','error')
            exit(-1)

    def navigate(self, url, ready_handles, timeout=None):
        bar = find(self.res.urlbar)
        bar.highlight(1)
        click(bar)#focus on the bar
        type(url + Key.ENTER)

        #only observe when there're handles
        if len(ready_handles) > 0:
            #register handles
            for img, handle in ready_handles:
                onAppear(img, handle)

            #wait for appear
            t = Browser.BROWSER_TIMEOUT
            if timeout:
                t = timeout
            observe(t, False)

    def focus(self):
        self.app.focus()

    def close(self):
        self.app.close()

class Site(object):

    def __init__(self, browser):
        self.browser = browser
        self.handle_map = {}

    def register_handle(self, url, img, handle):
        v = self.handle_map.setdefault(url,[])
        v.append([img,handle])

    def open(self, url, nohandle=False):
        self.browser.open()
        handles = self.handle_map.get(url)
        if handles is None and not nohandle:
            popup("No handle specified for %s"%url)
            exit(-1)

        self.browser.navigate(url, handles)

class WbxSite(Site):

    def __init__(self, browser, main_page):
        self.main_page = main_page
        self.result = False
        self.username = None
        self.password = None
        super(WbxSite,self).__init__(browser)

    def handle_menu_appear(self, event):
        self.result = True
        event.region.stopObserver()

    def handle_preference(self, event):
        self.result = True
        event.region.stopObserver()

    def mainpage(self):
        self.register_handle(self.main_page, IMG_MEETING_MENU,
self.handle_menu_appear)
        self.register_handle(self.main_page, IMG_PREF_RGN,
self.handle_preference)
        self.open(self.main_page)

    def logout(self):
        click(IMG_LOGOUT_BTN)
        click(IMG_LOGOUTOK_BTN)

    def login(self, username, password, rem):
        if exists(IMG_LOGOUT_BTN):
            return

        click(IMG_HOSTLOGIN_BTN)
        login_rng = find(IMG_LOGIN_RGN)#we should find it
        self._do_login(username, password, rem, login_rng)

        click(IMG_LATER_BTN)

    def _do_login(self, username, password, rem, login_rng):
        username_text = login_rng.find(IMG_USERNAME_RGN)
        click(username_text)
        type(username)
        pwd_text = login_rng.find(IMG_PWD_RGN)
        click(pwd_text)
        type(password)

        if rem:
            rem_rng = login_rng.find(IMG_KEEPLOGIN_CHKBOX)
            click(rem_rng)

        login_rng.click(IMG_LOGIN_BTN)

        #we've already logined
        self.username = username
        self.password = password

    def schdule_meeting(self, topic, pwd, username=None, userpwd=None):

        click(IMG_MEETINGCENTER_BTN)

        if not exists(IMG_SCHEDULE_RGN):
            click(IMG_HOSTMEETING_BTN)

        if exists(IMG_LOGIN_RGN):
            if (self.username is None or self.password is None)\
                and (username is None or userpwd is None):
                    popup("You need to provide username and password to
schedule a meeting.\nOr you should login first")
                    exit(-1)
            self._do_login(username, userpwd, True, find(IMG_LOGIN_RGN))

        wait(IMG_BROWSERMEETING_RGN)
        click(IMG_SCHEDULEMEETING_BTN)

        topic_text = find(IMG_MEETINGTOPIC_RGN)
        click(topic_text)
        type(topic)
        pwd_text = find(IMG_MEETINGPWD_RGN)
        click(pwd_text)
        type(pwd)
        confirm_text = find(IMG_CONFIRMPWD_RGN)
        click(confirm_text)
        type(pwd)

        click(IMG_STARTMEETING_BTN)


if __name__ == '__main__':
    #Let's import settings before use
    #from FirefoxSettings import *
    #from IE9Settings.Settings import *

    NAVIGATE_RES = BrowserRes(BROWSER_PATH, IMG_NAV, IMG_URL)

    browser = Browser(NAVIGATE_RES)
    wbx_site = WbxSite(browser,"https://erkfr29.qa.webex.com";)
    wbx_site.mainpage()
    if not wbx_site.result:
        popup("Seems the remote server doesn't response")

    print find(IMG_MEETING_MENU)

    #while True:
    #    wbx_site.login("jeromyf", "pass", True)
    #    wait(1)
    #    wbx_site.logout()
    #    wait(1)

    wbx_site.login("jeromyf", "pass", True)
    wbx_site.schdule_meeting("test on sikuli", "111111")
-----------------------------------------------------------------------------------------------------------


-----------------------------------------------------------------------------------------------------------
#FirefoxSettings.py

from sikuli import *

import os
import sys
cur_dir = os.path.abspath(os.path.dirname(__file__))
#popup(cur_dir)
addImagePath(cur_dir)
popup('\n'.join(getImagePath()))

BROWSER_PATH = "c:\\Program Files\\Mozilla Firefox\\Firefox.exe"
IMG_NAV = "ff6_nav.png"
IMG_URL = Pattern("ff6_url.png").targetOffset(-68,0)

IMG_MEETING_MENU = "meetingmenu.png"
IMG_PREF_RGN = "preferences.png"
IMG_LOGOUT_BTN = "logout_btn.png"
IMG_LOGOUTOK_BTN = "logoutok_btn.png"
IMG_HOSTLOGIN_BTN = "hosttLogIn.png"
IMG_LOGIN_RGN = "login_rng.png"
IMG_LATER_BTN = "later_btn.png"
IMG_USERNAME_RGN = "username_rng.png"
IMG_PWD_RGN = "password_rng.png"
IMG_KEEPLOGIN_CHKBOX = Pattern("keep_chkbox.png").targetOffset(-60,0)
IMG_LOGIN_BTN = "login_btn.png"

IMG_STARTMEETING_BTN = "startmeeting_btn.png"
IMG_BROWSERMEETING_RGN = "browsemeeting_rgn.png"
IMG_CONFIRMPWD_RGN = "confirmpwd_rgn.png"
IMG_HOSTMEETING_BTN = "hostmeeting_btn.png"
IMG_MEETINGCENTER_BTN = "meetingcenter_btn.png"
IMG_MEETINGPWD_RGN = "meetingpwd_rgn.png"
IMG_CONFIRMPWD_RGN = "confirmpwd_rgn.png"
IMG_MEETINGTOPIC_RGN = "meetingtopic_rgn.png"
IMG_SCHEDULE_RGN = "shedule_rgn.png"
IMG_SCHEDULEMEETING_BTN = "schedulemeeting_btn.png"


2011/11/3 RaiMan <question177227@xxxxxxxxxxxxxxxxxxxxx>

> Your question #177227 on Sikuli changed:
> https://answers.launchpad.net/sikuli/+question/177227
>
>    Status: Open => Answered
>
> RaiMan proposed the following answer:
> --- from sikuli import *
> is only needed in scripts that are imported (FirefoxSettings.sikuli in
> this case) and only if you use any Sikuli API features.
>
> --- the .py files
> should never be touched as long as you are using the Sikuli IDE to edit
> the Sikuli scripts. And then we should always talk about a Sikuli script
> (since this is the bundle of code and images contained in a folder with
> suffix .sikuli).
> The .py files are only of interest in very special situations and when you
> decide to use other IDE's like Eclipse or Netbeans to edit and run the
> Python code.
>
> so your structure is like this:
>
> - automation
>   - Site.sikuli
>   - FirefoxSetting.sikuli
>
> Now the solution, if you decide to have all your imports in the same
> directory as the main script:
>
> # Site.sikuli
> # preferably in first line
> from FirefoxSettings import *
>
> This makes available all names in FirefoxSettings without the need to
> qualify them. This is ok, if you are sure there will be no naming
> conflicts.
>
> To avoid conflicts, use:
>
> import FirefoxSettings
>
> but then you have to qualify the names from FirefoxSettings:
>
> x = FirefoxSettings.some_name_from_FirefoxSettings
>
> This is all, since Sikuli will look for imports in the same directory
> the main script lives in.
>
> Adding the folder containing your imports to sys.path is only required,
> when this folder is not the same as your main script lives in.
>
> --
> If this answers your question, please go to the following page to let us
> know that it is solved:
> https://answers.launchpad.net/sikuli/+question/177227/+confirm?answer_id=2
>
> If you still need help, you can reply to this email or go to the
> following page to enter your feedback:
> https://answers.launchpad.net/sikuli/+question/177227
>
> You received this question notification because you asked the question.
>

-- 
You received this question notification because you are a member of
Sikuli Drivers, which is an answer contact for Sikuli.