pytest符合命名约定,但不收集测试并导致没有运行测试

时间:2019-03-19 00:23:47

标签: python-3.x automated-tests pytest appium-ios python-appium

每当我尝试运行pytest test_clientLogin.py时,尽管我所知的模块和方法都符合pytest默认命名约定,但它会导致收集0个项目并且没有运行任何测试。我在这里想念什么吗?

import unittest
import os
from random import randint
from appium import webdriver
from time import sleep
from selenium.webdriver.common.keys import Keys

class Test_ClientLogin(unittest.TestCase):

    def setUp(self):
        app = ('/Users/myName/Library/Developer/Xcode/DerivedData/appName-adbzyybfvvcneaboeastjqennmqn/Build/Products/Debug-iphonesimulator/appName.app')
        self.driver = webdriver.Remote(
            command_executor='http://127.0.0.1:4723/wd/hub',
            desired_capabilities={
                'app': app,
                 'platformName': 'iOS',
                  'platformVersion': '12.1',
                  'deviceName': 'iPhone 8'
                }
        )

        def test_emailField(self):
            el1 = driver.find_element_by_xpath("//XCUIElementTypeApplication[@name=\"appName\"]/XCUIElementTypeWindow[1]/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeTextField")
            el1.send_keys("myEmail@gmail.com")
            sleep(1)
            self.assertNotEqual(el1.get_attribute("value"), "myEmail@gmail.com")

        def test_passwordField(self):
            el2 = driver.find_element_by_xpath("//XCUIElementTypeApplication[@name=\"appName\"]/XCUIElementTypeWindow[1]/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeSecureTextField")
            el2.send_keys("myPassword")
            sleep(1)
            self.assertNotEqual(el2.get_attribute("value"), "myPassword")

        def test_login(self):
                self.test_emailField()
                self.test_passwordField()
                el3 = driver.find_element_by_accessibility_id("Log In")
                el3.click()
                sleep(1)
                smiley = driver.find_element_by_xpath("""//XCUIElementTypeNavigationBar[@name="Journal"]""")
                self.assertNotEqual(smiley.get_attribute("name"), "Journal")

        def tearDown(self):
                self.driver.quit()

if __name__ == '__main__':
    suite = unittest.TestLoader().loadTestsFromTestCase(Test_ClientLogin)
    unittest.TextTestRunner(verbosity=2).run(suite)`

1 个答案:

答案 0 :(得分:0)

尝试

import os
from random import randint
from appium import webdriver
from time import sleep
from selenium.webdriver.common.keys import Keys

class TestClientLogin():

    def setUp(self):
        app = ('/Users/myName/Library/Developer/Xcode/DerivedData/appName-adbzyybfvvcneaboeastjqennmqn/Build/Products/Debug-iphonesimulator/appName.app')
        self.driver = webdriver.Remote(
            command_executor='http://127.0.0.1:4723/wd/hub',
            desired_capabilities={
                'app': app,
                 'platformName': 'iOS',
                  'platformVersion': '12.1',
                  'deviceName': 'iPhone 8'
                }
        )

        def test_email_field(self):
            el1 = driver.find_element_by_xpath("//XCUIElementTypeApplication[@name=\"appName\"]/XCUIElementTypeWindow[1]/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeTextField")
            el1.send_keys("myEmail@gmail.com")
            sleep(1)
            self.assertNotEqual(el1.get_attribute("value"), "myEmail@gmail.com")

        def test_password_field(self):
            el2 = driver.find_element_by_xpath("//XCUIElementTypeApplication[@name=\"appName\"]/XCUIElementTypeWindow[1]/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeSecureTextField")
            el2.send_keys("myPassword")
            sleep(1)
            self.assertNotEqual(el2.get_attribute("value"), "myPassword")

        def test_login(self):
                self.test_emailField()
                self.test_passwordField()
                el3 = driver.find_element_by_accessibility_id("Log In")
                el3.click()
                sleep(1)
                smiley = driver.find_element_by_xpath("""//XCUIElementTypeNavigationBar[@name="Journal"]""")
                self.assertNotEqual(smiley.get_attribute("name"), "Journal")

        def tearDown(self):
                self.driver.quit()

运行pytest test_clientLogin.py