【问题标题】:Structuring cucumber feature files for various mobile devices为各种移动设备构建黄瓜特征文件
【发布时间】:2017-12-07 17:36:29
【问题描述】:

我正在使用 Java、Cucumber-JVM、Appium 构建移动应用测试自动化。

对于各种场景,为了使场景更加详细,我们在场景/场景大纲/bdd 特征文件的背景开头添加了以下行。 例如:

 Given user with ios device "iPhone SE Simulator"
 And I select a book product
 And I select layout type "Square"

.. 另一个例子

 Given user with ios device "iPhone 7"
  And I select a book product
  And I select layout type "Square"

.. 另一个例子

 Given user with ios device "iPhone 6"
  And I select a book product
  And I select layout type "Tav"

现在,我们有很多设备,那么重用该步骤的最佳方法是什么。 我想避免在类型上使用场景大纲和参数化?

此外,如果功能文件的轻微重复/重复有助于轻松构建测试套件,我们可以接受。

请推荐

谢谢

【问题讨论】:

  • 不要使用故事情节中的设备参数,而是考虑使用 before 钩子或测试参数传递它。因此可以为多个设备重复相同的场景。
  • 从命令行传递设备,如 -Ddevice="iPhone 7",并在 beforeAll() 钩子中获取设备参数值,
  • 我们希望故事不言自明,即故事的第一行应该声明它将针对哪个移动设备执行。此外,围绕将 Mobile-type 作为参数传递到 BDD 中的这种方式构建了许多底层代码。请在这种情况下提出建议。/谢谢

标签: selenium appium cucumber-jvm


【解决方案1】:

如果您使用QAF,您可以简单地定义和使用属性

属性文件:

device.name=<your device name>

BDD

Given user with ios device "${device.name}"

还有更多的 qaf 支持 different way to set properties 以及 strong resource management for different environments。

【讨论】:

  • 谢谢。没有 QAF 是否有可能实现这一点:给定用户使用 ios 设备“${device.name}”?
【解决方案2】:

1) 从命令行指定设备:

-Ddevice="iPhone 6"

2) 在 All hook

之前从命令行捕获设备
class CLIParams {
  private static String device;
  public static void setDevice();
  public static String getDevice();
}

class Hook {
  @BeforeAll
  public beforeAll() {
    CLIParams.setDevice(System.getProperty("device", "iPhone 7"));
  }
}

3) 进入特征文件

Given user with mobile device "iPhone SE Simulator"
Given user with mobile device "iPhone 6"
Given user with mobile device "Google Neux"

4) 第一行的步骤定义

Given("^user with mobile device \"(.?)\"$", (device)->{
  // ignore the deivce from the step description
  // instead to use the device from command line
  CLIParams.getDevice();
})

5) 如何在eclipse中传递jvm args

对于其他 IDE,Intellij/NetBean 也应该有类似的地方来指定 jvm args,如果您通过命令行运行,只需将 -Ddevice="iPhon 7" 附加到命令

【讨论】:

  • 感谢您的解决方案。您能否告知如何在非 Maven 环境设置中传递 -Ddevice="iPhone 6" 。即在本地环境中运行 Cucumber runner。
  • 感谢您进一步详细说明。我在我的功能文件中添加了上述步骤定义。但只有最后一个正在执行:给定具有移动设备“Google Neux”的用户。我不清楚参数是如何传递的,您是否意味着我们需要将设备作为参数,例如 - (类似于我们在示例表中所做的)。请详细说明。谢谢
  • 请将三个 Given 分成 3 个场景在一个功能文件中,每个场景可能只允许一个 Given 语句。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2016-12-23
  • 1970-01-01
  • 1970-01-01
  • 2016-06-04
  • 1970-01-01
  • 1970-01-01
  • 2020-06-15
相关资源
最近更新 更多