【问题标题】:How to run Python test case with Appium?如何使用 Appium 运行 Python 测试用例?
【发布时间】:2018-04-15 00:08:11
【问题描述】:

我使用 Python(在 PyCharm 编辑器中)创建了简单的测试用例,它应该点击 iOS 应用程序上的加入/登录按钮,但它不起作用。代码如下:

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)

如果我运行这个测试用例,它会返回: "在 0.000 秒内运行 0 次测试

好的”

Appium 服务器已经在运行并且应用已经打开。在 PyCharm Preferences 中,我选择了 py.test 作为默认测试运行器。

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

【问题讨论】:

  • 你得到的错误是什么?
  • 所以,就像什么都没发生一样。我运行我的测试,这是我收到的消息:“”在 0.000 秒内运行 0 次测试“”。我在 appium 日志中看不到任何内容或单击该按钮,就像这段代码什么都不做,我不确定是否应该在 PyCharm 中设置任何偏好或代码不好。

标签: python ios pycharm appium appium-ios


【解决方案1】:

简单的代码怎么样:

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

【讨论】:

    【解决方案2】:

    我仍然不确定是什么问题,我尝试了很多东西,但它在 Pycharm 中不起作用,所以我在 Atom 编辑器中编写了代码并从终端使用命令运行它: "python -m py.test name_of_test.py -s" 就可以了。

    【讨论】:

      【解决方案3】:

      遇到了同样的问题。发现,“setUp”名称不是“test”大小写。 试试这个:

      def test_testcase1(self):
      

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

      【讨论】:

        【解决方案4】:

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

        test1.py
        

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

        def test_testcase1(self):
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2014-10-16
          • 1970-01-01
          • 2017-11-07
          • 2016-12-23
          • 1970-01-01
          • 2016-06-30
          • 2016-05-16
          • 2019-01-13
          相关资源
          最近更新 更多