Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

93
Views
WebdriverIO JS how to only run code block if tests are running on Browserstack

I have some code in my hooks that runs while were running tests in Browserstack to update test results etc.

The line of code in question:

global.driver.execute(`browserstack_executor: ${JSON.stringify(result)}`)

The problem with having it running in the hooks is that it'll run even if we're running the tests locally.

This produces the error (which makes sense):

ERROR webdriver: Request failed with status 405 due to unknown method: Method is not implemented

Obviously we don't want this running at all when we're running the tests locally, so I wrapped it in a try catch. The issue is that the error is actually being thrown after the try catch so doesn't actually suppress the error at all.

I want to try and wrap this in an if statement that says "If we're running tests in Browserstack then..." however I'm unsure how to write this, or if anything like this exists at all.

Any help or other suggestions would be appreciated!

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!