2

I've found uses of the following, but no documentation for other possible actions using the browserstack_executor:

  1. fileExists
  2. getFileContent
  3. getFileProperties
  4. setSessionStatus

I'm looking for a removeFile or unlinkFile or deleteFile to remove a file that was downloaded by the browser and is now in the way when the next file downloads and gets a (1) added to the filename.

In my selenium test I'm doing something like this:

if driver._is_remote:
    action = {"action": "fileExists", "arguments": {"fileName": os.path.basename(self.filepath)}}
    if driver.execute_script(f'browserstack_executor:{json.dumps(action)}'):
        action = {"action": "getFileContent", "arguments": {"fileName": os.path.basename(self.filepath)}}

        content = driver.execute_script(f'browserstack_executor:{json.dumps(action)}')
        with open(self.filepath, "wb") as f:
            f.write(base64.b64decode(content))

        action = {"action": "deleteFile", "arguments": {"fileName": os.path.basename(self.filepath)}}
        delete_status = driver.execute_script(f'browserstack_executor:{json.dumps(action)}')

I keep getting invalid action with all of the 3 I've tried so there must be something else to get rid of a file on the machine at browserstack.

boatcoder
  • 17,525
  • 18
  • 114
  • 178

2 Answers2

0

I believe 'browserstack_executor' is a custom executor specific to BrowserStack and has a limited set of operations that it can perform.

The supported operations are available in their documentation: https://www.browserstack.com/docs/automate/selenium/test-file-upload https://www.browserstack.com/docs/automate/selenium/test-file-download

Hence, operations like removeFile or unlinkFile or deleteFile, cannot be performed, as they are not supported currently and are also not mentioned in the links shared above.

N3M
  • 286
  • 1
  • 3
  • I agree with the first paragraph, but set-session is not mentioned on those pages and it exists. I just want a list of what can be done..... – boatcoder Mar 04 '21 at 16:40
  • 1
    To be honest, Browserstack documentation just plain sucks. Topics are scattered without any clear logical hierearchy. For example, on [setSessionStatus](https://www.browserstack.com/docs/app-automate/appium/set-up-tests/mark-tests-as-pass-fail#mark-test-status-from-the-test-script-using-javascriptexecutor) page we can learn that such a function does exist, but what other JavascriptExecutor methods are available, if any - no, you're not supposed to be curious to know. – sunny moon Jun 14 '23 at 09:29
0

Per the companies support staff, there is no list and unlink is not supported. In order to work around it I've modified the FileExists ExpectedCondition I was using to auto increment the filename after one is pulled from the test system and to use the "next available" name so that my tests can be the same running locally or on browser stack.

boatcoder
  • 17,525
  • 18
  • 114
  • 178