I have been following the Appium tutorial on the official website. After following the steps and adapting their code template to the resource names/paths on my machine, I ran the test.js file using node.js and got the following error:
const elementId = await client.findElement("accessibility id","TextField1"); client.elementSendKeys(elementId.ELEMENT, "Hello World!");
^^^^^
SyntaxError: await is only valid in async function
at new Script (vm.js:84:7)
at createScript (vm.js:264:10)
at Object.runInThisContext (vm.js:312:10)
at Module._compile (internal/modules/cjs/loader.js:684:28)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:732:10)
at Module.load (internal/modules/cjs/loader.js:620:32)
at tryModuleLoad (internal/modules/cjs/loader.js:560:12)
at Function.Module._load (internal/modules/cjs/loader.js:552:3)
at Function.Module.runMain (internal/modules/cjs/loader.js:774:12)
at executeUserCode (internal/bootstrap/node.js:342:17)
This is the content of the source file:
const wdio = require("webdriverio");
const opts = {
port: 4723,
capabilities: {
platformName: "Android",
platformVersion: "8.1.0",
deviceName: "Android Emulator",
app: "/Users/guest/Downloads/ApiDemos-debug.apk",
automationName: "UiAutomator2"
}
};
const client = wdio.remote(opts);
const elementId = await client.findElement("accessibility id","TextField1");
client.elementSendKeys(elementId.ELEMENT, "Hello World!");
const elementValue = await client.findElement("accessibility id","TextField1");
await client.getElementAttribute(elementValue.ELEMENT,"value").then((attr) => {
assert.equal(attr,"Hello World!");
});