使用 MSTEST 在多个浏览器上运行 selenium
我使用 selenium 并使用 mstest 来驱动它。我的问题是我希望我的整个套件能够在 3 种不同的浏览器(IE、Firefox 和 Chrome)上运行。
我不明白的是如何在套件级别上数据驱动我的测试或如何使用不同的参数重新运行套件。
我知道我可以向所有测试添加一个数据源,并针对多个浏览器运行单独的测试,但随后我必须为每个测试复制数据源的两行,我认为这不是很好的解决方案。
那么有人知道我如何数据驱动我的程序集初始化吗?或者是否有其他解决方案。
Im using selenium and using mstest to drive it. My problem is i want my entire suite to run against 3 different browsers(IE,Firefox and chrome).
What i can't figure out is how to data drive my test on a suite level or how to rerun the suite with different paramateres.
I know i can add a datasource to all my tests and have the individual test run against multiple browsers but then i would have to duplicate the 2 lines for the datasource for every single test which i don't think is very good solution.
So anybody knows how i can data drive my assembly initialize? or if there's another solution.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这就是我所做的。这种方法的好处是它适用于任何测试框架(mstest、nunit 等),并且测试本身不需要关心或了解有关浏览器的任何信息。您只需确保方法名称仅在继承层次结构中出现一次。我已经使用这种方法进行了数百次测试,它对我很有效。
BaseTest中有以下方法:
使用方法如下:
<前><代码>[测试方法]
公共无效RunSomeKindOfTest()
{
运行浏览器测试(); //在基类中调用上面步骤3中的方法
}
私有无效 RunSomeKindOfTest( IWebDriver 驱动程序)
{
//测试。每个浏览器都会调用此方法,在每种情况下传递适当的驱动程序
...
}
This is what I did. The benefit of this approach is that it will work for any test framework (mstest, nunit, etc) and the tests themselves don't need to be concerned with or know anything about browsers. You just need to make sure that the method name only occurs in the inheritance hierarchy once. I have used this approach for hundreds of tests and it works for me.
Have the following methods in BaseTest:
Use as follows:
为此,我们编写了一个围绕 webdriver 的包装器,并使用基于属性的 switch 语句来选择浏览器类型。
这是一个片段。使用 DesiredCapability,您可以告诉网格要针对哪些浏览器执行。
To do this, we wrote a wrapper around webdriver and we use a switch statement based on a property to select the browser type.
Here's a snippet. Using the DesiredCapabilities, you can tell grid which browsers to execute against.
这个想法更适合自动化 CI 场景而不是交互式 UI,但您可以使用 runsettings 文件并声明一个参数:
您的测试类上需要一个 TestContext
然后在 MSTest 中,当您初始化驱动程序时,您可以检查您要运行哪个浏览器
然后您将运行测试套件 n 次,每个运行设置文件运行一次
This idea is better for an automated CI scenario rather than interactive UI, but you can use a runsettings file and declare a parameter in that:
You'll need a TestContext on your Test class
Then in your MSTest when you initialise the Driver you can check which browser you want to run
You would then run the suite of tests n times, once for each runsettings file