【问题标题】:"Desired Capabilities must be a dictionary" error when passing dict into parametrized method将 dict 传递给参数化方法时出现“所需功能必须是字典”错误
【发布时间】:2019-08-25 19:59:19
【问题描述】:

我正在使用 Appium 和 pytest 测试移动应用程序。当我尝试通过参数化的 pytest 标记传递字典列表时出现以下错误。

 WebDriverException: Message: Desired Capabilities must be a dictionary

当我不使用 @pytest.mark.parametrize() 并将所需功能作为字典直接传递给 webdriver.Remote 时,它工作正常。

为了更好地理解,我稍微简化了代码:

class TestQATestProject(object): 
  def get_all(self):
      return [
          {'platformName': 'Android'},
          {'platformName': 'Android'}
      ]


  @pytest.mark.parametrize('desired_caps', get_all())
  def setup_method(self, desired_caps):
      self.driver = webdriver.Remote('http://localhost:4723/wd/hub', 
  desired_caps)
      self.driver.implicitly_wait(5000)

[UPD] 我发现@pytest.mark.parametrize 不适用于setup_method。那么还有其他方法可以在不同的配置上运行测试吗?

【问题讨论】:

  • 我认为没有自我,因为装饰器在任何方法之外
  • 好吧,我的错,可以说会有一些 devices.get.all()。这不是重点
  • 仅使用print(desired_caps) 并将其与您期望的而不是webdriver 代码进行比较是否有效?因为我不相信你现在的代码会起作用:get_all 仍然是TestQATestProject 的实例方法。
  • @pytest.mark.parameterize 中的标记自 pytest 4.0 以来已被弃用,这可能会导致问题。如果您使用的是最新的 pytest,请通过给定的 url:docs.pytest.org/en/latest/deprecations.html
  • 非常感谢。 @pytest.mark.unit 解决了问题

标签: python automated-tests appium pytest python-appium


【解决方案1】:

@pytest.mark.unit 为我做了一笔交易

【讨论】:

    猜你喜欢
    • 2021-05-09
    • 1970-01-01
    • 2021-11-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-12-20
    • 2021-12-29
    • 1970-01-01
    相关资源
    最近更新 更多