java - 使用 Selenium 上传 APK 文件
问题描述
我在测试中遇到一个问题。我正在尝试上传 APK 文件,但是当涉及到该步骤时,什么也没有发生。
我已经尝试过带有文件路径的简单 sendKeys 并使用 AutoIT 脚本,但它们都不起作用。
这是输入:
<button uib-tooltip-html="uploadTooltip" ng-if="(privileges.update && !uploadForm.$visible) || createNew" ng-click="this.value = null;" ng-file-select="uploadFile($files, uploadForm)" class="btn btn-xs btn-default ng-scope ng-isolate-scope" ng-disabled="status.disabled || progressPercentage" type="button" style="overflow: hidden;">
<i class="fa fa-fw fa-upload"></i>
<input type="file" tabindex="-1" ng-file-generated-elem="true" style="width: 1px; height: 1px; opacity: 0; position: absolute; padding: 0px; margin: 0px; overflow: hidden;">
<input type="file" tabindex="-1" ng-file-generated-elem="true" style="width: 1px; height: 1px; opacity: 0; position: absolute; padding: 0px; margin: 0px; overflow: hidden;">
</button>
而我尝试过的(也使用带有完整路径的字符串作为sendKeys):
String filePath = System.getProperty("user.dir") + "src\\test\\APK\\com.airbnb.android.apk";
tryToClearAndSendKeysForSeconds(5, UPLOAD_FILE_BUTTON, filePath); // method for sendKeys with wait, locator and string
Runtime.getRuntime().exec("C:\\Users\\IdeaProjects\\Automated_Tests\\src\\test\\APK\\FileUpload.exe");
汽车信息技术:
ControlFocus(“Open”,””,”Edit1″)
ControlSetText(“Open”,””,”Edit1″,”D:\HDimage\profile.jpeg”)
ControlClick(“Open”,””,”Button1″)
我不确定是否应该在发送文件之前单击上传按钮,然后发送文件,但是当我这样做时(我使用的是 win 10 btw):
将不胜感激任何帮助!
解决方案
请按照步骤上传 APK 或任何文件:
a) 将您的文件上传到服务器上的 tmp 目录中以进行临时备份。喜欢
String path = FILE_UPLOAD_COMMON_PATH + File.separatorChar + file.getName();
try(FileOutputStream fileOutputStream = new FileOutputStream(path)){
fileOutputStream.write(bs); // byte[] bs
}catch(Exception e) {
throw e;
}
b) 现在从 tmp 目录获取并使用驱动程序上传文件,例如,
String path = FILE_UPLOAD_COMMON_PATH + File.separatorChar + file.getName();
driver.findElements(By.id("files")).get(0).sendKeys(path);
愿它能解决你的问题。
推荐阅读
- c++ - C++ 编译器会内联包含少量术语的 for 循环吗?
- javascript - 如何添加链接到下拉/自动完成提交?
- docker - 在公司范围内管理 docker 节点和集群的最佳实践
- angular - 为什么我在 ngModel 中只看到私有类属性
- java - 为什么复制文件时android应用程序冻结?
- java - 是否可以从此处的标题中删除“throw IllegalArgumentException”?
- android - 平滑滚动到位置,无需每次都下载所有项目
- python - 如何将字典中的列表中的参数作为浮点数提取到单独的列中?
- vhdl - VHDL程序,BCD到7seg转换器,这段代码能编译吗?
- php - 当不在本地网络时,SESSION 变量在移动设备上不起作用