简体   繁体   English

模拟器无法打开本地保存的HTML文件-拒绝访问错误

[英]Emulator can not open locally saved html file - Access denied error

I'm writing UI automation scripts for which need to load a static html page stored on my PC; 我正在编写UI自动化脚本,需要为其加载存储在PC上的静态html页面。 onto a emulator. 到模拟器上。

When I try to access this directly from chrome browser in emulator with URL 当我尝试使用网址在模拟器中直接从Chrome浏览器访问此文件时

file:////Users/me/Documents/workspace/sample-code/sample-code/apps/RottenTomatoesSnapshot.html 文件:////Users/me/Documents/workspace/sample-code/sample-code/apps/RottenTomatoesSnapshot.html

Access to the file was denied. 对该文件的访问被拒绝。

code I'm trying to execute 我正在尝试执行的代码

if (driver != null) driver.get("file:///" + new File(System.getProperty("user.dir").split("examples")[0]+"apps/RottenTomatoesSnapshot.html").toString()); 如果(驱动程序!=空)driver.get(“ file:///” +新文件(System.getProperty(“ user.dir”)。split(“ examples”)[0] +“ apps / RottenTomatoesSnapshot.html” ).toString());

Please clarify how to make this work 请说明如何进行这项工作

Thanks & Regards, Vikram 谢谢与问候,维克拉姆

Emulators don't access files on your hard drive, they access files in the emulator. 模拟器不访问您硬盘上的文件,而是访问模拟器中的文件。 The easiest way to fix it is to add that file as an asset to your APK, and read it from assets instead. 修复它的最简单方法是将该文件作为资产添加到您的APK,然后从资产中读取文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM