Errors on previously running Javascript/Mocha iOS Automation


#1

A few months ago I had some Appium automation running successfully in Javascript using Mocha. I’ve moved over to a new laptop and app and replicated the same structure, but I’m receiving the below errors. Any help would be greatly appreciated!:

simon.g$ mocha ./login.test.js --timeout 1000000
2019-02-20T09:19:19.152Z DEBUG wdio-config: @wdio/sync not found, running tests asynchronous

(node:2338) UnhandledPromiseRejectionWarning: Error: Required option “capabilities” is missing
at validateConfig (/Users/simon.g/appium/node_modules/@wdio/config/build/utils.js:168:13)
at Object.remote (/Users/simon.g/appium/node_modules/webdriverio/build/index.js:28:45)
at Object. (/Users/simon.g/appium/login.test.js:6:21)
at Module._compile (internal/modules/cjs/loader.js:738:30)
at Object.Module._extensions…js (internal/modules/cjs/loader.js:749:10)
at Module.load (internal/modules/cjs/loader.js:630:32)
at tryModuleLoad (internal/modules/cjs/loader.js:570:12)
at Function.Module._load (internal/modules/cjs/loader.js:562:3)
at Module.require (internal/modules/cjs/loader.js:667:17)
at require (internal/modules/cjs/helpers.js:20:18)
at /usr/local/lib/node_modules/mocha/lib/mocha.js:250:27
at Array.forEach ()
at Mocha.loadFiles (/usr/local/lib/node_modules/mocha/lib/mocha.js:247:14)
at Mocha.run (/usr/local/lib/node_modules/mocha/lib/mocha.js:576:10)
at Object. (/usr/local/lib/node_modules/mocha/bin/_mocha:637:18)
at Module._compile (internal/modules/cjs/loader.js:738:30)
at Object.Module._extensions…js (internal/modules/cjs/loader.js:749:10)
at Module.load (internal/modules/cjs/loader.js:630:32)
at tryModuleLoad (internal/modules/cjs/loader.js:570:12)
at Function.Module._load (internal/modules/cjs/loader.js:562:3)
at Function.Module.runMain (internal/modules/cjs/loader.js:801:12)
at internal/main/run_main_module.js:21:11
(node:2338) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:2338) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
Login Test Suite
1) “before each” hook for “Onboarding Login Test”
2) “after each” hook for “Onboarding Login Test”

0 passing (9ms)
2 failing

  1. “before each” hook for “Onboarding Login Test”:
    TypeError: driver.init is not a function
    at Context.beforeEach (login.test.js:37:16)

  2. “after each” hook for “Onboarding Login Test”:
    TypeError: driver.end is not a function
    at Context.afterEach (login.test.js:43:16)

Here’s my code:

const wdio = require(‘webdriverio’);
const caps = require(’./helpers/desiredCapabilities’).options;
const driver = wdio.remote({
protocol: “http”,
host: “localhost”,
port: 4723,
path: “/wd/hub”,
desiredCapabilities: caps.desiredCapabilities
});

var chai = require(‘chai’);
var assert = require(‘chai’).assert;
//var expect = require(‘chai’).expect;
var chaiAsPromised = require(‘chai-as-promised’);
chai.use(chaiAsPromised);
chai.should();

var Switch = require(’./helpers/constants’);

beforeEach(async () => {
//console.log(“beforeEach”);
await driver.init();
});

afterEach(async () => {
//console.log(“afterEach”);
await driver.end();
});

describe(“Login Test Suite”, () => {

it(“Onboarding Login Test”, async () => {
await driver
.waitForEnabled(Switch.EnvContinue, 15000)
.element(Switch.EnvHeroku).click()
.element(Switch.EnvContinue).click()
.element(Switch.EnvConfirmPopupYes).click()

return driver.element(Switch.OnboardingSkip).isVisible().then(function (isOnboardingVisible) {
assert(isOnboardingVisible, “Onboarding is not visible”);
})
});

});


#2

Can you try running Appium Doctor?


#3

This is my appium-doctor outcome:

info AppiumDoctor Appium Doctor v.1.9.0
info AppiumDoctor ### Diagnostic for necessary dependencies starting ###
info AppiumDoctor :heavy_check_mark: The Node.js binary was found at: /usr/local/bin/node
info AppiumDoctor :heavy_check_mark: Node version is 11.10.0
info AppiumDoctor :heavy_check_mark: Xcode is installed at: /Applications/Xcode.app/Contents/Developer
info AppiumDoctor :heavy_check_mark: Xcode Command Line Tools are installed in: /Applications/Xcode.app/Contents/Developer
info AppiumDoctor :heavy_check_mark: DevToolsSecurity is enabled.
info AppiumDoctor :heavy_check_mark: The Authorization DB is set up properly.
info AppiumDoctor :heavy_check_mark: Carthage was found at: /usr/local/bin/carthage
info AppiumDoctor :heavy_check_mark: HOME is set to: /Users/simon.g
info AppiumDoctor :heavy_check_mark: ANDROID_HOME is set to: /Users/simon.g/Library/Android/sdk
info AppiumDoctor :heavy_check_mark: JAVA_HOME is set to: /Library/Java/JavaVirtualMachines/jdk-11.0.2.jdk/Contents/Home
info AppiumDoctor :heavy_check_mark: adb exists at: /Users/simon.g/Library/Android/sdk/platform-tools/adb
info AppiumDoctor :heavy_check_mark: android exists at: /Users/simon.g/Library/Android/sdk/tools/android
info AppiumDoctor :heavy_check_mark: emulator exists at: /Users/simon.g/Library/Android/sdk/tools/emulator
info AppiumDoctor :heavy_check_mark: Bin directory of $JAVA_HOME is set
info AppiumDoctor ### Diagnostic for necessary dependencies completed, no fix needed. ###
info AppiumDoctor
info AppiumDoctor ### Diagnostic for optional dependencies starting ###
info AppiumDoctor :heavy_check_mark: Python required by node-gyp (used by heapdump) is installed at: /usr/bin/python. Installed version is: 2.7.10
WARN AppiumDoctor :heavy_multiplication_x: opencv4nodejs cannot be found.
WARN AppiumDoctor :heavy_multiplication_x: ffmpeg cannot be found
WARN AppiumDoctor :heavy_multiplication_x: fbsimctl cannot be found
info AppiumDoctor :heavy_check_mark: applesimutils is installed at: /usr/local/bin/applesimutils. Installed versions are: applesimutils 0.6.3
WARN AppiumDoctor :heavy_multiplication_x: idevicelocation cannot be found
info AppiumDoctor :heavy_check_mark: ios-deploy is installed at: /usr/local/bin/ios-deploy. Installed version is: 1.9.4
WARN AppiumDoctor :heavy_multiplication_x: ios_webkit_debug_proxy cannot be found
WARN AppiumDoctor :heavy_multiplication_x: bundletool.jar cannot be found
info AppiumDoctor ### Diagnostic for optional dependencies completed, 6 fixes possible. ###
info AppiumDoctor
info AppiumDoctor ### Optional Manual Fixes ###
info AppiumDoctor The configuration can install optionally. Please do the following manually:
WARN AppiumDoctor ➜ Why opencv4nodejs is needed and how to install it: https://github.com/appium/appium/blob/master/docs/en/writing-running-appium/image-comparison.md
WARN AppiumDoctor ➜ ffmpeg is needed to record screen features. Please read https://www.ffmpeg.org/ to install it
WARN AppiumDoctor ➜ Why fbsimctl is needed and how to install it: http://appium.io/docs/en/drivers/ios-xcuitest/
WARN AppiumDoctor ➜ idevicelocation is used to set geolocation for real device. Please read https://github.com/JonGabilondoAngulo/idevicelocation to install it
WARN AppiumDoctor ➜ ios_webkit_debug_proxy is used to proxy requets from Appium to MobileSafari running on real device. Please read https://github.com/google/ios-webkit-debug-proxy to install it
WARN AppiumDoctor ➜ bundletool.jar is used to handle Android App Bundle. Please read http://appium.io/docs/en/writing-running-appium/android/android-appbundle/ to install it
info AppiumDoctor
info AppiumDoctor ###
info AppiumDoctor
info AppiumDoctor Bye! Run appium-doctor again when all manual fixes have been applied!
info AppiumDoctor


#4

You should fix the problems.


#5

I’ve fixed some of them, but I don’t see how any of them are contributing to my issue.

opencv4nodejs and ffmpeg are for images and screen recording (irrelevant), bundletool.jar is for Android (irrelevant) and idevicelocation is used to set geolocation manually (irrelevant)


#6

Ok, full disclosure: I am not a javascript programmer. In my experience this board does best with Java questions, with most other languages having spotty knowledge at best.

I did some research but I can’t find what could be causing your error. If you have the old laptop still I would suggest the following:

  1. Run Appium Doctor there and compare the two. Maybe that would show you something that can be fixed.
  2. Try some kind of diff tool (Beyond Compare is good for this) on the two machines (just in the automation folder) to see what kind of differences you might find.

Finally, I found a good tutorial on the error you are seeing. Don’t know if it will help:

Good Luck.


#7

Thanks, I’d done some digging and discovered that it’s a result of a lot of changes when Webdriver released v5 which broke a lot of existing functionality. So I’m going to have to go back to the drawing board and try and rewrite it.


#8

I want to know how to solve the problem of idevicelocation cannot be found, I also met this problem, please advise, thank you


#9

Here’s the repo:

Install instructions on the link.