【发布时间】:2013-10-10 00:25:41
【问题描述】:
我正在使用 Robotium 在与 Web 门户交互的 Android 应用程序上运行一些测试。
我想将一些信息保存到文件中;例如,我需要保存从应用程序创建的用户名的 ID,并且我想从 Selenium 读取它以在 Web 门户上运行测试,以验证该用户的网页是否已创建。
有可能吗?
有人可以建议我一个解决方案或变通方法吗?
这是一个代码示例,但它不起作用(我想写入一个文件,例如 c:\myworkspace\filename.txt 上的一个字符串):
public void test_write_file(){
if(!solo.searchText("HOME")){
signIn("39777555333", VALID_PASSWORD);
}
try {
String content = "This is the content to write into file";
File file = new File("filename.txt");
// if file doesnt exists, then create it
if (!file.exists()) {
file.createNewFile();
}
FileWriter fw = new FileWriter(file.getAbsoluteFile());
BufferedWriter bw = new BufferedWriter(fw);
bw.write(content);
bw.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
assertTrue(solo.searchText("HOME"));
}
此代码应写入设备上的文件;我的目标是在我启动脚本的机器上写一个文件;被测应用程序应具有写入存储卡的权限;但我问如何从 Android 环境中出去并获得我的桌面环境。
【问题讨论】:
-
当然有可能!你都尝试了些什么?你至少对所涉及的代码有一点了解吗?不幸的是,我们只有足够的时间来帮助您,而不是设计一个完整的解决方案。提供一些代码,我们可以帮助您。
-
我添加了我使用的代码,但它不起作用。