1

I've got an Angular 6 app with e2e test I'm trying to make. In this test I first login, then trying to get all menu items and click over them, however I'm unable even to get a menu. My test results in timeout

should easily navigate by menu - Failed: script timeout: result was not received in 11 seconds (Session info: chrome=70.0.3538.77)

And first string from below (any way it doesn't make much sense)

From: Task: Protractor.waitForAngular() - Locator: [object Object] at Driver.schedule

describe('Walking through', () => {

    let page: AppPage;

    beforeEach(() => {
        page = new AppPage();
    });

    it('should be at proper url', () => {
        page.navigateTo();
        page.logIn(
            'test',
            'password'
        );
        expect(
            browser.wait(browser.ExpectedConditions.urlContains('dashboard'), 5000)
                .catch(() => false)
        ).toBeTruthy();
    });

    // Not working
    it('should easily navigate by menu', () => {
        const menu = element(by.css('.menu'));

        expect(menu).toBeTruthy();

        const menuItems = element(menu).all(by.tagName('li'));

        expect(menuItems).toBeTruthy();

        menuItems.each(e => {
            browser.sleep(500);
            e.click();
            expect(e).toBeTruthy();
        });
    });
});
Sergey
  • 7,184
  • 13
  • 42
  • 85
  • You don't navigate to your page in the second test, and you don't login. – JB Nizet Nov 23 '18 at 08:29
  • Of course, because I've done it before. It works continuously not running it from scratch if I don't specify so. Moreover, I've been observing the tests and it was staying right on the page it had to found an element. – Sergey Nov 23 '18 at 09:19
  • Tests are supposed to be independent of each other. And BTW jasmine now runs them in a random order, on purpose. – JB Nizet Nov 23 '18 at 09:21
  • It's a protractor which runs them by ORDER. Check it yourself. There is no logic in things you say in way of testing business logic. I may need to log in once, than a thousand times just for each test. – Sergey Nov 23 '18 at 09:42
  • https://www.protractortest.org/#/style-guide#make-your-tests-independent-from-each-other – JB Nizet Nov 23 '18 at 09:48
  • @JBNizet well you are right. Can I use `beforeAll` to not to reload app and log in again each time what is too costy? – Sergey Nov 23 '18 at 09:56
  • https://stackoverflow.com/questions/36687920/protractor-how-to-run-login-test-script-first – JB Nizet Nov 23 '18 at 09:59
  • @JBNizet but this is about when login isn't an angular app. Meanwhile, I do have an Angular app which does have login. Thus, if I make tests independently they need to start from base page or admin page, but session is built on socket connection and as soon as connection closed the session ceases. As we know browser.get opens a link as a simple request therefore angular is being refreshed and we got to log in once again. It's crazy to do this for each test. – Sergey Nov 23 '18 at 16:25
  • @JBNizet as it's said in docs "Make your tests independent at least at the file level" that meaning test files may run simultaneously BUT tests are ran in ORDER. I've been observing that myself that's why I've pointed on it. I've ran them more than 10 times and seen them run according to the order. – Sergey Nov 23 '18 at 16:58
  • I agree with that. It's still bad practice though, as explained later in the document, for the reasons explained later in the document. – JB Nizet Nov 23 '18 at 17:02
  • @JBNizet but, if we do read it carefully we may notice that it's mainly said about file scoped tests. Since we may have like `home.spec.ts` etc. they would run simultaneously, but tests inside those files are ran one by one. I've also tried to divide one login process into different `it`s and that worked. In first I've assigned login/password, in second I've clicked a button and check that my URL changed to what I needed. That's why I can't understand where the problem is to just take that poor element and go over. Because the page isn't reloaded between `it`. For me it makes no sense. – Sergey Nov 23 '18 at 17:25

0 Answers0