简体   繁体   中英

Use the same page in Cucumber Scenario examples

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?

A scenario outline is just a way of writing several scenarios concisely. Each scenario starts from scratch and so will load the initial page. If you want to make this more efficient don't use scenario outlines and write less scenarios.

I really don't see why you need to test that the browser can navigate to the other window, I think we're pretty confident that clicking links in a browser works, so all you really need to do is test that the links or on the page. So you could write

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

and introducing the concept of the benefits_pdfs collection do something like

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

in your implementation. This gives you a scenario that runs probably 10 times faster and gives almost the same utility.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM