0

I am starting to learn e2e test with Protractor in our Angular app. Now I am trying to test the routing in one of the pages. All this should do is to spin up a page object and click on the top row of our test data with the id 7. This (click)-Event triggers should trigger a routing event which takes me to the desired page.

forwarding.e2e-spec.ts

      let detailsPage: ForwardingDetailsPo;
      beforeAll(async () => {
        page = new ForwardingPagePo();
        await page.navigateTo();
        detailsPage = new ForwardingDetailsPo();
        table = await page.getForwardingTablePo();
        await table.getTable().getRow('7').click();
      });
      afterEach(async () => {
        await detailsPage.navigateTo('7');
      });
      it('should navigate to details', async (done) => {
        browser.getCurrentUrl().then(url => {
          expect(url).toContain('administration/forwardings/7');
          done();
          }
        );
      });

    }); 

After that I try to check if the url has changed. The automatically opened browser, on which the tests are run seems to execute the task perfectly, yet the test fails:

Expected 'http://localhost:4200/administration/forwardings' to contain 'administration/forwardings/7'.

I already checked that the row I try to click .isPresent().

As you can see I tryed to litter the code with awaits to avoid, that the test runs before the routing completes, but that does not seem to work perfectly.

Hints anyone?

______EDIT_______

The solution had nothing to do with the click itself, see my answer for details.

Chund
  • 355
  • 2
  • 15

2 Answers2

0

From what I see you navigate to 7 after checking url not before, because afterEach executes after each it block

Sergey Pleshakov
  • 7,964
  • 2
  • 17
  • 40
  • I should have mentioned, that the rows, do have click-event listeners which trigger the routing. Thanks i edited the question. – Chund Oct 01 '19 at 05:50
  • do you have any setup for step-by-step debugging? – Sergey Pleshakov Oct 01 '19 at 19:27
  • @RonaldHund ^ . – Sergey Pleshakov Oct 01 '19 at 19:28
  • and the standard browser.pause() and browser.debugger() do not even trigger as of my observation – Chund Oct 02 '19 at 07:24
  • yeah... same here. I debug with webstorm, its free first month and then session is limited to 30 mins. And the license is cheap anyway. I recommend you install it and setup debugging configuration like this https://stackoverflow.com/questions/20137109/how-to-debug-angular-protractor-tests-in-webstorm/53783055#53783055 it'll boost your ability of improving your tests. If I was dealing with your issue, this is how I would approach it, by executing step by step and seeing what's happening – Sergey Pleshakov Oct 02 '19 at 14:42
  • hi i was able to hook my code up to the crome debugger, that was quite helpful indeed. Thanks for the advice. – Chund Oct 04 '19 at 07:30
0

I just found the solutions and thought to share it here. My problem was timing based. I had some other tests that relied on BeforeEach functions to set up properly. In one of those I routed to my main page again. And since beforeAll gets executed before the beforeEach calls, the routing itself functioned like desired, but I was routing away practically immediatly.

Today I learned to not use beforeAll in some inner tests unless neccessary.

Chund
  • 355
  • 2
  • 15