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()

python-appium520-3引入unittest,编写自动化用例-LMLPHP

引入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()
04-26 04:03