gpt4 book ai didi

java - Selenium 在第二个 .get(url) 上出现 HTMLUnitDriver ScriptException (未找到 tmp 文件)

转载 作者:行者123 更新时间:2023-11-30 08:03:55 26 4
gpt4 key购买 nike

我使用 testng 和 htmlUnitDriver 运行 Selenium 测试。我使用一个 webDriver 实例进行所有测试。我只是在每个测试类之后注销并清除 cookie driver.manage().deleteAllCookies() (删除 cookie 本身不负责我对此进行的测试)

所以基本上发生的是:

driver.get(url1);
... login to Single Page App ...
driver ... pseudo ... find logout-element and click logout
driver.manage().deleteAllCokies();
driver.get(url1);
... input credentials ...
loginForm.submit();

这会导致以下异常:

    com.gargoylesoftware.htmlunit.ScriptException: java.io.FileNotFoundException: C:\tmp\selenium\htmlunit5619416597224576810.tmp (Das System kann die angegebene Datei nicht finden)
at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine$HtmlUnitContextAction.run(JavaScriptEngine.java:705)
at net.sourceforge.htmlunit.corejs.javascript.Context.call(Context.java:620)
at net.sourceforge.htmlunit.corejs.javascript.ContextFactory.call(ContextFactory.java:513)
at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.callFunction(JavaScriptEngine.java:637)
at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.callFunction(JavaScriptEngine.java:612)
at com.gargoylesoftware.htmlunit.html.HtmlPage.executeJavaScriptFunctionIfPossible(HtmlPage.java:1001)
at com.gargoylesoftware.htmlunit.javascript.host.EventListenersContainer.executeEventListeners(EventListenersContainer.java:179)
at com.gargoylesoftware.htmlunit.javascript.host.EventListenersContainer.executeBubblingListeners(EventListenersContainer.java:239)
at com.gargoylesoftware.htmlunit.javascript.host.Node.fireEvent(Node.java:814)
at com.gargoylesoftware.htmlunit.javascript.host.Node.fireEvent(Node.java:748)
at com.gargoylesoftware.htmlunit.html.HtmlElement$1.run(HtmlElement.java:920)
at net.sourceforge.htmlunit.corejs.javascript.Context.call(Context.java:620)
at net.sourceforge.htmlunit.corejs.javascript.ContextFactory.call(ContextFactory.java:513)
at com.gargoylesoftware.htmlunit.html.HtmlElement.fireEvent(HtmlElement.java:925)
at com.gargoylesoftware.htmlunit.html.HtmlPage.executeEventHandlersIfNeeded(HtmlPage.java:1298)
at com.gargoylesoftware.htmlunit.html.HtmlPage.initialize(HtmlPage.java:256)
at com.gargoylesoftware.htmlunit.WebClient.loadWebResponseInto(WebClient.java:475)
at com.gargoylesoftware.htmlunit.WebClient.loadDownloadedResponses(WebClient.java:2074)
at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.doProcessPostponedActions(JavaScriptEngine.java:733)
at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.processPostponedActions(JavaScriptEngine.java:820)
at com.gargoylesoftware.htmlunit.html.HtmlElement.click(HtmlElement.java:1325)
at com.gargoylesoftware.htmlunit.html.HtmlElement.click(HtmlElement.java:1268)
at com.gargoylesoftware.htmlunit.html.HtmlElement.click(HtmlElement.java:1216)
at org.openqa.selenium.htmlunit.HtmlUnitWebElement.submit(HtmlUnitWebElement.java:177)
... <snip> ...
at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:111)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:204)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:175)
Caused by: java.lang.RuntimeException: java.io.FileNotFoundException: C:\tmp\selenium\htmlunit5619416597224576810.tmp (Das System kann die angegebene Datei nicht finden)
at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.doProcessPostponedActions(JavaScriptEngine.java:739)
at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.access$500(JavaScriptEngine.java:93)
at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine$HtmlUnitContextAction.run(JavaScriptEngine.java:700)
... 56 more
Caused by: java.io.FileNotFoundException: C:\tmp\selenium\htmlunit5619416597224576810.tmp (Das System kann die angegebene Datei nicht finden)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(FileInputStream.java:138)
at com.gargoylesoftware.htmlunit.DownloadedContent$OnFile.getInputStream(DownloadedContent.java:81)
at com.gargoylesoftware.htmlunit.WebResponseData.getStream(WebResponseData.java:91)
at com.gargoylesoftware.htmlunit.WebResponseData.getInputStream(WebResponseData.java:156)
at com.gargoylesoftware.htmlunit.WebResponse.getContentAsStream(WebResponse.java:241)
at com.gargoylesoftware.htmlunit.util.WebResponseWrapper.getContentAsStream(WebResponseWrapper.java:58)
at com.gargoylesoftware.htmlunit.DefaultPageCreator.createPage(DefaultPageCreator.java:150)
at com.gargoylesoftware.htmlunit.WebClient.loadWebResponseInto(WebClient.java:468)
at com.gargoylesoftware.htmlunit.WebClient.loadDownloadedResponses(WebClient.java:2074)
at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.doProcessPostponedActions(JavaScriptEngine.java:733)
... 58 more

该文件的删除发生在第二次 get 调用时。我很乐意就可能导致这种情况的原因提供建议。

这是我使用的 selenium maven 依赖项:

    <dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>2.45.0</version>
</dependency>

最佳答案

此错误是因为 WebResponse 被缓存,并且在获取新页面时清理旧页面并删除其本地文件(默认内容大于 500 KB)。

您可以使用以下内容直到问题得到解决。

    WebDriver driver = new HtmlUnitDriver() {
@Override
protected WebClient getWebClient() {
WebClient c = super.getWebClient();
c.getCache().setMaxSize(0);
return c;
}
};

关于java - Selenium 在第二个 .get(url) 上出现 HTMLUnitDriver ScriptException (未找到 tmp 文件),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31453513/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com