环境:
python3.8+Appium+unittest+模拟器对有道云app进行测试
问题:在对Appium代码使用unittest框架改造之后,报了弃用的警告,查了很多资料也没看到有说怎么改。
使用ignore方法是可以忽视这个问题的,但是想知道一下如果不使用ignore的话,可以对代码进行何种修改呢,因为警告是弃用,那现在使用的新方法是什么呢?
代码如下:
# 使用unittest框架完成新增笔记的脚本
# 导入Appium类库
import time
from appium.webdriver.webdriver import WebDriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.wait import WebDriverWait
import unittest
# import warnings
# 定义测试类
class TestAddnote(unittest.TestCase):
def setUp(self):
# warnings.filterwarnings("ignore")
self.caps = {
'automationName': 'UiAutomator2',
'platformName': 'Android',
'platformVersion': '6.0',
'deviceName': '192.168.23.101:5555',
'appPackage': 'com.youdao.note',
'appActivity': '.activity2.MainActivity'}
self.driver = WebDriver('http://127.0.0.1:4723/wd/hub', self.caps)
self.driver.implicitly_wait(10)
def test_case1(self):
el = WebDriverWait(self.driver, 10).until(
lambda x: x.find_element(By.ID, 'com.android.packageinstaller:id/permission_allow_button'))
if el:
# 点击同意
self.driver.find_element(By.ID, 'com.android.packageinstaller:id/permission_allow_button').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.ID, 'com.youdao.note:id/btn_cancel').click()
# 输入内容
self.driver.find_element(By.XPATH,
'//*[@resource-id="com.youdao.note:id/note_content"]/android.widget.EditText').send_keys(
'testcontext1234')
# 输入标题
self.driver.find_element(By.ID, 'com.youdao.note:id/note_title').send_keys('testtitle')
# 点击完成
self.driver.find_element(By.ID, 'com.youdao.note:id/actionbar_complete_text').click()
time.sleep(1)
# 获取新增成功后的标题内容
real_title = self.driver.find_element(By.ID, 'com.youdao.note:id/title').text
self.assertEqual(real_title, 'testtitle', '新增笔记测试失败')
def tearDown(self):
self.driver.quit()
if __name__ == '__main__':
unittest.main()
警告信息如下:
C:\Python\Python39\python.exe "C:\Program Files\JetBrains\PyCharm Community Edition 2021.2.2\plugins\python-ce\helpers\pycharm\_jb_unittest_runner.py" --path D:/PythonTest/AppiumTest/unittest_fram/unittest_test_addnote.py
Testing started at 23:06 ...
Launching unittests with arguments python -m unittest D:/PythonTest/AppiumTest/unittest_fram/unittest_test_addnote.py in D:\PythonTest\AppiumTest\unittest_fram
Process finished with exit code 0
C:\Python\Python39\lib\site-packages\appium\webdriver\webdriver.py:274: DeprecationWarning: desired_capabilities has been deprecated, please pass in an Options object with options kwarg
super().__init__(
Ran 1 test in 16.542s
OK