当前位置: 首页 > 知识库问答 >
问题:

无法在具有browserstack本地测试的移动real设备上从我的本地计算机上载文件

仲孙钊
2023-03-14

我正在使用Browserstack在本地机器(Windows 10)上托管的Web应用程序上执行一些测试。我使用Mocha和selenium-webdrive编写了测试。

我需要测试一个文件上传,从本地环境中选择一个文件。浏览Browserstack文档,我想我已经找到了解决方案,它可以在Windows和Mac OS配置下工作。

首先,我正在使用FileDetector

driver.setFileDetector(new remote.FileDetector);

然后我在fileInput WebElement上使用sendKeys()

fileInput.sendKeys(imageFilePath);

相反,当我在真正的iOS设备(iOS 13-iPhone 8.0)上运行测试会话时,我得到:

WebDriverError: Appium error: File upload is not supported on real iOS devices
    at Object.checkLegacyResponse (node_modules/selenium-webdriver/lib/error.js:546:15)
    at parseHttpResponse (node_modules/selenium-webdriver/lib/http.js:509:13)
    at doSend.then.response (node_modules/selenium-webdriver/lib/http.js:441:30)
    at process._tickCallback (internal/process/next_tick.js:68:7)
From: Task: remote.FileDetector.handleFile(/home/admin/BuildAgent/work/491c0dc9a984bb27/test/resources/images/imageUploader/partImage02.jpg)
    at WebDriver.schedule (node_modules/selenium-webdriver/lib/webdriver.js:807:17)
    at zip.addFile.then.then.then.encodedZip (node_modules/selenium-webdriver/remote/index.js:586:27)
From: Task: WebElement.sendKeys()
    at WebElement.sendKeys (node_modules/selenium-webdriver/lib/webdriver.js:2185:43)
    at [...]

在Android real设备上(例如Android Pixel 4-默认浏览器):

UnsupportedOperationError: The URL '/wd/hub/session/45359c9c6c467dd8f00f6c1a638c993fe933bf67/file' did not map to a valid resource
    at parseHttpResponse (node_modules/selenium-webdriver/lib/http.js:534:11)
    at doSend.then.response (node_modules/selenium-webdriver/lib/http.js:441:30)
    at process._tickCallback (internal/process/next_tick.js:68:7)
From: Task: remote.FileDetector.handleFile(/home/admin/BuildAgent/work/491c0dc9a984bb27/test/resources/images/imageUploader/partImage02.jpg)
    at WebDriver.schedule (node_modules/selenium-webdriver/lib/webdriver.js:807:17)
    at zip.addFile.then.then.then.encodedZip (node_modules/selenium-webdriver/remote/index.js:586:27)
From: Task: WebElement.sendKeys()
    at WebElement.sendKeys (node_modules/selenium-webdriver/lib/webdriver.js:2185:43)
    at [...]

我是否应该假设Android real设备和iOS都不支持使用这些工具(Browserstack、selenium webdriver)从本地计算机上载文件?

谢啦

共有1个答案

姚信鸥
2023-03-14

LocalFileDetector仅支持桌面浏览器,不支持移动设备。您可以在此处查看:https://github.com/appium/appium/issues/9120

 类似资料: