Exemplo n.º 1
0
def stop_appium():
    try:
        if os.system("taskkill /f /im node.exe"):
            log.info("关闭appium服务成功!")

    except Exception as e:
        log.error("关闭appium服务失败,失败原因是:{}".format(e))
Exemplo n.º 2
0
def checkport(host, port):
    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    try:
        s.connect((host, port))
        s.shutdown(2)
        print('%s is used' % port)
        return True
    except WindowsError:
        log.error('端口{}未被占用,可以使用!'.format(port))
        return False
Exemplo n.º 3
0
 def __init__(self):
     # uninstall('io.appium.settings')
     try:
         desired_caps = dict(cfg.items('android-ZTE'))  #获取desired_caps的键值对
         url = ('http://%s:%s/wd/hub' %
                (cfg.get('HOST-IP', 'host'), cfg.get('HOST-IP', 'port')))
         self.driver = webdriver.Remote(url, desired_caps)
     except Exception as e:
         log.error("手机连接失败,失败的原因是{}".format(e))
     else:
         log.info("手机app连接成功,接下来开始操作界面ing")
Exemplo n.º 4
0
 def start_appium(self):
     while 1:
         if checkport(self.host, self.port):
             self.port = self.port + 1
         else:
             break
     bp = self.port + 1
     cmd = (r'node.exe "%s" -a %s -p %s -bp %s --session-override' %
            (self.cmdpath, self.host, self.port, bp))
     try:
         t1 = RunServer(cmd)
         t1.start()  #进程的启动方式
         log.info("appium启动成功,接下来开始连接手机啦!")
     except Exception as e:
         log.error("appium启动失败!失败原因是:{}".format(e))
Exemplo n.º 5
0
    def run(self):
        appium = appiumserver.AppiumServer()
        appium.start_appium()
        time.sleep(15)
        driver = appiumserver.Android()
        time.sleep(10)
        try:
            driver.clickbutton('xpath',
                               "//android.widget.TextView[@text='工作台']")
            print('-----click the workplace')
            time.sleep(10)
            driver.clickbutton('name', '工作台')
            print('-----click the workplace agin')
            time.sleep(10)

            if not driver.is_element_exist('打卡'):
                driver.downswipe()
                print('-----下滑提示')

            driver.clickbutton(
                'xpath',
                "//androidx.recyclerview.widget.RecyclerView[@resource-id='com.tencent.wework:id/w4']/android.widget.RelativeLayout[5]"
            )
            #driver.clickbutton('xpath', "//androidx.recyclerview.widget.RecyclerView[@resource-id='com.tencent.wework:id/w4']/android.widget.RelativeLayout[11]/android.widget.LinearLayout[1]")
            print('-----click the clock in')
            time.sleep(10)
            driver.tap(266, 693)  # ZTE
            time.sleep(10)
            driver.tap(453, 903)  # ZTE
            print('-----clock in')
            time.sleep(10)
            driver.tap(20, 75)
            time.sleep(10)
            driver.tap(132, 121)
            print('-----clock back button')
            time.sleep(10)
            if driver.is_element_exist('工作台'):
                log.info("界面断言成功啦!开心~~~")
            else:
                log.error("界面断言失败了!::>_<:: ")

            time.sleep(10)
        except Exception as e:
            log.error("打卡失败,原因是{}".format(e))

        appiumserver.stop_appium()