如何使用 Appium 运行 Python 测试用例?

How to run Python test case with Appium?

我使用 Python(在 PyCharm 编辑器中)创建了简单的测试用例,它应该点击 iOS 应用程序上的 Join/Login 按钮,但它没有工作。这是代码:

from appium import webdriver
import unittest
import os


class LoginTests(unittest.TestCase):
    def setUp(self):
        desired_caps = {}
        desired_caps['platformName'] = 'iOS'
        desired_caps['platformVersion'] = '11.0'
        desired_caps['deviceName'] = 'iPhone Simulator' # Run on simulator
        desired_caps['bundleId'] = 'com.matchbook.MatchbookApp'
        desired_caps['app'] = os.path.abspath('/Users/majdukovic/Library/Developer/Xcode/DerivedData/MatchBook-bgvchkbwrithuaegnjgpoffewdag/Build/Products/Debug-iphonesimulator/MatchBook.app') # Path to .app
        self.wd = webdriver.Remote('http://0.0.0.0:4723/wd/hub', desired_caps)
        self.wd.implicitly_wait(60)
        loginButton = self.wd.find_element_by_id("JOIN/LOGIN") # Button ID
        self.assertTrue(loginButton.is_displayed())
        loginButton.click()

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

如果我运行这个测试用例它returns: "运行 0.000 秒内进行 0 次测试

确定

Appium 服务器已经 运行ning 并且应用程序已打开。在 PyCharm 首选项中,我选择 py.test 作为默认测试 运行ner.

我的设置详情:
macOS - HighSierra v10.13
Appium 桌面应用程序 - v1.2.6
Python - v2.7.10
xCode - v9.0.1
模拟器 - iPhone 8,iOS v11.0

简单的代码怎么样:

if __name__ == '__main__':
  unittest.main()

我仍然不确定问题出在哪里,我尝试了很多东西,但它在 Pycharm 中不起作用,所以我在 Atom 编辑器和 [=14= 中编写了代码] 它来自终端命令: "python -m py.test name_of_test.py -s" 并且有效。

遇到同样的问题。发现,那个“setUp”的名字不是读作“test”的case。 试试这个:

def test_testcase1(self):

测试用例应命名为“test_*testcasename_or_whatever*(self)

文件名应为 test*.py ,例如:

test1.py

函数名应该是test*,例如:

def test_testcase1(self):