예제 #1
0
 def flow_ball(self):
     self.skip_page()
     try:
         self.driver.find_element(*self.flow_ball_btn).click()
         self.getScreenshot("flow")
     except NoSuchElementException:
         logs.error("the flow_ball element not found")
예제 #2
0
 def flow_coin(self):
     # self.login_key()
     # self.skip_page()
     # self.check_bounced()
     try:
         flows = self.driver.find_elements(*self.flow_btn)
     except NoSuchElementException:
         logs.error("the flow_btn element not found")
     else:
         flows[2].click()
         self.driver.find_element(*self.exchange_btn).click()
         exc_list = self.driver.find_elements(
             *self.exchange_flow_btn)  #页面有多个相同按钮,读取列表形式在切片取值
         try:
             exc_list[1].click()
             btn_left = self.driver.find_element(
                 *self.button_left)  #确认兑换提示框
         except NoSuchElementException:
             logs.info("流量币不足或已抢光!")
             self.getScreenshot("flowNotEnough")
         else:
             btn_left.click()
             total = self.driver.find_element(
                 *self.flow_total_ele).get_attribute("text")
             self.getScreenshot("exchange_flow")
             return int(total)
예제 #3
0
 def get_size(self):
     try:
         x = self.get_window_size()["width"]  # x值为720,其实就是屏幕分辨率
         y = self.get_window_size()["height"] # y值为1280,返回一个元组(720,1280)
         return x,y
     except Exception as e:
         logs.error("Failed to get screen size")
예제 #4
0
 def get_driver(self):
     data = self.conf.get_yamlfile()
     try:
         capabs = {}
         capabs["platformName"] = data["platformName"]
         capabs["platformVersion"] = data["platformVersion"]
         capabs["deviceName"] = data["deviceName"]
         # capabs["udid"] = data["udid"]
         # base_dir = os.path.dirname(os.path.dirname(__file__)) #获取当前文件根目录
         base_dir = r"E:\appium_apk" #apk在电脑上的路径,启动成功后会自动安装apk
         # app_path = os.path.join(base_dir,'app',data["appname"])
         app_path = os.path.join(base_dir,data["appname"])
         capabs["app"] = app_path
         capabs["appPackage"] = data["appPackage"]
         capabs["appActivity"] = data["appActivity"]
         capabs["noReset"] = data["noReset"]
         capabs["automationName"] = data["automationName"] #打开这行可能会导致运行不稳定
         # capabs["unicodeKeyboard"] = data["unicodeKeyboard"]
         capabs["newCommandTimeout"] = data["newCommandTimeout"]
         logs.info("start app...")
         driver = webdriver.Remote("http://%s:%s/wd/hub"%(data["ip"],data["port"]),capabs)
         # 设置隐性等待,在规定的时间内页面的所有元素都加载完了就执行下一步,否则一直等到时间截止,然后再继续下一步。
         driver.implicitly_wait(10)
         return driver
     except Exception as e:
         logs.error("Appium服务未启动或设备devices未连接!",e)
         exit()
예제 #5
0
 def sliding_banner(self):
     self.skip_page()
     try:
         banner_element = self.driver.find_element(*self.banner)
     except NoSuchElementException:
         logs.error('the banner element not found')
     else:
         banner_element.click()
예제 #6
0
 def enter_butn(self): #滑动引导页,然后立即进入
     try:
         self.swipeLeft()
     except NoSuchElementException:
         # pass
         logs.error("启动失败!")
     else:
         self.find_element(*self.btn_enter).click()
예제 #7
0
 def get_csv_data(self,line):
     try:
         with open(self.csvfile,'r',encoding='utf-8-sig') as cf:
             data = csv.reader(cf)
             for index,items in enumerate(data,1): #从索引1开始
                 if index == line:
                     return items
     except Exception as e:
         logs.error(e)
예제 #8
0
 def check_flow_exchange_successful(self):
     try:
         self.driver.find_elements(*self.flow_btn)[2].click()
         ele = self.driver.find_element(*self.flow_total_ele)
         flow_coin_total = int(ele.get_attribute("text"))
     except NoSuchElementException:
         logs.error("the flow_btn element not found")
         return None
     else:
         self.find_element(*self.back_btn).click()
         return flow_coin_total
예제 #9
0
 def loginView(self, phone_num, password):
     self.click_passwd()
     self.skip_page()
     try:
         self.driver.find_element(
             *self.phonenum_element).send_keys(phone_num)
         self.driver.find_element(
             *self.password_element).send_keys(password)
     except NoSuchElementException:
         logs.error("No Login page element found")
     else:
         self.driver.find_element(*self.login_Button).click()
         self.getScreenshot("login")
예제 #10
0
 def phone_pay(self):
     try:
         self.driver.find_element(*self.phone_pay_btn).click()
         # self.driver.find_element(*self.phone_pay_ele)
         # 显示等待
         WebDriverWait(driver, 8).until(
             lambda x: x.find_element_by_id('com.sxhsh:id/webview'))
     except NoSuchElementException:
         logs.error("not found phone_pay_ele element")
     else:
         self.get_H5element("WEBVIEW_com.android.browser")
         self.driver.find_element(
             *self.input_phone).send_keys('18293117474')
예제 #11
0
 def swipeLeft(self):
     try:
         rig = self.get_size()
         x1 = int(rig[0] * 0.99)
         y1 = int(rig[1] * 0.99)
         x2 = int(rig[0] * 0.15)
         s = 0
         time.sleep(2)
         while s<4:
             self.get_swipe(x1,y1,x2,x1,1000)
             s+=1
     except Exception as e:
         logs.error("引导页滑动失败!")
예제 #12
0
 def send_email(self, reports):
     sender = "yzm<%s>" % (self.sender_eml)
     mtp = MIMEMultipart()  #带附件实例
     mtp['Subject'] = self.subject
     mtp['From'] = sender
     mtp['To'] = ';'.join(self.recipient_list)  #收件人
     # 构造文字内容邮件
     mtp.attach(MIMEText(self.content, _subtype='plain', _charset='utf-8'))
     # 构造附件
     attach_file = reports  #报告文件
     mit = MIMEText(open(attach_file, 'rb').read(), 'base64', 'utf-8')
     mit['Content-Type'] = 'application/octet-stream'
     mit['Content-Disposition'] = 'attachment; filename="hsq_UIAutoTestReport.html"'  #附件重命名
     mtp.attach(mit)
     # 发送邮件
     try:
         server = smtplib.SMTP()
         server.connect(self.host)
         server.login(self.sender_eml, self.passwd)
         server.sendmail(sender, self.recipient_list, mtp.as_string())
     except Exception as e:
         logs.error(e)
     else:
         server.quit()
예제 #13
0
 def get_values(self,sec_name,opt_name):
     try:
         return self.conf.get(sec_name,opt_name)
     except Exception as e:
         logs.error(e)