如何使用Appium对iOS和Android进行相同的规格测试?

发布于 2025-02-13 15:27:07 字数 1174 浏览 0 评论 0原文

我使用Xamarin UI测试和Nunit进行了现有的UI测试。在我的测试课中,我能够用

[TestFixture(Platform.Android)]
[TestFixture(Platform.iOS)]

我可以在测试设置和执行中使用此课程来处理每个平台的不同内容,而VS中的测试跑步者将显示诸如“ logintest -ios -ios”,“ logintest -android)之类的东西”。

我已经切换到Appium,并且正在尝试使用SpecFlow,但是我无法弄清楚如何自动使单个方案目标两个平台。我不想将配置文件更改为运行iOS vs android,当我运行要同时运行的测试时,或者理想情况下,测试跑步者为每个平台显示不同的不同测试,但从同一功能/步骤派生代码。

我如何参数化每个平台的整个方案?

**更新 好的,所以我偶然发现了如何完成此操作,但是我仍然不确定这是否是最佳方法。

例如,在我的功能文件中,我有这样的:

Scenario Outline: Successful login
    Given the user is on login page
    And the user entered valid credentials
    When the user presses sign in button
    Then the user ends on dashboard page

Scenarios:
    |platform|
    |IOS|
    |Android|

添加方案表没有任何变量指定的表格将表添加到scepenariocontext.scenarioinfo.arguments [“ platform”]。它还向VS中的测试跑者添加了每个平台的条目。

我以这种方式看到的唯一真正的问题是您必须输入每个场景表方案大纲。似乎这可能会成为一场噩梦,以后进行大量测试,并说您想添加另一个平台。能够在每个功能文件中以某种方式包含或引用的外部文件中指定表将非常好,因为我可能会将其用于所有测试。

I had existing UI tests using Xamarin UI Test and NUnit. In my test class I was able to decorate the class with

[TestFixture(Platform.Android)]
[TestFixture(Platform.iOS)]

I could in turn use this in my test setup and execution to handle different thing per platform and the test runner in VS would show things like "LoginTest - iOS", "LoginTest - Android".

I have switched to Appium and I am trying to use Specflow, but I can't figure out how to make a single Scenario target both platforms automatically. I don't want to have to change a config file to run iOS vs Android, when I run the tests I want to run both, or ideally have the test runner display different distinct tests for each platform but derived from the same feature/step code.

How do I parameterize the entire Scenario per platform?

**UPDATE
Ok, so I have sort of stumbled on how to accomplish this but I am still not sure whether this is the optimal way.

In my feature file I have this for example:

Scenario Outline: Successful login
    Given the user is on login page
    And the user entered valid credentials
    When the user presses sign in button
    Then the user ends on dashboard page

Scenarios:
    |platform|
    |IOS|
    |Android|

Adding the Scenarios table with no variable specified adds the table to the scenarioContext.ScenarioInfo.Arguments["platform"]. It also adds an entry per platform to the test runner in VS.

enter image description here

The only real problem I see in this way is that you have to enter the Scenarios table of platforms for each Scenario Outline. This seems like it could become a nightmare later with tons of tests and say you want to add another platform. It would be great to be able to specify the table in an external file that was included or referenced some way by each feature file since I would likely use it for all my tests.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

秋千易 2025-02-20 15:27:07

好的,所以我偶然发现了nuget specflow.contrib.variants
这完全可以做到我想要的,我能够从我的OOB解决方案切换到软件包,而没有太多问题。

使用变体软件包,您可以使用类似的东西来装饰功能或方案,

@Platform:Android
@Platform:IOS

然后在测试跑者中获得这样的清洁视图:

这使我可以删除所有重复的重复:

Scenarios:
    |platform|
    |IOS|
    |Android|

很少设置,效果很好,我希望我先找到它。

https://github.com/totaltest/specflow.contrib.variants

Ok, so I stumbled upon the Nuget SpecFlow.Contrib.Variants.
This does exactly what I want and I was able to switch from my OOB workaround to the package without much issue.

With the Variants package you can decorate a feature or scenario with something like

@Platform:Android
@Platform:IOS

Then in test runner you get this much cleaner view like:
enter image description here

This allowed me to remove all my repeated:

Scenarios:
    |platform|
    |IOS|
    |Android|

Very little setup, works great, I wish I found it first.

https://github.com/totaltest/SpecFlow.Contrib.Variants

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文