首页 > 解决方案 > browserstack_executor 操作列表在哪里?

问题描述

我发现了以下用途,但没有使用 browserstack_executor 的其他可能操作的文档:

  1. 文件已存在
  2. 获取文件内容
  3. 获取文件属性
  4. 设置会话状态

我正在寻找removeFileunlinkFiledeleteFile删除浏览器下载的文件,现在在下一个文件下载并在文件名中添加 (1) 时挡住了路。

在我的硒测试中,我正在做这样的事情:

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)}')

我一直invalid action在尝试我尝试过的所有 3 种方法,因此必须有其他东西可以摆脱浏览器堆栈机器上的文件。

标签: selenium-webdriverbrowserstack

解决方案


我相信“browserstack_executor”是特定于 BrowserStack 的自定义执行程序,它可以执行的操作集有限。

支持的操作可在其文档中找到: https ://www.browserstack.com/docs/automate/selenium/test-file-upload https://www.browserstack.com/docs/automate/selenium/test-file-下载

因此,无法执行诸如 removeFile 或 unlinkFile 或 deleteFile 之类的操作,因为它们当前不受支持,并且在上面共享的链接中也未提及。


推荐阅读