如果在步骤

时间:2015-08-11 08:18:03

标签: selenium-webdriver specflow

我已经实施了Specflow来重用某些功能,如本例所示 - Specflow,Selenium-Share data between different Step definitions or classes。但是,在我们的项目中,我们正在集成多个功能和功能。重用它们。根据上述方法,如果按照步骤触发浏览器会话,那么最好的方法是什么?

我的情景:

创建应用程序后,我需要启动新会话,登录不同的用户设置不同服务并批准它。

但登录失败后,在When的{​​{1}}步骤中,步骤定义4出现以下错误。该特定步骤来自不同的特征,因此需要在这些步骤中使用新会话。下面的Given(Set the service to (.*))方法只是用url启动网站,没有创建新会话 - 这很好用

  

OpenQA.Selenium.WebDriverException:意外错误。 System.Net.WebException:无法连接到远程服务器---> System.Net.Sockets.SocketException:无法建立连接,因为目标计算机主动拒绝它“IP here”

LaunchURl

其他功能

[Given(@"A New Application is added")]    
public void GivenANewApplicationIsAdded()
{
    Given("UK_The Service is set");
    Given("User Navigated to New Application screen");
    When("User fills up form as in data row 1");
    Then("new SID generated");
}

[Given(@"New Browser Launched")]
public void GivenNewBrowserLaunched()
{
    SeleniumContext sl = new SeleniumContext();
    this.seleniumContext = sl;
}


[Given(@"Login is successful with ""(.*)"" and ""(.*)""")]
public void GivenLoginIsSuccessfulWithAnd(string userName, string password)
{
    SuperTests spr = new SuperTests();
    _driver = spr.LaunchURL(seleniumContext.WebDriver);
    //seleniumContext.WebDriver = _driver;
    LoginPage lg = new LoginPage(_driver);
    lg.LoginProcess(userName, password);        
}

[Given(@"Set the service to ""(.*)""")]
public void GivenSetTheServiceTo(string serviceId)
{
    When("Select a Service from the option "+serviceId);
    Then("The Services is changed to the one selected " + serviceId);
}

围绕我们想象的2工作 创建绑定类的新实例以调用如下所示的方法或步骤

[When(@"Select a Service from the option (.*)")]    
public void WhenSelectAServiceFromTheOptionTestTeam(string p0)
{
    HomePage mst = new HomePage(seleniumContext.WebDriver);
    mst.SetServiceId(p0);
}

试过这个也很好用 - 基本上调用一个新方法来创建一个新会话。为此,我不需要为Binding类创建任何新实例。直接称之为步骤。

[Given(@"Set the service to ""(.*)""")]
public void GivenSetTheServiceTo(string serviceId)
{  
   var serIdSteps = new UK_SetServiceIDSteps(seleniumContext);
   serIdSteps.WhenUK_SelectAServiceFromTheOptionTest(serviceId);
   serIdSteps.ThenUK_TheServicesIsChangedToTheOneSelected(serviceId);
}

不确定,这是正确的做法吗?试图从可重用的步骤中找出它?后者不建议,因为我们需要更改浏览器的类型以便在多个位置启动。

0 个答案:

没有答案