Use the same page in Cucumber Scenario examples

时间:2017-04-10 01:43:46

标签: javascript protractor cucumber

Currently using Protractor 5.1.0 with cucumber-protractor-framework with Javascript.

In using the following Scenario Outline in the Feature file:

Feature: As an online customer
I should be able to validate the Benefits Page and links on it

Background:
Given I am on the "Benefits Page"

@regression @fixup
Scenario Outline: validation of the MyPage links
When I click on the "<link>" link
Then a new tab should be opened
Then I should be directed to the "<URL>" in new window

Examples:
|link                    |URL                                      |
|Benefit (PDF)           |/guide-to-benefit.pdf                    |
|Pro Benefit (PDF)       |/professional-benefit.pdf                |
|Signature Benefit (PDF) |/signature-guide-to-benefits-revised.pdf |
|Business Benefit (PDF)  |/business-benefits.pdf                   |

And the Page file follows:

var Benefits_Guide_Page = function (PageUrl) {

  this.visit = function (PageUrl) {
  browser.manage().deleteAllCookies();
  browser.get(PageUrl);
};

this.get_element = function (element_name) {
  switch (element_name) {

  //Links Navigates to different window

  case "Benefit (PDF)":
  case "Pro Benefit (PDF)":
  case "Signature Benefit (PDF)":
  case "Business Benefit (PDF)":
    return element(by.linkText(element_name));
    break;

  ... // continue element checks

Each scenario opens the tab, switches to the new tab, validates the URL, closes the new tab, switches to the original tab, and reloads the original page, starting the next example.

I think there is something of an answer in this Android Q&A, but I'm not sure it's the same problem.

Basically, I don't need the page to reload with each example. It's wasteful and time consuming in context of the larger test.

I have other scenarios where I'm checking links loading in the same window. I just need to go "back" and check the next link or same page anchor, not load the page again.

Any tips?

1 个答案:

答案 0 :(得分:1)

场景大纲只是简洁地编写几个场景的一种方式。每个场景都从头开始,因此将加载初始页面。如果您想提高效率,请不要使用场景大纲并编写更少的场景。

我真的不明白为什么你需要测试浏览器可以导航到另一个窗口,我认为我们非常有信心点击浏览器中的链接,所以你真的需要做的就是是测试链接或在页面上。那么你 可以写

Given I am on the benefits page
Then I should see the benefits pdf's

并引入了benefits_pdfs集合的概念,类似于

benefits_pdf.each do |pdf|
  page.should have_link pdf.link
end

在您的实施中。这为您提供了一个运行速度可能快10倍并且几乎提供相同实用程序的方案。