2016-11-10 58 views
0

的要求是創建三個用戶,然後創建一個模板/文件中添加這三個用戶是否可以寫兩個不同的集情景大綱例

我可以在一個場景輪廓實現這一目標?

Scenario Outline: Create users and load to a template 
Given I create an user <username> 
And the password as <password> 
And the description as <description> 

Example: 
| username | password | description | 

| user1 | pwd1   | user1creation | 

| user2 | pwd2   | user2creation | 

| user3 | pwd3   | user3creation | 

When user create a template ?????? 

任何人都可以建議如何編寫模板創建步驟並傳遞用戶名作爲參數嗎?

+0

您可以編寫多個示例表(U已放入示例中更改它)。在這種情況下,對多個表格的要求是什麼,似乎一張表格就足夠了。運行黃瓜時,您可以使用dryRun = true,缺失的步驟定義將自動打印在控制檯中。複製並粘貼這些。當你想要真正運行時移除dryRun。 – Grasshopper

+0

當我運行這個場景時,模板也會創建3次,但是需求是創建3個用戶,然後只創建一個模板並將用戶名輸入到這個模板 – sajida

+0

如果您使用Java設置了一個私有靜態標誌變量,並且在步驟定義類中將其設置爲false。在該模板創建的任何步驟中,檢查標誌值,如果爲false,則創建並設置爲true。如果爲true,則繞過模板創建。如果不使用Java,則使用適合您的語言的全局變量。 – Grasshopper

回答

0

方案可以這樣寫:

Scenario Outline: Create users and load to a template 
Given I have the following users: 
    | username | password | description | 
    | <username1> | <password1> | <description1> | 
    | <username2> | <password2> | <description2> | 
    | <username3> | <password3> | <description3> | 
When I create template for users: 
    | username | 
    | <username1> | 
    | <username2> | 
    | <username3> | 
Then users should be added to template 
Examples: 
    | username1 | password1 | description1 | username2 | password2 | description2 | username3 | password3 | description3 | 
    | user1  | pwd1  | user1creation | user2  | pwd2  | user2creation | user3  | pwd3  | user3creation | 

或者作爲不使用場景輪廓替代:

Scenario: Create users and load to a template 
Given I have the following users: 
    | username | password | description | 
    | user1 | pwd1  | user1creation | 
    | user2 | pwd2  | user2creation | 
    | user3 | pwd3  | user3creation | 
When I create template for users: 
    | username | 
    | user1 | 
    | user2 | 
    | user3 | 
Then users should be added to template 

在給定步驟的用戶這兩種情況下應定義,步驟定義創建和放在一些共享的地圖上,在何時可以將它們提取出來並添加到模板中。

+0

亞歷克斯感謝您的答覆 我認爲第二個方法是適合我的需求, 但在這裏我需要定義模板的名稱,以及 當我爲用戶創建模板: | templatename |用戶名| | template1 | user1 | | user2 | | user3 | 然後將用戶添加到模板 – sajida

+0

當我爲用戶創建模板時 | templatename |用戶名| | template1 | user1 | | | user2 | | | user3 | – sajida

+0

是的。您可以根據需要添加任意數量的表格列(如templateName),然後像使用DataTables一樣操作它。 –

相關問題