wswebcreation / webdriver-image-comparison

MIT License
43 stars 36 forks source link

Can't take a screenshot with Appium (browser.checkElement is not a function) #101

Closed Searcher865 closed 2 years ago

Searcher865 commented 2 years ago

Describe the bug 1) after launch, Chrome opens on Pixel 3 (Android Studio emulator). 2) URL is being navigated 3) Finds a layout element. 4) await browser.checkElement(await element, 'simple', {}) is called 5) Error appears in console "browser.checkElement is not a function" Playable for any other image comparison or image save function

Repeat for any other image comparison function or image save function

To Reproduce start Android Emulator Pixel 3 npm i npm test

https://github.com/Searcher865/wdio-with-appium-example-

Expected behavior Test completed successfully. A screenshot of the element is taken and saved.

2022-02-01T14:28:12.563Z INFO @wdio/cli:launcher: Run onPrepare hook
2022-02-01T14:28:12.570Z INFO chromedriver: Start Chromedriver (C:\automation\wdio-with-appium-example-\node_modules\chromedriver\lib\chromedriver\chromedriver.exe) with args --port=9515 --url-base=/
2022-02-01T14:28:12.597Z INFO chromedriver: Starting ChromeDriver 83.0.4103.39 (ccbf011cb2d2b19b506d844400483861342c20cd-refs/branch-heads/4103@{#416}) on port 9515
2022-02-01T14:28:12.598Z INFO chromedriver: Only local connections are allowed.
2022-02-01T14:28:12.598Z INFO chromedriver: Please see https://chromedriver.chromium.org/security-considerations for suggestions on keeping ChromeDriver safe.
2022-02-01T14:28:12.599Z INFO chromedriver: ChromeDriver was started successfully.
2022-02-01T14:28:16.060Z WARN @wdio/config:ConfigParser: pattern ./test/specs/check_form.ts did not match any file
2022-02-01T14:28:16.061Z INFO @wdio/cli:launcher: Run onWorkerStart hook
2022-02-01T14:28:16.062Z INFO @wdio/local-runner: Start worker 0-0 with arg: run,./wdio.conf.js
[0-0] 2022-02-01T14:28:16.639Z INFO @wdio/local-runner: Run worker command: run
[0-0] RUNNING in Android - C:\automation\wdio-with-appium-example-\test\specs\simple.ts
[0-0] 2022-02-01T14:28:20.973Z INFO webdriver: Initiate new session using the WebDriver protocol
[0-0] 2022-02-01T14:28:21.038Z INFO webdriver: [POST] http://localhost:4723/session
[0-0] 2022-02-01T14:28:21.039Z INFO webdriver: DATA {
[0-0]   capabilities: {
[0-0]     alwaysMatch: {
[0-0]       platformName: 'Android',
[0-0]       'appium:deviceName': 'Pixel 3',
[0-0]       'appium:platformVersion': '11.0',
[0-0]       'appium:automationName': 'UIAutomator2',
[0-0]       'appium:browserName': 'Chrome',
[0-0]       'appium:chromedriverExecutable': 'C:/WebDriver/bin/chromedriver.exe',
[0-0]       'appium:appiumVersion': '2.0.0-beta.25',
[0-0]       'appium:waitforTimeout': '30000',
[0-0]       'appium:commandTimeout': '30000'
[0-0]     },
[0-0]     firstMatch: [ {} ]
[0-0]   },
[0-0]   desiredCapabilities: {
[0-0]     platformName: 'Android',
[0-0]     'appium:deviceName': 'Pixel 3',
[0-0]     'appium:platformVersion': '11.0',
[0-0]     'appium:automationName': 'UIAutomator2',
[0-0]     'appium:browserName': 'Chrome',
[0-0]     'appium:chromedriverExecutable': 'C:/WebDriver/bin/chromedriver.exe',
[0-0]     'appium:appiumVersion': '2.0.0-beta.25',
[0-0]     'appium:waitforTimeout': '30000',
[0-0]     'appium:commandTimeout': '30000'
[0-0]   }
[0-0] }
[0-0] 2022-02-01T14:28:28.251Z INFO wdio-image-comparison-service: Adding commands to Multi Browser:  [
[0-0]   'maxInstances',
[0-0]   'platformName',
[0-0]   'appium:deviceName',
[0-0]   'appium:platformVersion',
[0-0]   'appium:automationName',
[0-0]   'appium:browserName',
[0-0]   'appium:chromedriverExecutable',
[0-0]   'appium:appiumVersion',
[0-0]   'appium:waitforTimeout',
[0-0]   'appium:commandTimeout',
[0-0]   'protocol',
[0-0]   'hostname',
[0-0]   'port',
[0-0]   'path'
[0-0] ]
[0-0] 2022-02-01T14:28:28.254Z ERROR @wdio/utils:shim: TypeError: Cannot read property 'browserName' of undefined
[0-0]     at getInstanceData (C:\automation\wdio-with-appium-example-\node_modules\wdio-image-comparison-service\build\utils.js:45:37)
[0-0]     at WdioImageComparisonService.addCommandsToBrowser (C:\automation\wdio-with-appium-example-\node_modules\wdio-image-comparison-service\build\service.js:86:53)
[0-0]     at WdioImageComparisonService.before (C:\automation\wdio-with-appium-example-\node_modules\wdio-image-comparison-service\build\service.js:67:14)
[0-0]     at C:\automation\wdio-with-appium-example-\node_modules\@wdio\utils\build\shim.js:88:27
[0-0]     at new Promise (<anonymous>)
[0-0]     at C:\automation\wdio-with-appium-example-\node_modules\@wdio\utils\build\shim.js:85:47
[0-0]     at Array.map (<anonymous>)
[0-0]     at executeHooksWithArgsShim (C:\automation\wdio-with-appium-example-\node_modules\@wdio\utils\build\shim.js:85:33)
[0-0]     at Runner.run (C:\automation\wdio-with-appium-example-\node_modules\@wdio\runner\build\index.js:99:48)
[0-0]     at processTicksAndRejections (node:internal/process/task_queues:93:5)
[0-0] 2022-02-01T14:28:28.266Z INFO webdriver: COMMAND navigateTo("https://webdriver.io/")
[0-0] 2022-02-01T14:28:28.266Z INFO webdriver: [POST] http://localhost:4723/session/1a9fb82b-c859-4faf-8294-0abd463c79f4/url
[0-0] 2022-02-01T14:28:28.266Z INFO webdriver: DATA { url: 'https://webdriver.io/' }
[0-0] 2022-02-01T14:28:32.617Z INFO webdriver: COMMAND findElement("css selector", ".hero__title")
[0-0] 2022-02-01T14:28:32.618Z INFO webdriver: [POST] http://localhost:4723/session/1a9fb82b-c859-4faf-8294-0abd463c79f4/element
[0-0] 2022-02-01T14:28:32.618Z INFO webdriver: DATA { using: 'css selector', value: '.hero__title' }
[0-0] 2022-02-01T14:28:32.685Z INFO webdriver: RESULT {
[0-0]   ELEMENT: 'c6f63576-45f4-4e92-825f-2a4967a78468',
[0-0]   'element-6066-11e4-a52e-4f735466cecf': 'c6f63576-45f4-4e92-825f-2a4967a78468'
[0-0] }
[0-0] TypeError in "Test one.Simple test"
TypeError: browser.checkElement is not a function
    at C:\automation\wdio-with-appium-example-\test\specs\simple.ts:18:23
    at Generator.next (<anonymous>)
    at fulfilled (C:\automation\wdio-with-appium-example-\test\specs\simple.ts:4:58)
    at processTicksAndRejections (node:internal/process/task_queues:93:5)
[0-0] 2022-02-01T14:28:32.722Z INFO webdriver: COMMAND deleteSession()
[0-0] 2022-02-01T14:28:32.723Z INFO webdriver: [DELETE] http://localhost:4723/session/1a9fb82b-c859-4faf-8294-0abd463c79f4
[0-0] FAILED in Android - C:\automation\wdio-with-appium-example-\test\specs\simple.ts
2022-02-01T14:28:33.247Z INFO @wdio/cli:launcher: Run onComplete hook
Report successfully generated to allure-report
Allure report successfully generated

I would be very grateful for any help.

wswebcreation commented 2 years ago

@Searcher865

Thanks for filing an issue. I need to dive into it a bit more but I already have some questions / remarks:

  1. "appium:browserName": "Chrome", this is not valid. browserName is a valid W3C cap, so it does not need to be pre-fixed
  2. Are these all the logs, if not, then the problem might be that it's not loading the service, it needs to be shown in the debug logs.
Searcher865 commented 2 years ago

@wswebcreation

  1. I'm sorry, maybe I still don't understand how it works so well since I'm just starting my way with Appium. I understand that this question is not related to webdriver-image-comparison. I tried writing different capabilities ("browserName": "Chrome", "browserName": "chrome", browserName: Chrome). I've also tried not writing browserName at all, but my Appium test only runs with "appium:browserName": "Chrome". I also read the documentation at https://github.com/appium/appium-uiautomator2-driver and it says about BrowserName.
  2. I put the logs in the repository link https://github.com/Searcher865/wdio-with-appium-example-/tree/master/logs
wswebcreation commented 2 years ago

See https://github.com/webdriverio/webdriverio/issues/7974#issuecomment-1030870647, closing this one