|
老师,在caps里如果不注释掉caps['automationName'] = 'UiAutomator2, send_keys方法就报错,java.lang.Thread.run(Thread.java:818)
不是只在unittest里,顺序执行时也有这个问题,看您的视频里并没有报错呀
# 使用unitest框架实现新增笔记的脚本
import unittest
from appium.webdriver.webdriver import WebDriver
from selenium.webdriver.support.wait import WebDriverWait
import time
class TestAddNote(unittest.TestCase):
def setUp(self):
self.desired_caps = dict()
self.desired_caps['automationName'] = 'UiAutomator2'
self.desired_caps['platformName'] = 'Android'
self.desired_caps['platformVersion'] = '6.0.1'
self.desired_caps['deviceName'] = 'CB5A294W2D'
self.desired_caps['unicodeKeyboard'] = True
self.desired_caps['appPackage'] = 'com.youdao.note'
self.desired_caps['appActivity'] = '.activity2.MainActivity t186'
self.driver = WebDriver('http://127.0.0.1:4723/wd/hub', self.desired_caps)
self.driver.implicitly_wait(10)
# 测试新增笔记
def test_case1(self):
if WebDriverWait(self.driver, 10).until(
lambda x: x.find_element_by_id('com.android.packageinstaller:id/permission_allow_button')):
self.driver.find_element_by_id('com.android.packageinstaller:id/permission_allow_button').click()
if WebDriverWait(self.driver, 10).until(lambda x: x.find_element_by_class_name('android.widget.ImageView')):
x1 = self.driver.get_window_size()['width'] * 0.85
x2 = self.driver.get_window_size()['width'] * 0.15
y1 = self.driver.get_window_size()['height'] * 0.5
self.driver.swipe(x1, y1, x2, y1)
self.driver.find_element_by_id('com.youdao.note:id/enter_app').click()
self.driver.find_element_by_id('com.youdao.note:id/add_note').click()
self.driver.find_element_by_id('com.youdao.note:id/add_note_floater_add_note').click()
self.driver.find_element_by_class_name('android.widget.FrameLayout').send_keys('content')
self.driver.find_element_by_id('com.youdao.note:id/note_title').send_keys('title')
self.driver.find_element_by_id('com.youdao.note:id/actionbar_complete_text').click()
time.sleep(3)
# 获取新增后的标题内容
rtitle = self.driver.find_element_by_id('com.youdao.note:id/title').text
self.assertEqual(rtitle, 'title', '新增笔记测试失败')
def tearDown(self):
self.driver.quit()
if __name__ == '__main__':
unittest.main() |
|