klamping / ui-testing-book

Content for "The Web App Testing Guidebook"
https://leanpub.com/webapp-testing-guidebook/
Other
29 stars 8 forks source link

code in 2.1.5 does not work #10

Closed salmankhilji closed 8 months ago

salmankhilji commented 3 years ago

The example code from section 2.1.5, copied from the manuscript folder of the book contents from GitHub, does not work.

describe('Homepage', function () {
  it('should load properly', function () {
    browser.url('./');
    console.log(browser.getTitle());
    $('=Sign in').click();
    console.log(browser.getUrl());
  });
});
$ npx wdio --logLevel=trace

Execution of 1 workers started at 2021-05-30T06:48:06.591Z

2021-05-30T06:48:06.592Z DEBUG @wdio/utils:initialiseServices: initialise service "chromedriver" as NPM package
2021-05-30T06:48:06.606Z INFO @wdio/cli:launcher: Run onPrepare hook
2021-05-30T06:48:06.606Z INFO chromedriver: Start Chromedriver (/home/precor/Developer/ui-testing/wdio-realworld/node_modules/chromedriver/lib/chromedriver/chromedriver) with args --port=9515 --url-base=/
2021-05-30T06:48:06.612Z INFO chromedriver: Starting ChromeDriver 90.0.4430.24 (4c6d850f087da467d926e8eddb76550aed655991-refs/branch-heads/4430@{#429}) on port 9515
2021-05-30T06:48:06.612Z INFO chromedriver: Only local connections are allowed.
2021-05-30T06:48:06.612Z INFO chromedriver: Please see https://chromedriver.chromium.org/security-considerations for suggestions on keeping ChromeDriver safe.
2021-05-30T06:48:06.612Z INFO chromedriver: ChromeDriver was started successfully.
2021-05-30T06:48:06.613Z DEBUG @wdio/cli:utils: Finished to run "onPrepare" hook in 7ms
2021-05-30T06:48:06.614Z INFO @wdio/cli:launcher: Run onWorkerStart hook
2021-05-30T06:48:06.614Z DEBUG @wdio/cli:utils: Finished to run "onWorkerStart" hook in 0ms
2021-05-30T06:48:06.615Z INFO @wdio/local-runner: Start worker 0-0 with arg: --logLevel=trace
[0-0] 2021-05-30T06:48:06.882Z INFO @wdio/local-runner: Run worker command: run
[0-0] 2021-05-30T06:48:06.884Z DEBUG @wdio/config:ConfigParser: No compiler found, continue without compiling files
[0-0] 2021-05-30T06:48:06.885Z DEBUG @wdio/local-runner:utils: init remote session
[0-0] 2021-05-30T06:48:06.887Z DEBUG @wdio/utils:initialiseServices: initialise service "chromedriver" as NPM package
[0-0] RUNNING in chrome - /test/specs/navigation.js
[0-0] 2021-05-30T06:48:06.952Z DEBUG @wdio/local-runner:utils: init remote session
[0-0] 2021-05-30T06:48:06.953Z INFO webdriver: Initiate new session using the WebDriver protocol
[0-0] 2021-05-30T06:48:06.953Z INFO webdriver: [POST] http://localhost:9515/session
[0-0] 2021-05-30T06:48:06.953Z INFO webdriver: DATA {
[0-0]   capabilities: {
[0-0]     alwaysMatch: { browserName: 'chrome', acceptInsecureCerts: true },
[0-0]     firstMatch: [ {} ]
[0-0]   },
[0-0]   desiredCapabilities: { browserName: 'chrome', acceptInsecureCerts: true }
[0-0] }
2021-05-30T06:48:07.136Z WARN chromedriver: [1622357287.137][WARNING]: This version of ChromeDriver has not been tested with Chrome version 91.
[0-0] 2021-05-30T06:48:07.184Z INFO webdriver: COMMAND getTitle()
[0-0] 2021-05-30T06:48:07.184Z INFO webdriver: [GET] http://localhost:9515/session/fa648a7ac9fc3cf4e7eeed783cb8ca1b/title
[0-0] Promise { <pending> }
[0-0] 2021-05-30T06:48:07.186Z INFO webdriver: COMMAND findElement("link text", "Sign in")
[0-0] 2021-05-30T06:48:07.186Z INFO webdriver: [POST] http://localhost:9515/session/fa648a7ac9fc3cf4e7eeed783cb8ca1b/element
[0-0] 2021-05-30T06:48:07.187Z INFO webdriver: DATA { using: 'link text', value: 'Sign in' }
[0-0] 2021-05-30T06:48:07.189Z INFO webdriver: COMMAND navigateTo("http://localhost:8080/")
[0-0] 2021-05-30T06:48:07.189Z INFO webdriver: [POST] http://localhost:9515/session/fa648a7ac9fc3cf4e7eeed783cb8ca1b/url
[0-0] 2021-05-30T06:48:07.189Z INFO webdriver: DATA { url: 'http://localhost:8080/' }
[0-0] TypeError in "Homepage should load properly"
TypeError: $(...).click is not a function
    at Context.<anonymous> (/home/precor/Developer/ui-testing/wdio-realworld/test/specs/navigation.js:5:19)
    at Context.executeAsync (/home/precor/Developer/ui-testing/wdio-realworld/node_modules/@wdio/utils/build/shim.js:136:25)
    at Context.testFrameworkFnWrapper (/home/precor/Developer/ui-testing/wdio-realworld/node_modules/@wdio/utils/build/test-framework/testFnWrapper.js:45:32)
[0-0] 2021-05-30T06:48:07.193Z INFO webdriver: COMMAND deleteSession()
[0-0] 2021-05-30T06:48:07.193Z INFO webdriver: [DELETE] http://localhost:9515/session/fa648a7ac9fc3cf4e7eeed783cb8ca1b
[0-0] 2021-05-30T06:48:07.201Z INFO webdriver: RESULT 
[0-0] 2021-05-30T06:48:07.239Z INFO webdriver: RESULT {
[0-0]   error: 'no such element',
[0-0]   message: 'no such element: Unable to locate element: {"method":"link text","selector":"Sign in"}\n' +
[0-0]     '  (Session info: chrome=91.0.4472.77)',
[0-0]   stacktrace: '#0 0x557071d3de89 <unknown>\n'
[0-0] }
2021-05-30T06:48:08.152Z DEBUG @wdio/local-runner: Runner 0-0 finished with exit code 1
[0-0] FAILED in chrome - /test/specs/navigation.js
2021-05-30T06:48:08.154Z INFO @wdio/cli:launcher: Run onComplete hook
2021-05-30T06:48:08.155Z DEBUG @wdio/cli:utils: Finished to run "onComplete" hook in 0ms

 "spec" Reporter:
------------------------------------------------------------------
[chrome 91.0.4472.77 linux #0-0] Running: chrome (v91.0.4472.77) on linux
[chrome 91.0.4472.77 linux #0-0] Session ID: fa648a7ac9fc3cf4e7eeed783cb8ca1b
[chrome 91.0.4472.77 linux #0-0]
[chrome 91.0.4472.77 linux #0-0] » /test/specs/navigation.js
[chrome 91.0.4472.77 linux #0-0] Homepage
[chrome 91.0.4472.77 linux #0-0]    ✖ should load properly
[chrome 91.0.4472.77 linux #0-0]
[chrome 91.0.4472.77 linux #0-0] 1 failing (855ms)
[chrome 91.0.4472.77 linux #0-0]
[chrome 91.0.4472.77 linux #0-0] 1) Homepage should load properly
[chrome 91.0.4472.77 linux #0-0] $(...).click is not a function
[chrome 91.0.4472.77 linux #0-0] TypeError: $(...).click is not a function
[chrome 91.0.4472.77 linux #0-0]     at Context.<anonymous> (/home/precor/Developer/ui-testing/wdio-realworld/test/specs/navigation.js:5:19)
[chrome 91.0.4472.77 linux #0-0]     at Context.executeAsync (/home/precor/Developer/ui-testing/wdio-realworld/node_modules/@wdio/utils/build/shim.js:136:25)
[chrome 91.0.4472.77 linux #0-0]     at Context.testFrameworkFnWrapper (/home/precor/Developer/ui-testing/wdio-realworld/node_modules/@wdio/utils/build/test-framework/testFnWrapper.js:45:32)

Spec Files: 0 passed, 1 failed, 1 total (100% completed) in 00:00:01 

2021-05-30T06:48:08.157Z INFO @wdio/local-runner: Shutting down spawned worker
2021-05-30T06:48:08.409Z INFO @wdio/local-runner: Waiting for 0 to shut down gracefully
2021-05-30T06:48:08.409Z INFO @wdio/local-runner: shutting down

2 1 5-issue

Notice that the text of the link is "Sign in ". i.e., with a trailing space. I repeated the same with a trailing space, and still no go. Please help.

I am running the server with docker-compose.

cerebellum13 commented 3 years ago

Probably I have the same problem. For me helped simply install @wdio/sync.

klamping commented 8 months ago

I believe this has been fixed, but will be running through all the code examples in the near future and will double-check