How to use FindByText method in websmith

Best Python code snippet using websmith_python

ddtTestSettings.py

Source:ddtTestSettings.py Github

copy

Full Screen

1import unittest2from ddt import ddt,data,unpack3import uiautomator2 as u24import datetime5from config.config import *6from base.baseframe import BaseFrame7from base.watcherframe import WatcherFrame8from project.page.loginPage import *9# from data.get_data_login import GetData10@ddt #将测试类添加ddt修饰11class TestSettings(unittest.TestCase): # 创建测试类12 @classmethod # 类方法,只执行一次,但必须要加注解@classmethod,且名字固定为setUpClass13 def setUpClass(cls):14 # cls.d = u2.connect('192.168.199.168')15 # cls.d = u2.connect_usb('127.0.0.1:62025')16 cls.watcherframe = WatcherFrame(outdevice=TestDeviceID) #实例化17 cls.watcherframe.new_create_watcher()18 cls.watcherframe.new_create_watcher(outwatchername='OK',outconditiontextname='OK',outclicktextname='OK')19 cls.watcherframe.start_watcher()20 print('\n')21 pass22 @classmethod # 类方法,只执行一次,但必须要加注解@classmethod,且名字固定为tearDownClass23 def tearDownClass(cls):24 print('\n')25 cls.watcherframe.close_all_watchers()26 pass27 def setUp(self): # 每条用例执行测试之前都要执行此方法28 self.baseframe = BaseFrame(outdevice=TestDeviceID) #实例化29 print('\n')30 #pass31 def tearDown(self): # 每条用例执行测试之后都要执行此方法32 print('\n')33 pass34 #登录的测试方法35 def defineclickandbackandlogout(self,outtestcasediscription=None,issettings=False,islogout=False,outclickelementtext=None):36 if outtestcasediscription==None:37 testcasediscription = '测试用例'38 else:39 testcasediscription = outtestcasediscription40 if outclickelementtext==None:41 clickelementtext = "My QR"42 else:43 clickelementtext = outclickelementtext44 if issettings:45 self.baseframe.findbytext_and_click("Settings")46 if islogout:47 self.baseframe.findbytext_and_click("Log Out")48 self.baseframe.findbytext_and_click("Log Out")49 self.baseframe.findbytext(outclickelementtext)50 else:51 self.baseframe.findbytext_and_click(clickelementtext)52 self.baseframe.delaytime(5)53 self.baseframe.clickback()54 self.baseframe.findbytext("Settings")55 print("%s.---测试通过" %testcasediscription)56 @data(("点击Settings进入Settings页,点击ChangeLoginPassword后返回Settings",True,False,"Change Login Password"),57 ("点击ChangeTransactionPIN后返回Settings", False, False, "Change Transaction PIN"),58 ("点击AboutQRindo后返回Settings", False, False, "About QRindo"),59 ("点击Help后返回Settings", False, False, "Help"),60 ("点击Logout登出",False,True,"Login"))61 @unpack62 def test_clickandbackandlogout(self,outtestcasediscription,issettings,islogout,outclickelementtext):63 self.defineclickandbackandlogout(outtestcasediscription,issettings,islogout,outclickelementtext)64# @staticmethod #根据不同的参数生成测试用例65# def getTestFunc(outtestcasediscription,outphonenumberinput,66# outpwdinput,outprepagetext,67# outpretoastmessage,outexceptiontext):68# def func(self):69# self.definelogin(outtestcasediscription,outphonenumberinput,70# outpwdinput,outprepagetext,71# outpretoastmessage,outexceptiontext)72# return func73#74#75# @unittest.skip('test_020') # 跳过用例名字为‘test_01’的用例,跳过的用例的执行结果显示:是76# def test_020(self):77# """78# 正确的账号和密码,登录成功79# """80# outadborder = None81# outphonenumberid = None82# outphonenumberinput = None83# outpwdid = None84# outpwdinput = None85# outloginbuttonid = None86# outprepagetext = 'QRindo-Merchant'87# outpretoastmessage = None88#89# self.definelogin(outprepagetext=outprepagetext)90# print("已经注册商户的正确的钱包账号和密码,登录成功.---测试通过")91#92# # def generateTestCases():93# # arglists = [("非8或08开头的手机号登录,toast提示 'You have entered an invalid Indonesia number'",94# # '1122336666','123456',None,95# # 'You have entered an invalid Indonesia number',None),96# # ("没有注册商户的正确的钱包账号和密码,登录提示'Login account is not bound to the merchant(MC320)'",97# # '81122337788','a123456','Login account is not bound to the merchant(MC320)',98# # None,'OK'),99# # ('没有注册的钱包账号登录,提示“Incorrect account number or login password Please try again(PP001)”',100# # '86754893987','a123456','Incorrect account number or login password. Please try again(PP001)',101# # None,'OK'),102# # ('正确的钱包账号,错误的密码,提示“Incorrect account number or login password Please try again(PP001)”',103# # '833669911','123456','Incorrect account number or login password. Please try again(PP001)',104# # None,'OK'),105# # ("账号长度输入小于8位,密码位数等于6位,登录按钮置灰不可用",106# # '1234567','123456','Log in',107# # None,'Log in'),108# # ("账号长度输入等于8位,密码位数小于6位,登录按钮置灰不可用",109# # '12345678','12345','Log in',110# # None,'Log in'),111# # ("账号长度输入大于13位时,密码位数等于6位,登录按钮置灰不可用",112# # '12345678901234','123456','Log in',113# # None,'Log in'),114# # ("账号长度输入等于13位时,密码位数大于24位,登录按钮置灰不可用",115# # '1234567890123','1234567890123456789012345','Log in',116# # None,'Log in'),117# # ("已经注册商户的正确的钱包账号和密码,登录成功",118# # None,None,'QRindo-Merchant',119# # None,None),120# #121# # ]122# # for i in range(0,len(arglists)):123# # args = arglists[i]124# # setattr(TestLogin, 'test_func_%s_%s' % (i,args[0]),125# # TestLogin.getTestFunc(*args)) # 通过setattr自动为TestCase类添加成员方法,方法以“test_func_”开头126#127# def __generateTestCases():128# file_name = "D:/Users/Administrator/PycharmProjects/uiautomator2project/dataconfig/autologin.xls"129# sheet_id = 0130# datasheet = GetData(file_name,sheet_id) #实例化131# rows_count = datasheet.get_case_lines() #获取表的行数132# for i in range(1, rows_count): # 循环,但去掉第一133# args = []134# args.append(datasheet.get_case_title_content(i))135# args.append(datasheet.get_account_input_content(i))136# args.append(datasheet.get_password_input_content(i))137# args.append(datasheet.get_pre_text_content(i))138# args.append(datasheet.get_pre_toast_content(i))139# args.append(datasheet.get_pre_back_text_content(i))140# setattr(TestLogin, 'test_func_%s_%s' % (datasheet.get_case_id_content(i),args[0]),141# TestLogin.getTestFunc(*args)) # 通过setattr自动为TestCase类添加成员方法,方法以“test_func_”开头142#143#144# __generateTestCases()145if __name__ == '__main__':146 print("hello world")...

Full Screen

Full Screen

baseframe.py

Source:baseframe.py Github

copy

Full Screen

1# _*_ coding:utf-8 _*_2__author__ = 'bobby'3__date__ = '2018/10/9 15:55'4import os5import uiautomator2 as u26import time7from util.gettimestr import GetTimeStr #导入获取时间串函数8class BaseFrame:9 def __init__(self,outdevice=None):10 if outdevice==None:11 # self.d = u2.connect('192.168.199.168')12 self.d = u2.connect_usb('810EBM32TZ4K')13 else:14 self.d = u2.connect_usb(outdevice)15 self.timeStr = GetTimeStr() # 实例化16 def adbshell(self,order):17 d = self.d18 d.adb_shell(order)19 print('输入shell命令:',order,'。\n')20 def startapp(self,packagename):21 d = self.d22 d.app_start(packagename)23 print('启动包名为[%s]的应用---------'% packagename)24 # print('设备信息:', d.device_info)25 self.delaytime(3)26 def delaytime(self,dalaytime):27 dalaytime = int(dalaytime)28 time.sleep(dalaytime)29 print('等待%d秒...'% dalaytime)30 def findbyresourceId(self,resourceId):31 d = self.d32 try:33 ele = d(resourceId=resourceId)34 eletext = self.geteleinfo_text(ele)35 if eletext == "":36 print("定位到resourceId为[%s]的控件。" % resourceId)37 else:38 print("定位到text为[%s]的控件。" % eletext)39 return ele40 except Exception as e:41 self.getScreenshotError()42 self.printredword()43 print("出错原因:",e)44 self.printnormalword()45 self.delaytime(3)46 def findbyresourceId_and_input(self,resourceId,inputtext):47 ele = self.findbyresourceId(resourceId)48 self.ele_input(ele, inputtext)49 def findbyresourceId_and_click(self,resourceId,outpretoastmessage=None):50 ele = self.findbyresourceId(resourceId)51 toastmessage = self.ele_click_and_return_toastmessage(ele,outpretoastmessage)52 return toastmessage53 def findbyresourceId_and_return_enabledstatus(self,resourceId):54 ele = self.findbyresourceId(resourceId)55 eleinfo_enabled = self.geteleinfo_enabled(ele)56 return eleinfo_enabled57 def findbyresourceId_and_return_text(self,resourceId):58 ele = self.findbyresourceId(resourceId)59 eleinfo_text = self.geteleinfo_text(ele)60 return eleinfo_text61 def findbyresourceId_and_return_selectedstatus(self,resourceId):62 ele = self.findbyresourceId(resourceId)63 eleinfo_selected= self.geteleinfo_selected(ele)64 return eleinfo_selected65 def findbytext(self,text):66 d = self.d67 try:68 ele = d(text=text)69 eletext = self.geteleinfo_text(ele)70 if eletext == "":71 print("没有定位到控件。")72 else:73 print("定位到text为[%s]的控件。" % eletext)74 return ele75 except Exception as e:76 self.getScreenshotError()77 self.printredword()78 print("出错原因:",e)79 self.printnormalword()80 self.delaytime(3)81 def findbytext_and_input(self,text, inputtext):82 ele = self.findbytext(text)83 self.ele_input(ele,inputtext)84 def findbytext_and_click(self,text,outpretoastmessage=None):85 ele = self.findbytext(text)86 toastmessage = self.ele_click_and_return_toastmessage(ele,outpretoastmessage)87 return toastmessage88 def findbytext_and_return_enabledstatus(self,text):89 ele = self.findbytext(text)90 eleinfo_enabled = self.geteleinfo_enabled(ele)91 return eleinfo_enabled92 def findbytext_and_return_text(self,text):93 ele = self.findbytext(text)94 eleinfo_text = self.geteleinfo_text(ele)95 return eleinfo_text96 def findbytext_and_return_selectedstatus(self,text):97 ele = self.findbytext(text)98 eleinfo_selected= self.geteleinfo_selected(ele)99 return eleinfo_selected100 def ele_input(self,ele,inputtext):101 ele.clear_text()102 ele.send_keys(inputtext)103 print("输入:%s。" % inputtext)104 self.delaytime(1)105 def ele_click_and_return_toastmessage(self,ele,outpretoastmessage=None):106 ele.click()107 print("点击该控件。")108 if outpretoastmessage==None:109 self.delaytime(3)110 return None111 else:112 toastmessage = self.getToast()113 print("pretoastmessage:",outpretoastmessage)114 return toastmessage115 def geteleinfo_enabled(self,ele):116 value = 'enabled'117 eleinfo_enabled = self.geteleinfo_value(ele,value)118 print('该控件的enabled属性的值为:',eleinfo_enabled)119 return eleinfo_enabled120 def geteleinfo_text(self,ele):121 value = 'text'122 eleinfo_text = self.geteleinfo_value(ele,value)123 if eleinfo_text !='':124 print('该控件的text属性的值为:', eleinfo_text)125 return eleinfo_text126 def geteleinfo_selected(self,ele):127 value = 'selected'128 eleinfo_selected = self.geteleinfo_value(ele,value)129 if eleinfo_selected !='':130 print('该控件的selected属性的值为:', eleinfo_selected)131 return eleinfo_selected132 def geteleinfo_value(self,ele,value):133 eleinfo = ele.info134 # print('eleinfo:',eleinfo)135 eleinfo_value = eleinfo[value]136 return eleinfo_value137 def getToast(self):138 toastmessage = self.d.toast.get_message(5.0, default="")139 print("toastmessage:",toastmessage)140 return toastmessage141 def getdeviceinfo(self):142 deviceinfo = self.d.device_info143 print("deviceinfo:",deviceinfo)144 return deviceinfo145 def clickback(self):146 self.d.press("back")147 self.delaytime(1)148 def createwatcher(self):149 d = self.d150 d.watcher('crash').when(text='很抱歉,“QRindo MCH”已停止运行。').click(text="确定")151 d.watcher("crash").triggered152 print('d.watcher:',d.watcher)153 #打印红色文字154 def printredword(self):155 print('\033[1;31;0m') #<!--1-高亮显示 31-前景色红色 47-背景色白色-->156 #打印默认文字157 def printnormalword(self):158 print('\033[0m') # <!--采用终端默认设置,即取消颜色设置-->159 #打印绿色文字160 def printgreenword(self):161 print('\033[1;32;0m') # <!--1-高亮显示 32-前景色绿色 40-背景色黑色-->162 #获取时间串163 def getTimeStr(self):164 tStr = self.timeStr.getTimeStr()165 return tStr166 #出错时,获取页面截图167 def getScreenshotError(self):168 d = self.d169 self.printredword()170 print("调用截取图片函数")171 tStr = self.getTimeStr()172 # path = "../screenshots/screenpicture_%s.png"% tStr173 path = '%s/screenshots/screenpicture_%s.png'%(str(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))),tStr)174 self.printnormalword()175 d.screenshot(path)176 print("*****")177 print(path)178 print("*****")179 return path180 #正常,获取页面截图181 def getScreenshotNormal(self):182 d = self.d183 print("调用截取图片函数")184 tStr = self.getTimeStr()185 # path = "../screenshots/screenpicture_%s.png"% tStr186 path = '%s/screenshots/screenpicture_%s.png' % (str(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))), tStr)187 d.screenshot(path)188 print("*****")189 print(path)190 print("*****")191 return path192if __name__ == "__main__":193 bf = BaseFrame()...

Full Screen

Full Screen

MainPage.py

Source:MainPage.py Github

copy

Full Screen

1#!usr/bin/env python2#-*- coding:utf-8 -*-3from selenium.webdriver.common.by import By4from page_object.driver.AndroidClient import AndroidClient5from page_object.page.BasePage import BasePage6from page_object.page.MarketPage import MarketPage7from page_object.page.ProfilePage import ProfilePage8from page_object.page.SearchPage import SearchPage9from page_object.page.SelectedPage import SelectedPage10class MainPage(BasePage):11 _profile_button=(By.ID,"user_profile_icon")12 _search_button=(By.ID,"home_search")13 def gotoSelected(self):14 #调用全局的driver对象使用webdriver api操纵app15 zixuan=("自选")16 self.findByText(zixuan)17 self.findByText(zixuan).click()18 return SelectedPage()19 def gotoMarket(self):20 market=("行情")21 self.findByText(market)22 self.findByText(market).click()23 return MarketPage()24 def gotoSearch(self):25 self.find(self._search_button).click()26 return SearchPage()27 def gotoProfile(self):28 self.find(MainPage._profile_button).click()...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run websmith automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful