2015-08-28 24 views

回答

2

对没错。为什么不只是设置URL的步骤,将要使用的URL分配给某个变量(在类中,在ScenarioContext.Current中,或在自定义上下文对象中),然后在所有调用中使用此URL。在我的电话,以便格式化是一种痛苦,但这样的事情:

Given I'm using the site '<site>' 
    When I login 
    Then something should happen 
Examples: 
    |site   | 
    | aaa.com| 
    | bbb.com| 

然后在给定步骤只是记录的网址,并使用该基础URL构建完整的URL的时候一步。

你的步骤类可能看起来像这样。

[Binding] 
Public class Steps 
{ 
    Private string baseUrl; 
    [Given ("I'm using the site '(.*)'")] 
    Public void GivenImUsingTheSite(string baseUrl) 
    { 
      This.baseUrl=baseUrl; 
    } 

    [When ("I log in") 
    Public void WhenILogIn() 
    { 
      String URL=baseUrl + "\login"; 
      ....login 
    } 
} 
0

考虑以下方案概要:

Scenario Outline: Each page has an help option 
    Given I am on the '<PageName>' page that has id '<Id>' 
    Then I expect an help option 

Examples: 
    | PageName | Id | 
    | Home  | 0 | 
    | Products | 5 | 
    | FAQ  | 42 | 

然后你就可以做出让步是这样的:

[Given(@"I am on the '(.*)' page that has id '(.*)'")] 
public void GivenIAmOnThePageThatHasId(string friendlyName, string id) 
{ 
    // pageids are shaped like 'http://www.example.com/pageid?4' 
    var myUrl = @"http://www.example.com/pageid?" + id; 

    Console.WriteLine("Navigating to the {0} page following url {1}", friendlyName, myUrl); 
    NavigateToUrl(myUrl); 
} 
+0

的事情是,我们正在测试多个网站,所以网站会是这样: http://www.aaa.com http://www.bbb.com HTTP ://www.ccc.com 他们将运行相同的步骤,只是登录步骤之前的不同起始URL。 – AutomatedOrder

+0

我们使用[app.config](http://stackoverflow.com/questions/13043530/what-is-app-config-in-c-net-how-to-use-it)区分测试环境之间的设置。如果您将用户名与testenvironment和testenvironment连接到一组参数(如URL),则每个用户都可以拥有其他设置,并可以在瞬间改变测试环境。在'[BeforeTestRun]'钩子中,您可以获得用户名为'Environment.UserName'的环境,并在configfile中搜索正确的设置。在静态对象中使用这些设置或者在'ScenarioContext'中注入它们。 – AutomatedChaos

相关问题