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!