0

I have this test case

it("should have list", async () => {
    // wait until list populated
    browser.wait(protractor.until.elementLocated(by.css(COMPONENT_CSS.ITEM)));

    console.log("First...............");
    try {
        await componentPage.toggleDD();
    } catch (err) {
        console.log("err", err);
    }
    console.log("Second...............");
    const count = await componentPage.getCount();
    console.log("count", count);
    expect(count).toBe(this.COUNT);
    await componentPage.toggleDD();
});

and here is toggleDD

async toggleDD(): Promise<any> {
    const _dropdown = await element(by.id(this.CSS.DD_ID));
    await _dropdown.click();
}

but this shows

err ScriptTimeoutError: script timeout
  (Session info: chrome=84.0.4147.135)
  (Driver info: chromedriver=84.0.4147.30 (48b3e868b4cc0aa7e8149519690b6f6949e110a8-refs/branch-heads/4147@{#310}),platform=Windows NT 6.3.9600 x86_64)
    at Object.checkLegacyResponse (E:\PROJECTS\NewProject\node_modules\selenium-webdriver\lib\error.js:546:15)
    at parseHttpResponse (E:\PROJECTS\NewProject\node_modules\selenium-webdriver\lib\http.js:509:13)
    at E:\PROJECTS\NewProject\node_modules\selenium-webdriver\lib\http.js:441:30
    at processTicksAndRejections (internal/process/task_queues.js:94:5)
From: Task: Protractor.waitForAngular() - Locator: By(css selector, *[id="my-dropdown"])

and fails the test case, I have tried putting await before browser.wait, tried by.xpath, by.id, by.css to get dropdown.

I tried it in debug mode, elements are present on DOM but somehow it is not getting the element.

Checked other element to get for each element it is showing

- Failed: script timeout
    (Session info: chrome=84.0.4147.135)
    (Driver info: chromedriver=84.0.4147.30 (48b3e868b4cc0aa7e8149519690b6f6949e110a8-refs/branch-heads/4147@{#310}),platform=Windows NT 6.3.9600 x86_64)

I tried

<div id="dummyId">Hello</div>

with this div by

const _divText = await element(by.id("dummyId")).getText();

even for this I am getting scripttimeout err

More Info

Here is beforeAll

beforeAll(async () => {
    componentPage = new HomePage();
    helperService = new HelperService();

    COMPONENT_CSS = componentPage.CSS;
    await helperService.navigate(helperService.PAGE_URL.HOME);
    try {
        await helperService.skipIntro();
    } catch (err) {
        console.error("Intro element not found");
    }
    // browser.waitForAngular();
});

and protractor.conf.js

// Protractor configuration file, see link for more information
// https://github.com/angular/protractor/blob/master/lib/config.ts

const { SpecReporter } = require("jasmine-spec-reporter");

exports.config = {
    allScriptsTimeout: 50000,
    specs: [
        "./src/login/login.component.e2e-spec.ts",
        "./src/home/home.component.e2e-spec.ts",
    ],
    capabilities: {
        "browserName": "chrome"
    },
    directConnect: true,
    baseUrl: "http://localhost:4200/",
    framework: "jasmine",
    jasmineNodeOpts: {
        showColors: true,
        defaultTimeoutInterval: 1000000,
        print: function () {
        }
    },
    onPrepare() {
        require("ts-node").register({
            project: require("path").join(__dirname, "./tsconfig.e2e.json")
        });
        jasmine.getEnv().addReporter(new SpecReporter({ spec: { displayStacktrace: true } }));
    }
};
Sunil Garg
  • 14,608
  • 25
  • 132
  • 189
  • First glance, I am assuming this is async / await and not the control flow. `browser.wait` should be awaited. I'm guessing this is why the element is not visible on the screen when `toggleDD` has been called. Give it a try. If you get stuck, I could also write an answer – cnishina Aug 24 '20 at 07:15
  • @cnishina, tried that not working – Sunil Garg Aug 24 '20 at 12:51
  • @cnishina not able to produce in the demo project, though updated the question, included protractor.conf.js and beforeAll function, any other way arround to look into it – Sunil Garg Aug 31 '20 at 05:45
  • Sorry this has taken me a while to respond back. What kind of dropdown is it? Is it an angular material dropdown like https://material.angular.io/components/select/overview ? – cnishina Sep 11 '20 at 04:36
  • @cnishina yes angular material, tried to reproduce in demo project, but i am not able to.. – Sunil Garg Sep 11 '20 at 08:26

1 Answers1

0

Looking at the error, it appears that the element is not displayed before you want to interact with it. until.elementLocated appears to call into findElements and return the first element.

See https://github.com/SeleniumHQ/selenium/blob/trunk/javascript/node/selenium-webdriver/lib/until.js#L241

This means that it will return it if it is in the DOM but doesn't mean that it will be displayed or enabled to click. The isDisplayed call explicitly checks that the element is displayed.

See https://github.com/SeleniumHQ/selenium/blob/trunk/javascript/node/selenium-webdriver/lib/webdriver.js#L2296

Maybe instead do something like this?

it("should have list", async () => {
  // wait until list populated
  await browser.wait(async () => {
    return element(by.css(COMPONENT_CSS.ITEM)).isDisplayed();
  }, 10000);  // wait 10 seconds, make sure your protractor suite does not time out.
Sunil Garg
  • 14,608
  • 25
  • 132
  • 189
cnishina
  • 5,016
  • 1
  • 23
  • 40
  • will try and let you know – Sunil Garg Aug 27 '20 at 08:46
  • not working, same kind of code is working for login page, before home page i test login page that works fine. tried isDisplayed not working, even static div with some id, not able to find that, used debugger , when the control reach to debugger evverything is on dom – Sunil Garg Aug 27 '20 at 14:13
  • Do you have this to try out on GitHub? I think that might be the easiest way to help debug this. – cnishina Aug 27 '20 at 20:12
  • kind of private project, may you can try taking remote or on skype by screen sharing – Sunil Garg Aug 28 '20 at 05:15
  • Could you just create an example angular app with a material drop down menu that can duplicate your error? – cnishina Aug 28 '20 at 06:02