DEV Community

loading...
Cover image for Running CodeceptJS in BrowserStack Automate

Running CodeceptJS in BrowserStack Automate

alexandlazaris profile image Alexander Lazaris ・2 min read

Using a service like BrowserStack you can take your local automation tests to the skies. This is made possible by directing CodeceptJS to point to BrowserStack instead of running locally.

The BrowserStack service required is Automate, which runs tests using appium libraries on a plethora of mobile devices and operating systems. It also records tests by default, allowing you to review each scenario once complete.

Automate dashboard

To do so, you'll need to upload your mobile app. When successful, you'll receive an app_url in the response, which is the url to access the app in BrowserStack. This is how the devices provided by BrowserStack can access your application under test.

{
    "app_url": "bs://c8ddcb5649a8280ca800075bfd8f151115bba6b3",
    "custom_id": "SampleApp",
    "shareable_id": "steve/SampleApp"
}
Enter fullscreen mode Exit fullscreen mode

Next, you'll need to modify codecept.conf.js to run the tests in BrowserStack. Ensure you store sensitive info in an .env file and access using dotenv.

  helpers: {
    Appium: {
      host: "hub-cloud.browserstack.com",
      port: 4444,
      user: process.env.BROWSERSTACK_USER,
      key: process.env.BROWSERSTACK_KEY,
      platform: "Android",
      app: process.env.BROWSERSTACK_APP_URL,
      desiredCapabilities: {
        realMobile: "true",
        device: "Samsung Galaxy S9",
        os_version: "8.0",
        networkLogs : "true",
      }
    }
  },
Enter fullscreen mode Exit fullscreen mode

The new properties needed are:

  • host : your browserstack host url
  • user : your browserstack username
  • key : your browserstack accesskey
  • app : your uploaded app url
  • desiredCapabilities : choose your device + appium settings. More can be found here

With this set, you're all good to go. No changes are need to your individual test files. When you're ready, run tests as you normally would and you'll see each test run tracked in the BrowserStack dashboard.

Discussion (0)

pic
Editor guide