0
votes

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
Case of new page opening in new tab - What is the reason for reloading the original page? Is there any impact on the original page due to new tab? If not then do not reload the original page... Case of new page opening in same tab - Have you tried browser.navigate().back() to go back one step to the original page?... - Grasshopper
I'm guessing you're going to the page at the start? You could wrap it in an if statement. If I am not already on this page, get the page. This will mean it does it once, or on failure. - KyleFairns
@Grasshopper and @kyle-fairns, added some more context. What is the reason for reloading the original page? None that I can tell. It appears to be the result of the Page definition file, but I'm not sure if it's how the Feature file is organized as well. If each example calls the page definition then I may be stuck. note I inherited the mess. This page was taking 2 minutes to check because they put a 5sec sleep on each run as they were not using Promises correctly to wait. Reduced it to 30 secs. I think I can shave off more if I can solve the reload problem. - javafueled
what is the goal of this test. If you just want to validate the urls you have 3 options. 1. Just get the href of the a tag and validate it. 2. put this in a unit test, if it's really for validating the url's this could be done much faster with for example karma jasmine 3. don't validate this, it's basic html work. The first 2 suggested options are depending on how you handle the link. If there is a lot of Angular code that handles the click, processes stuff and then opens a tab, then you are right, if not (option 3), don't waste your time in automating these kind of tests in the GUI. - wswebcreation
@wswebcreation oh, I agree. That aside: How do I stop the original page from reloading on each run through the Examples? That's the root of the question. Something the original maintainer wrote is doing it, I think it's the Page definition visit(url) function, but I'm not sure what I need to change and the documentation is sparse. - javafueled

1 Answers

1
votes

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.