question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

await is only valid in async function' when running a test in js (webdriverio)

See original GitHub issue

The 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] [Appium] Welcome to Appium v1.13.0 [info] [Appium] 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:closed
  • Created 4 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
imurchiecommented, Jun 5, 2019

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

0reactions
dpgrahamcommented, Jun 5, 2019

Try running with Node v12

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found