python-appium520-2引入unittest,编写自动化用例
Posted singleSpace
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python-appium520-2引入unittest,编写自动化用例相关的知识,希望对你有一定的参考价值。
unittest是python的测试框架,和junit相似。
test.py
import unittest
class Apptest(unittest.TestCase):
def setUp(self):
print("prepare")
def tearDown(self):
print("cleanup")
def test_c(self):
print("testc")
def test_a(self):
print("test a")
def test_b(self):
print("test b")
if __name__=="__main__":
unittest.main()
引入unittest
test2.py
import unittest
from appium import webdriver
from time import sleep
class Apptest(unittest.TestCase):
def setUp(self):
caps = {}
caps["platformName"] = "android"
caps["deviceName"] = "domo"
caps["appPackage"] = "com.xueqiu.android"
caps["appActivity"] = ".view.WelcomeActivityAlias"
caps["newCommandTimeout"] = 600
caps["automationName"] = "UiAutomator2"
self.driver = webdriver.Remote("http://localhost:4723/wd/hub", caps)
self.driver.implicitly_wait(20)
sleep(20)
def tearDown(self):
self.driver.quit()
def test_c(self):
print(self.driver.session_id)
def test_a(self):
self.driver.find_element_by_id("com.xueqiu.android:id/user_profile_icon").click()
sleep(1)
self.driver.find_element_by_id("com.xueqiu.android:id/tv_login").click()
sleep(1)
self.driver.find_element_by_id("com.xueqiu.android:id/tv_login_by_phone_or_others").click()
sleep(1)
self.driver.find_element_by_id("com.xueqiu.android:id/register_phone_number").send_keys("123456789")
sleep(3)
print(self.driver.session_id)
def test_b(self):
print("test b")
if __name__=="__main__":
unittest.main()
以上是关于python-appium520-2引入unittest,编写自动化用例的主要内容,如果未能解决你的问题,请参考以下文章