如何通过网站参数SeleniumGrid我使用C#MbUnit的硒电网实例

问题描述:

,我需要3度不同的环境中开发,QA和PROD运行相同的脚本。我在Selenium grid中启动3个不同的遥控器,但是如何将不同的网站网址传递给这些实例?我需要一个实例到开发站点,另一个到QA,另一个到PROD。如何通过网站参数SeleniumGrid我使用<strong>C#</strong>,<strong>MbUnit的</strong>和<strong>硒电网</strong>实例

这是一个使用TestNG的示例。在你的单元测试文件/脚本,你就会有一些看起来像这样:

public class LoginTest { 
    private static final HUB_URL = "http://theGridHubServer/wd/hub"; 

    @Parameters({ "appUrl" }) 
    public void loginTest(@Optional("http://theTestServer/login/") final String appUrl) { 

    // ... create RemoteWebDriver object/connections/capabilities here and execute test 
} 

并行执行它们,你需要配置一个TestNG的XML配置文件,这将是这个样子:

<suite name="Login Test Suite" parallel="tests" verbose="1" thread-count="8"> 
    <test name="Dev"> 
     <parameter name="appUrl" value="http://theDevServer/login"></parameter> 
     <classes> 
      <class name="package.to.your.test.class.LoginTest" /> 
     </classes> 
    </test> 
     <test name="QA"> 
     <parameter name="appUrl" value="http://theTestServer/login"></parameter> 
     <classes> 
      <class name="package.to.your.test.class.LoginTest" /> 
     </classes> 
    </test> 
    </test> 
     <test name="Prod"> 
     <parameter name="appUrl" value="http://theProdServer/login"></parameter> 
     <classes> 
      <class name="package.to.your.test.class.LoginTest" /> 
     </classes> 
    </test> 
</suite> 

然后你运行XML文件作为TestNG的测试,并假设你有符合您定义的webdriver的能力,至少有三个webdriver的客户端节点,这三个测试将被发送到集线器,然后将发它们与客户端节点并行,每个测试执行将使用不同的URL。

希望这会有所帮助!