Android Studio 环境Robotium网页相关测试异常java.lang.NullPointerException: lock == null

来源:互联网 发布:中建七局网络教育 编辑:程序博客网 时间:2024/06/05 05:38

 Assert.assertTrue("OpenWebUrlError", solo.waitForWebElement(By.textContent("找不到网页")));

java.lang.NullPointerException: lock == nullat java.io.Reader.<init>(Reader.java:64)at java.io.InputStreamReader.<init>(InputStreamReader.java:122)at java.io.InputStreamReader.<init>(InputStreamReader.java:59)at com.robotium.solo.WebUtils.getJavaScriptAsString(WebUtils.java:354)at com.robotium.solo.WebUtils.prepareForStartOfJavascriptExecution(WebUtils.java:162)at com.robotium.solo.WebUtils.executeJavaScriptFunction(WebUtils.java:276)at com.robotium.solo.WebUtils.executeJavaScript(WebUtils.java:238)at com.robotium.solo.WebUtils.getWebElements(WebUtils.java:111)at com.robotium.solo.Searcher.searchForWebElement(Searcher.java:238)at com.robotium.solo.Waiter.waitForWebElement(Waiter.java:498)at com.robotium.solo.Solo.waitForWebElement(Solo.java:672)
AndroidStudio直接调用Robotium源码时,测试网页相关所有case都抛出以上异常,
定位

BufferedReader input =  new BufferedReader(new InputStreamReader(fis));

该语句抛出null异常

InputStream fis = getClass().getResourceAsStream("RobotiumWeb.js");


执行发现这个js文件似乎读取失败,修改读取路径到androidTest下也抛出同样的异常,由于AS新的三部分架构可能改变了测试的框架导致,getResourceAsStream读取文件失败


暂时解决办法把这个js文件扔到sdcard里了


InputStream fis = new FileInputStream(new File("/sdcard/RobotiumWeb.js"));


测试执行通过。













0 0
原创粉丝点击