Exemplo n.º 1
0
def uninstall(uninstaller_path):
    # 1. start uninstaller
    run_external(uninstaller_path)
    time.sleep(2)

    # 2. find the installer dialog
    uninstaller = None
    try:
        uninstaller = Application().connect(title=u'2345王牌输入法 卸载程序')
    except Exception as e:
        raise RuntimeError('Cannot find uninstaller, exception: %s' % repr(e))

    # 3. get position of the install button and note the installed path
    # can get all handlers by call like this:
    # print(installer.window_(title_re=u'2345王牌输入法 v[0-9]+\.[0-9]+ 安装').print_control_identifiers())
    uninstall_dlg = uninstaller.window_(title=u'2345王牌输入法 卸载程序')
    print(uninstall_dlg.print_control_identifiers())

    l, r, t, b = uninstall_dlg.Rectangle().left, uninstall_dlg.Rectangle().right, \
                 uninstall_dlg.Rectangle().top, uninstall_dlg.Rectangle().bottom
    pos = (int(l + (r - l) * 0.713), int(t + (b - t) * 0.923))
    print('Move mouse to button(%d, %d)' % (pos[0], pos[1]))
    uninstall_dlg.click_input(coords=pos, absolute=True)
    resolve_confirm_dlg(title_re=u'2345王牌输入法卸载程序')

    # 4. wait for finish
    confirm_pos = (int(l + (r - l) * 0.9), int(t + (b - t) * 0.9))
    while uninstall_dlg.exists():
        uninstall_dlg.click_input(coords=confirm_pos, absolute=True)
        time.sleep(5)
Exemplo n.º 2
0
def resolve_configure_dlg():
    try:
        configure_app = Application().connect(title_re=u'2345王牌输入法设置向导')
    except Exception as e:
        raise RuntimeError('Cannot find confirm dialog, exception: %s' % repr(e))
    configure_dlg = configure_app.window_(title_re=u'2345王牌输入法设置向导')
    print(configure_dlg.print_control_identifiers())
    l, r, t, b = configure_dlg.Rectangle().left, configure_dlg.Rectangle().right, \
                 configure_dlg.Rectangle().top, configure_dlg.Rectangle().bottom
    pos = (int(l + (r - l) * 0.92), int(t + (b - t) * 0.94))
    while configure_dlg.exists():
        configure_dlg.click_input(coords=pos, absolute=True)
Exemplo n.º 3
0
def resolve_confirm_dlg(title_re, cancel=False):
    try:
        confirm_app = Application().connect(title_re=title_re)
    except Exception as e:
        raise RuntimeError('Cannot find confirm dialog, exception: %s' % repr(e))
    confirm_dlg = confirm_app.window_(title_re=title_re)
    print(confirm_dlg.print_control_identifiers())
    l, r, t, b = confirm_dlg.Rectangle().left, confirm_dlg.Rectangle().right, \
                 confirm_dlg.Rectangle().top, confirm_dlg.Rectangle().bottom
    pos = (int(l + (r - l) * 0.87), int(t + (b - t) * 0.87)) if cancel else (int(l + (r - l) * 0.64), int(t + (b - t) * 0.87))

    confirm_dlg.click_input(coords=pos, absolute=True)
Exemplo n.º 4
0
def install(installer_path):
    # 1. start installer and wait for UerAccoutCotrol confirm
    run_external(installer_path)
    time.sleep(2)

    # 2. find the installer dialog
    installer = None
    try:
        installer = Application().connect(title_re=u'2345王牌输入法 v[0-9]+\.[0-9]+ 安装')
    except Exception as e:
        raise RuntimeError('Cannot find installer, exception: %s' % repr(e))

    # 3. get position of the install button and note the installed path
    # can get all handlers by call like this:
    # print(installer.window_(title_re=u'2345王牌输入法 v[0-9]+\.[0-9]+ 安装').print_control_identifiers())
    install_dlg = installer.window_(title_re=u'2345王牌输入法 v[0-9]+\.[0-9]+ 安装')
    print(install_dlg.print_control_identifiers())

    installed_path = None
    for widget in install_dlg.descendants():
        if widget.class_name() == 'Edit':
            installed_path = widget.window_text()

    l, r, t, b = install_dlg.Rectangle().left, install_dlg.Rectangle().right, \
                 install_dlg.Rectangle().top, install_dlg.Rectangle().bottom
    pos = (int((l + r) / 2), int(t + (b - t) * 0.775))
    print('Move mouse to button(%d, %d)' % (pos[0], pos[1]))
    install_dlg.click_input(coords=pos, absolute=True)
    time.sleep(2)

    # 4. wait for finish
    while b != install_dlg.Rectangle().bottom:
        time.sleep(2)
    install_dlg.click_input(coords=pos, absolute=True)

    try:
        time.sleep(2)
        resolve_configure_dlg()
    except:
        print('No configure dlg, ignore')
    return installed_path
Exemplo n.º 5
0
Arquivo: main.py Projeto: wlhost/PUBG
    'cancel': pickle.load(open('dicts/cancel.pkl', 'rb')),
    'exit_to_lobby': pickle.load(open('dicts/exit_to_lobby.pkl', 'rb')),
    'tl_pubg_logo': pickle.load(open('dicts/tl_pubg_logo.pkl', 'rb'))
}

start_rect = make_relative_rect(window_rect, [50, 680, -1100, -30])
mp_plane_rect = make_relative_rect(window_rect, [214, 600, -1070, -70])
plane_rect = make_relative_rect(window_rect, [76, 600, -1208, -70])
reconnect_rect = make_relative_rect(window_rect, [609, 430, -610, -317])
reconnect_ng_rect = make_relative_rect(window_rect, [609, 447, -610, -300])
cancel_rect = make_relative_rect(window_rect, [670, 441, -589, -308])
exit_to_lobby_rect = make_relative_rect(window_rect, [1095, 660, -88, -83])
tl_pubg_logo_rect = make_relative_rect(window_rect, [58, 58, -1205, -684])

pwa_app = Pwa_app().connect(handle=hwnd)
window = pwa_app.window_()
actions = Actions(window)
while True:
    sleep(5)
    if image_compare(dicts['start'], ImageGrab.grab(start_rect)) > 0.98:
        verboseprint('start')
        round_count = round_count + 1
        if round_count % 10 == 0:
            notify.method('Starting the {0}th game'.format(round_count))
        actions.start(args.team)
        continue

    if image_compare(dicts['exit_to_lobby'], ImageGrab.grab(exit_to_lobby_rect)) > 0.8:
        verboseprint('quit')
        actions.quit()
        continue
Exemplo n.º 6
0
# Get access to any window on the desktop

from pywinauto import Application  #for autowin
import pywinauto.keyboard
import time

lsAppPath = ""

#start the app
app = Application().start(lsAppPath)

#while the window does not exist
while not app.app():
    time.sleep(5)

#the title from the window we would like to access
lsWindowTitle = ""

#check if the window exists
if app.window_(title_re=lsWindowTitle).Exists():
    #get the window
    Window = app[lsWindowTitle]

    #we imagin there is an edit with the text hallo
    #get the edit
    editCtrl = Window[u'MyEdit']  # we need the name of the edit
    lsText = editCtrl.TextBlock()  # thats the important line

    #now we would like to write into the text edit
    editCtrl.TypeKeys(u"Nothing")
class EasyWire:
    """
    base class for running automated tests.

    """
    def __init__(self, hv_status=True, test_iterations=20):
        self.title = u'Cirris Easy-Wire'
        self.test_category_name = 'EW - Test Time'
        self.class_name = 'TInitialDialog'
        self.ew_path = self.ew_get_path()
        self.app = self.start_ew()
        self.app_uia = Application(backend='uia').connect(
            class_name_re='TInitialDialog')
        self.ew_test_list_window = self.app_uia[
            u'Cirris Easy-Wire'].child_window(class_name='TListView')
        self.test_list = []
        self.lv_test_time = []
        self.test_iterations = test_iterations
        if hv_status:
            self.hv_status = True
            self.hv_test_time = []
        else:
            self.hv_status = False

    def __str__(self):
        return f'App is {self.app}, test list is {self.test_list}, lv_test_time is {self.lv_test_time}, ' \
               f'hv_time_test is {self.hv_test_time}, ew_path is {self.ew_path}'

    def __repr__(self):
        return f'App is {self.app}, test list is {self.test_list}, lv_test_time is {self.lv_test_time}, ' \
               f'hv_time_test is {self.hv_test_time}, ew_path is {self.ew_path}'

    def ew_get_path(self):
        """
        method to locate easywire install path

        :return: string of install path
        """
        install_dict = dict()
        possible_install_paths = [
            [
                'ew_dev',
                Path(
                    r'C:\Dev\PC\Cirris\EasyWire\PC\Project\easywire.broken.exe'
                )
            ],
            [
                'ew_64_install',
                Path(r'C:\Program Files (x86)\Cirris\easywire\easywire.exe')
            ],
            [
                'ew_32_install',
                Path(r'C:\Program Files\Cirris\easywire\easywire.exe')
            ]
        ]
        for pair in possible_install_paths:
            install_dict[pair[0]] = pair[1]

        found = False
        for key, value in install_dict.items():
            if value.exists():
                found = True
                return str(value)

    def start_ew(self):
        """
        method to connect or launch easywire if not currently running

        :return: pywinauto Application object
        """

        try:
            app = Application().connect(title=self.title,
                                        class_name=self.class_name)
            return app
        except (application.ProcessNotFoundError,
                application.findwindows.ElementNotFoundError):
            app = Application().start(self.ew_path)
            self.login(app=app,
                       user='******',
                       tester_type='1100/Easy Touch',
                       password='')
            return app

    def login(self,
              app,
              user='******',
              tester_type='1100/Easy Touch',
              password=''):
        """
        method to log into easywire.

        :param user: User name required to log into easywire.  Defaults to 'Master Login'
        :param tester_type: Model type of the tester to be used during automated testing.  Defaults to 1100/Easy Touch
        :param password: Password required to login.  Defaults to ''
        :return: None
        """

        app.UserLogin.wait('ready')
        app.UserLogin.ComboBox.select(user)
        app.UserLogin.TEdit.set_text(password)

        try:
            app.UserLogin.ComboBox2.select(tester_type)
        except ValueError:
            pass

        app.Userlogin.OK.click()
        try:
            app.Hardware.wait('ready')
            print("Hardware error")
            print(app.Hardware.Edit.TextBlock())
            app.Hardware.OK.click()
        except timings.TimeoutError:
            pass

    def get_test_list(self, category_name='EW - Test Time'):
        """
        method to collect test list for a given category name in easywire.

        :param category_name: string of category name in easywire.  Defaults to 'Ew - Test Time'
        :return: list of tests from category name
        """
        test_list = []
        self.app[self.title].TComboBox.select(category_name)
        self.app_uia.window_(visible_only=False).restore()
        for test in self.ew_test_list_window.texts():
            if test[0].strip("'"):
                test_list.append(test[0])
        return test_list

    def select_current_test(self, test):
        """
        method to select current test from drop down list in easywire
        :param test: string of test name from easywire
        :return:
        """
        self.ew_test_list_window[test].select()
        try:
            self.app[self.title].Test.click()
        except base_wrapper.ElementNotEnabled:
            print('Tried to click Test button but it is not enabled')
            print('Verify the correct tester is attached and connected')
            sys.exit()

    @wait_helper
    def confirm_lv_test_window_good(self, **kwargs):
        """
        method to collect start and end times for lv only testing.  uses the decorator wait_helper to deal with try
        catch to handle timing issues with pywinauto.

        :param test_window_handle: pywinauto dialog object used to start tests and check for completion condition.
        :param exception_to_handle: exception be to passed to wait_helper decorator.  Not used in this method.
        :return: timestamp of start and end times of current test
        """
        test_window_handle = kwargs['test_window_handle']
        start_time = time.time()
        test_window_handle.Start.click()
        test_window_handle.Good.wait('ready')
        end_time = time.time()
        return start_time, end_time

    @wait_helper
    def confirm_lv_hv_test_window_good(self, **kwargs):
        """
        method to collect start and end times for both lv and hv testing.

        :param kwargs:
        :return: timestamp for start and stop times for both lv and hv
        """
        test_window_handle = kwargs['test_window_handle']
        lv_start = time.time()
        test_window_handle.Start.click()
        test_window_handle.Hipot.wait('ready')
        lv_stop = time.time()
        hv_start = time.time()
        test_window_handle.Hipot.click()
        test_window_handle.Done.wait('ready')
        hv_stop = time.time()
        test_window_handle.Done.click()
        return lv_start, lv_stop, hv_start, hv_stop

    def test_lv_only(self):
        """
        method to cycle through lv testing only.  Prints output to console using maths function.
        :return:
        """
        self.test_list = self.get_test_list(category_name='EW - Test Time')
        for test_num, test in enumerate(self.test_list, 1):
            for iter_num in range(1, self.test_iterations + 1):
                print(
                    f'Test #{test_num} - Test name: {test} - iteration: {iter_num}'
                )
                self.select_current_test(test)
                test_window = self.app[
                    f'Test Program - [{test} - Signature Single Test]']
                while True:
                    try:
                        test_window.Start.wait('ready')
                        break
                    except timings.TimeoutError:
                        print('timeout error triggered.')
                        time.sleep(1)
                lv_start, lv_stop = self.confirm_lv_test_window_good(
                    test_window_handle=test_window,
                    exception_to_handle=timings.TimeoutError)
                test_window.Done.click()
                self.lv_test_time.append(round(lv_stop - lv_start, 3))
        self.maths()

    def test_lv_hv(self):
        """
        method to cycle through lv and hv testing.  Prints output to console using maths function.

        :return:
        """
        lv_stop = 0
        lv_start = 0
        hv_stop = 0
        hv_start = 0
        self.test_list = self.get_test_list(
            category_name='EW - Time Test lvhv')
        for test_num, test in enumerate(self.test_list, 1):
            for iter_num in range(1, self.test_iterations + 1):
                self.select_current_test(test)
                print(
                    f'Test #{test_num} - Test name: {test} - iteration: {iter_num}'
                )
                test_window = self.app.window(title_re=".*" + test + ".*")
                lv_start, lv_stop, hv_start, hv_stop = self.confirm_lv_hv_test_window_good(
                    test_window_handle=test_window,
                    exception_to_handle=timings.TimeoutError)
            self.lv_test_time.append(round(lv_stop - lv_start, 3))
            self.hv_test_time.append(round(hv_stop - hv_start, 3))
        self.maths()

    def maths(self):
        """
        method to perform basic statistics for lv and hv test results.
        :return:
        """
        print(f'Baseline lv: {self.lv_test_time}')
        print(f'LV Values Median: {statistics.median(self.lv_test_time)}')
        print(
            f'LV Values Median_low: {statistics.median_low(self.lv_test_time)}'
        )
        print(
            f'LV Values Median_high: {statistics.median_high(self.lv_test_time)}'
        )

        if self.hv_status:
            print(f'Baseline hv: {self.hv_test_time}')
            print(f'HV Values Median: {statistics.median(self.hv_test_time)}')
            print(
                f'HV Values Median_low: {statistics.median_low(self.hv_test_time)}'
            )
            print(
                f'HV Values Median_high: {statistics.median_high(self.hv_test_time)}'
            )