adb devices
60
秒false
false
true
false
。true
:新会话之前完全卸载被测应用程序false
。true
#打开的app退出后重新启动
adb shell am start -S 包名/activity名
#打开的app不需要退出,直接使用当前页面
adb shell am start 包名/activity名
tools/bin
目录下的 uiautomatorviewer
程序pip install weditor
进行安装python -m weditor
即可Xpath
表达式中的一个函数contains()
函数匹配==属性值==中包含的==字符串==//*[contains(@属性,"属性值")]
contains()
函数定位的元素很容易为 list
contains()
函数内的属性名需要用 @
开始//*[@text="HK"]/..
//*[@text="HK"]/parent::*
//*[@resource-id="com.xueqiu.android:id/stock_layout"]/child::*
//*[@text="HK"]/../..
//*[@text="HK"]/parent::*/parent::*
//*[@resource-id="com.xueqiu.android:id/stock_layout"]/child::*/child::*
//*[@text="HK"]/ancestor::android.widget.RelativeLayout
//*[@text="HK"]/ancestor::android.widget.RelativeLayout[1]
//*[@text="HK"]/following-sibling::*
//*[@resource-id="com.xueqiu.android:id/stock_layout"]/following-sibling::*[@resource-id="com.xueqiu.android:id/price_layout"]
//*[@text="09988"]/preceding-sibling::*
//*[@resource-id="com.xueqiu.android:id/add_attention"]/preceding-sibling::*[@resource-id="com.xueqiu.android:id/price_layout"]
XPath
表达式中放置 2 个条件AND
两个条件都应该为真的情况下,才能找到元素//*[@resource-id="com.xueqiu.android:id/current_price" and @text="107.8"]
XPath
表达式中放置 2 个条件OR
的情况下,两个条件中的任何一个为真,就可找到元素。OR
定位获取的是并集//*[@resource-id="com.xueqiu.android:id/tv_stock_add_follow" or @text="加自选"]
and
定位是 2 个条件的交集or
定位是 2 个条件的是并集# ID 定位
driver.find_element_by_android_uiautomator('\
new UiSelector().resourceId("")')
# 组合定位
driver.find_element_by_android_uiautomator('\
new UiSelector().resourceId("com.xueqiu.android:id/tab_name").\
text("我的")')
driver.find_element(AppiumBy.CSS_SELECTOR,\
"#com\.xueqiu\.android\:id\/tv_search")
解析前:
{"using":"css selector",\
"value":"#com\\.xueqiu\\.android\\:id\\/tv_search"}
解析后:
{"strategy":"-android uiautomator",\
"selector":"new UiSelector().resourceId
(\"com.xueqiu.android:id/tv_search\")",...}
# 通过 id
elementById("someResourceID")`
-> `elementsByCss("#someResourceID")
# 通过 class
elementsByClassName("android.widget.TextView")`
-> `elementsByCss("android.widget.TextView")
# 通过 accessibility id
elementsByAccessibilityId("Some Content Description")`
-> `elementsByCss('*[description="Some Content Description"]')
# 通过 xpath
elementsByXpath("//android.widget.TextView[@description='Accessibility']")`
-> `elementsByCss("android.widget.TextView[description='Accessibility']")
def test_search1(self):
# 点击搜索框
element = self.driver.find_element(\
AppiumBy.CSS_SELECTOR,"#com\.xueqiu\.android\:id\/tv_search")
element.click()
# 向搜索框输入:alibaba
self.driver.find_element(AppiumBy.CSS_SELECTOR,
"#com\.xueqiu\.android\:id\/search_input_text"). \
send_keys("alibaba")
alibaba_element = self.driver.find_element(\
AppiumBy.CSS_SELECTOR, "*[text='阿里巴巴']")
displayed = alibaba_element.get_attribute("displayed")
print(displayed)
# 判断【阿里巴巴】可见
assert displayed == "true"
print(f"结束时间:{self.get_time()}")
xpath
可以找到 ``` //*[@class=“android.widget.Toast”]driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(50));
driver.findElement(AppiumBy.xpath("//*[@class=\"android.widget.Toast\"]"));
from appium import webdriver
from appium.webdriver.common.mobileby import MobileBy
class TestToast():
def setup(self):
desire = {
'platformName': 'android',
'platformVersion': '6.0',
'deviceName': 'emulator-5554',
'appPackage': 'io.appium.android.apis',
'appActivity': 'io.appium.android.apis.view.PopupMenu1',
#可以加也可以不加,现在默认就是uiautomator2
'automationName' : 'uiautomator2'
}
self.driver = webdriver.Remote("http://127.0.0.1:4723/wd/hub", desire)
self.driver.implicitly_wait(5)
def teardown(self):
self.driver.quit()
def test_toast(self):
self.driver.find_element(MobileBy.ACCESSIBILITY_ID,"Make a Popup!").click()
self.driver.find_element(MobileBy.XPATH,"//*[@text='Search']").click()
# print(self.driver.page_source)
# print(self.driver.find_element(MobileBy.XPATH, "//*[@class='android.widget.Toast']").text)
#获取toast弹框信息
print(self.driver.find_element(MobileBy.XPATH, "//*[contains(@text, 'Clicked popup')]").text)
driver.implicitly_wait(TIMEOUT)
WebDriverWait(self.driver,10).until(expected_conditions.visibility_of_element_located(LOCATOR))
NoSuchElementException
WebDriverWait
和 expected_conditions
两个类presence_of_element_located
判断元素是否被加到了 DOM 树里,并不代表该元素一定可见
WebDriverWait().until(expected_conditions.presence_of_element_located(元素对象))
visibility_of_element_located
判断某个元素是否可见,可见代表元素非隐藏,并且元素的宽和高都不等于 0
WebDriverWait().until(expected_conditions.visibility_of_element_located(元素定位符))
WebDriverWait(driver,time).until(lambda x:x.find_element_by_id("someId")
# 定义ActionChains 实例
actions = ActionChains(driver)
# 第一步:定义输入源
# ActionChains里有个属性是ActionBuilder类型的, 使用的就是w3c协议
# 可以定义鼠标指针源,键盘源,滚轮源事件
actions.w3c_actions = ActionBuilder(driver, mouse=PointerInput(interaction.POINTER_TOUCH, "touch"))
# 第二步:定义动作
# 移动到起点-> 按下-> 滑动-> 抬起
actions.w3c_actions.pointer_action.move_to_location(115, 183)
actions.w3c_actions.pointer_action.pointer_down()
actions.w3c_actions.pointer_action.move_to_location(362, 179)
actions.w3c_actions.pointer_action.release()
actions.perform()
driver.makeGsmCall(PHONE_NUMBER, GsmCallActions.CALL);
driver.makeGsmCall(PHONE_NUMBER, GsmCallActions.ACCEPT);
driver.makeGsmCall(PHONE_NUMBER, GsmCallActions.CANCEL);
driver.sendSMS("555-123-4567", “Appium Test”);
self.driver.set_network_connection(1)
self.driver.set_network_connection(4)
def set_network_connection(self, connection_type: int) -> int:
"""Sets the network connection type. Android only.
Possible values:
+--------------------+------+------+---------------+
| Value (Alias) | Data | Wifi | Airplane Mode |
+====================+======+======+===============+
| 0 (None) | 0 | 0 | 0 |
+--------------------+------+------+---------------+
| 1 (Airplane Mode) | 0 | 0 | 1 |
+--------------------+------+------+---------------+
| 2 (Wifi only) | 0 | 1 | 0 |
+--------------------+------+------+---------------+
| 4 (Data only) | 1 | 0 | 0 |
+--------------------+------+------+---------------+
| 6 (All network on) | 1 | 1 | 0 |
+--------------------+------+------+---------------+
driver.rotate(Screenorientation.LANDSCAPE)
driver.rotate(Screenorientation.PORTRAIT)
self.driver.log_types
self.driver.get_log("logcat")
driver.lock()
driver.get_screenshot_as_file('./photos/img.png')
self.driver.start_recording_screen()
self.driver.stop_recording_screen()
最后:下面是配套学习资料,对于做【软件测试】的朋友来说应该是最全面最完整的备战仓库,这个仓库也陪伴我走过了最艰难的路程,希望也能帮助到你!【100%无套路免费领取】
被百万人刷爆的软件测试题库!!!谁用谁知道!!!全网最全面试刷题小程序,手机就可以刷题,地铁上公交上,卷起来!
涵盖以下这些面试题板块:
1、软件测试基础理论 ,2、web,app,接口功能测试 ,3、网络 ,4、数据库 ,5、linux
6、web,app,接口自动化 ,7、性能测试 ,8、编程基础,9、hr面试题 ,10、开放性测试题,11、安全测试,12、计算机基础