a p
a p

Reputation: 1271

Error locating element using Protractor - Failed: script timeout: result was not received in 20 seconds

I have a very basic website developed in Angular 6 and I am trying to write some e2e tests for it. But the first script itself is giving me a hard time. I am getting the following error -

C:\Users\user\Documents\workspace-vs-code\protractor-poc>protractor
[18:25:12] I/launcher - Running 1 instances of WebDriver
[18:25:12] I/direct - Using ChromeDriver directly...
[14500:21224:0129/182513.778:ERROR:configuration_policy_handler_list.cc(91)] Unk
nown policy: PasswordManagerAllowShowPasswords
[14500:21224:0129/182513.866:ERROR:configuration_policy_handler_list.cc(91)] Unk
nown policy: PasswordManagerAllowShowPasswords

DevTools listening on ws://127.0.0.1:58686/devtools/browser/22a05a0a-e850-47e3-b
a7b-fecc6ed97ac8
Jasmine started
(node:20576) [DEP0022] DeprecationWarning: os.tmpDir() is deprecated. Use os.tmp
dir() instead.

  service catalog search
    x should login
      - Failed: script timeout: result was not received in 20 seconds
        (Session info: chrome=71.0.3578.98)
        (Driver info: chromedriver=2.45.615291 (ec3682e3c9061c10f26ea9e5cdcf3c53
f3f74387),platform=Windows NT 6.1.7601 SP1 x86_64)
        (Session info: chrome=71.0.3578.98)
        (Driver info: chromedriver=2.45.615291 (ec3682e3c9061c10f26ea9e5cdcf3c53
f3f74387),platform=Windows NT 6.1.7601 SP1 x86_64)
          at Object.checkLegacyResponse (C:\Users\user\AppData\Roaming\npm\no
de_modules\protractor\node_modules\selenium-webdriver\lib\error.js:546:15)
          at parseHttpResponse (C:\Users\user\AppData\Roaming\npm\node_module
s\protractor\node_modules\selenium-webdriver\lib\http.js:509:13)
          at doSend.then.response (C:\Users\user\AppData\Roaming\npm\node_mod
ules\protractor\node_modules\selenium-webdriver\lib\http.js:441:30)
          at process._tickCallback (internal/process/next_tick.js:68:7)
      From: Task: Protractor.waitForAngular() - Locator: By(css selector, *[id="
password"])
          at Driver.schedule (C:\Users\user\AppData\Roaming\npm\node_modules\
protractor\node_modules\selenium-webdriver\lib\webdriver.js:807:17)
          at ProtractorBrowser.executeAsyncScript_ (C:\Users\user\AppData\Roa
ming\npm\node_modules\protractor\built\browser.js:425:28)
          at angularAppRoot.then (C:\Users\user\AppData\Roaming\npm\node_modu
les\protractor\built\browser.js:456:33)
          at ManagedPromise.invokeCallback_ (C:\Users\user\AppData\Roaming\np
m\node_modules\protractor\node_modules\selenium-webdriver\lib\promise.js:1376:14
)
          at TaskQueue.execute_ (C:\Users\user\AppData\Roaming\npm\node_modul
es\protractor\node_modules\selenium-webdriver\lib\promise.js:3084:14)
          at TaskQueue.executeNext_ (C:\Users\user\AppData\Roaming\npm\node_m
odules\protractor\node_modules\selenium-webdriver\lib\promise.js:3067:27)
          at asyncRun (C:\Users\user\AppData\Roaming\npm\node_modules\protrac
tor\node_modules\selenium-webdriver\lib\promise.js:2927:27)
          at C:\Users\user\AppData\Roaming\npm\node_modules\protractor\node_m
odules\selenium-webdriver\lib\promise.js:668:7
          at process._tickCallback (internal/process/next_tick.js:68:7)Error
          at ElementArrayFinder.applyAction_ (C:\Users\user\AppData\Roaming\n
pm\node_modules\protractor\built\element.js:459:27)
          at ElementArrayFinder.(anonymous function).args [as isDisplayed] (C:\U
sers\user\AppData\Roaming\npm\node_modules\protractor\built\element.js:91:29)

          at ElementFinder.(anonymous function).args [as isDisplayed] (C:\Users\
user\AppData\Roaming\npm\node_modules\protractor\built\element.js:831:22)
          at UserContext.<anonymous> (C:\Users\user\Documents\workspace-vs-co
de\protractor-poc\e2e\app.servicecatalogsearch.ts:17:44)
          at step (C:\Users\user\Documents\workspace-vs-code\protractor-poc\e
2e\app.servicecatalogsearch.ts:32:23)
          at Object.next (C:\Users\user\Documents\workspace-vs-code\protracto
r-poc\e2e\app.servicecatalogsearch.ts:13:53)
          at C:\Users\user\Documents\workspace-vs-code\protractor-poc\e2e\app
.servicecatalogsearch.ts:7:71
          at new Promise (<anonymous>)
          at __awaiter (C:\Users\user\Documents\workspace-vs-code\protractor-
poc\e2e\app.servicecatalogsearch.ts:3:12)
          at UserContext.<anonymous> (C:\Users\user\Documents\workspace-vs-co
de\protractor-poc\e2e\app.servicecatalogsearch.ts:51:16)
      From: Task: Run it("should login") in control flow
      From asynchronous test:
      Error
          at Suite.<anonymous> (C:\Users\user\Documents\workspace-vs-code\pro
tractor-poc\e2e\app.servicecatalogsearch.ts:15:5)
          at Object.<anonymous> (C:\Users\user\Documents\workspace-vs-code\pr
otractor-poc\e2e\app.servicecatalogsearch.ts:3:1)
          at Module._compile (internal/modules/cjs/loader.js:689:30)
          at Module.m._compile (C:\Users\user\Documents\workspace-vs-code\pro
tractor-poc\node_modules\ts-node\src\index.ts:422:23)
          at Module._extensions..js (internal/modules/cjs/loader.js:700:10)
          at Object.require.extensions.(anonymous function) [as .ts] (C:\Users\A
527629\Documents\workspace-vs-code\protractor-poc\node_modules\ts-node\src\index
.ts:425:12)

**************************************************
*                    Failures                    *
**************************************************

1) service catalog search should login
  - Failed: script timeout: result was not received in 20 seconds
    (Session info: chrome=71.0.3578.98)
    (Driver info: chromedriver=2.45.615291 (ec3682e3c9061c10f26ea9e5cdcf3c53f3f7
4387),platform=Windows NT 6.1.7601 SP1 x86_64)

Executed 1 of 1 spec (1 FAILED) in 24 secs.
[18:25:39] I/launcher - 0 instance(s) of WebDriver still running
[18:25:39] I/launcher - chrome #01 failed 1 test(s)
[18:25:39] I/launcher - overall: 1 failed spec(s)
[18:25:39] E/launcher - Process exited with error code 1

And my test script is -

import { browser, element, by, until, ExpectedConditions, By } from 'protractor';

describe('service catalog search', function() {

    it('should login', function() {
      browser.get('http://localhost:4200');
      element(by.id('password')).sendKeys('abc');
    });
  });

Now the problem is while sending keys. If I remove sendkeys, then it passes but don't know if it locates it properly.

Following is the html -

enter image description here

enter image description here

Upvotes: 0

Views: 1401

Answers (3)

a p
a p

Reputation: 1271

I got my answer here after struggling enough. Much thanks to Gleb to share it.

Instead of element(by), I used browser.driver.findElement

Upvotes: 1

Majesty
Majesty

Reputation: 1909

I notice that you put async keyword for it block, probably you are trying to implement async/await approach, in this case your code should look like so

it('should login', async function() {
  await browser.get('http://localhost:4200');
  await element(by.id('password')).sendKeys('abc');
});

If you doubt if an expression require await keyword, check protractor API and you will see, that, for example, sendKeys returns !webdriver.promise.Promise. Which means you should add await, otherwise protractor would not wait this step to be done before moving forward, which may cause an error, like the one you have.

P.S. To enable async/await you should put the following option in conf file

SELENIUM_PROMISE_MANAGER: false

Otherwise your code does not require async/await declaration and Web Driver Control Flow will do all the job for you, though it is currently deprecated and will be removed in a later moment.

Upvotes: 0

Buczkowski
Buczkowski

Reputation: 2416

I've set up a very basic test that is almost same as yours:

it('should have value', () => {
    browser.get('http://localhost:4200/register');
    element(by.id('email')).sendKeys('abc');

    expect(element(by.id('email')).getAttribute('value')).toEqual('abc');
});
  1. Get to register page (url)
  2. Get input element with id "email" and type to it some text
  3. Assert to check if that input element has previously typed text as a value

In my case, it works just fine. Can you add assert? Maybe that gives us more information what goes wrong.

Upvotes: 0

Related Questions