await is only valid in async function' when running a test in js (webdriverio)
See original GitHub issueThe problem
I am running the code from the ‘Get Started’ page of the Appium website and I am running into the following error:
const field = await client.$("~TextField1");
^^^^^
SyntaxError: await is only valid in async function
Environment
- Appium version (or git revision) that exhibits the issue: 1.13.0
- Desktop OS/version used to run Appium: Windows 10
- Mobile platform/version under test: Android 8.0
- Real device or emulator/simulator: Android Emulator (Google Pixel 2)
- Appium CLI or Appium.app|exe: Appium App
Details
I ran the code exactly copied from the Appium website under ‘Get Started’ and I ran into the error described above.
Link to Appium logs
[info] [35m[Appium][39m Welcome to Appium v1.13.0 [info] [35m[Appium][39m Appium REST http interface listener started on 0.0.0.0:4723
Note: the logs don’t seem to show a connection to the Appium server running on localhost:4723 ocurring
Code To Reproduce Issue [ Good To Have ]
const wdio = require("webdriverio");
const opts = {
port: 4723,
capabilities: {
platformName: "Android",
platformVersion: "8.0",
deviceName: "Pixel 2 Android 8.0",
app: "./ApiDemos.apk",
automationName: "UiAutomator2"
}
};
const client = wdio.remote(opts);
const field = await client.$("~TextField1");
await field.setValue("Hello World!");
const value = await field.getValue();
assert.equal(value,"Hello World!");
Issue Analytics
- State:
- Created 4 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
await is only valid in async function - Stack Overflow
Well, the issue is that await can only be used inside an async function. That is, await makes a function asynchronous, so it...
Read more >Await is only valid in Async functions error in JavaScript
The "await is only valid in async functions" error occurs when the `await` keyword is used inside of a function that wasn't marked...
Read more >await is only valid in async function” - Support - Appium Discuss
Appium code generates “SyntaxError: await is only valid in async ... I ran the test.js file using node.js and got the following error:...
Read more >From Sync to Async - WebdriverIO
Async Transition The WebdriverIO testrunner can handle async and sync execution within the same test suite. This means that you can slowly migrate...
Read more >Await Is Only Valid in Async Function: Reasons and Solution
Await Is Only Valid in Async Function : Fixing the Error in JS ... The await is only valid in async function error...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
The “Getting Started” page was recently fixed. I guess it hasn’t been updated on appium.io.
See https://github.com/appium/appium/blob/master/docs/en/about-appium/getting-started.md
Try running with Node v12