51Testing软件测试论坛

标题: 为什么总是抱错Caused by: java.net.SocketException: Connection reset [打印本页]

作者: albertzhou    时间: 2014-11-30 12:59
标题: 为什么总是抱错Caused by: java.net.SocketException: Connection reset
背景:我编写的一段小代码Java Selenium WebDriver,完成[打开页面]-〉[用户登入]-〉[用户登出]的简单工作。

问题:程序运行很不稳定。表现为同样的代码,运行若干次,仅有一两次等成功。其余几乎报同样的错误:
Exception in thread "main" org.openqa.selenium.remote.UnreachableBrowserException: Error communicating with the remote browser. It may have died.
Build info: version: '2.39.0', revision: 'ff23eac', time: '2013-12-16 16:12:12'
System info: host: 'Albert-HP', ip: '192.168.0.14', os.name: 'Windows 7', os.arch: 'x86', os.version: '6.1', java.version: '1.6.0_45'
Driver info: driver.version: RemoteWebDriver
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:548)
at org.openqa.selenium.remote.RemoteWebElement.execute(RemoteWebElement.java:268)
at org.openqa.selenium.remote.RemoteWebElement.sendKeys(RemoteWebElement.java:89)
at local.webdriver.WebDriverDemo.main(WebDriverDemo.java:24)
Caused by: java.net.SocketException: Connection reset
at java.net.SocketInputStream.read(Unknown Source)
at org.apache.http.impl.io.AbstractSessionInputBuffer.fillBuffer(AbstractSessionInputBuffer.java:160)
at org.apache.http.impl.io.SocketInputBuffer.fillBuffer(SocketInputBuffer.java:84)
at org.apache.http.impl.io.AbstractSessionInputBuffer.read(AbstractSessionInputBuffer.java:206)
at org.apache.http.impl.io.ContentLengthInputStream.read(ContentLengthInputStream.java:178)
at org.apache.http.conn.EofSensorInputStream.read(EofSensorInputStream.java:137)
at org.apache.http.conn.EofSensorInputStream.read(EofSensorInputStream.java:150)
at org.apache.http.util.EntityUtils.toByteArray(EntityUtils.java:136)
at org.openqa.selenium.remote.HttpCommandExecutor$EntityWithEncoding.<init>(HttpCommandExecutor.java:407)
at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:303)
at org.openqa.selenium.firefox.internal.NewProfileExtensionConnection.execute(NewProfileExtensionConnection.java:165)
at org.openqa.selenium.firefox.FirefoxDriver$LazyCommandExecutor.execute(FirefoxDriver.java:366)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:527)
... 3 more

分析:
一开始认为可能是WebDriver和Firefox的版本搭配有问题,就尝试将配置从WebDriver 2.44.0+Firefox 33.1.1+JDK 1.6.0_45,修改为WebDriver 2.39.0+Firefox 25.0.1+JDK 1.6.0_45。但遗憾的是,情况依旧。
从错误信息分析,理解是socket连接被复位,导致Firefox到WebDriver无法继续通信。但不知道这个问题改如何确定和解决,希望有相关经验的同仁指点迷津。

代码:
package local.webdriver;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.*;
import org.openqa.selenium.firefox.FirefoxDriver;
public class WebDriverDemo {
public static void main(String[] args) throws InterruptedException {
  
  WebDriver driver=new FirefoxDriver();
  
  driver.get("http://www.claimsecure.com/en-CA/products/OnlineServices.aspx");
  
  driver.manage().window().maximize();
  
  // type in Username
  Thread.sleep(5000);
  driver.findElement(By.name("pin")).sendKeys("username");  //在此暂时屏蔽真实用户名
  
  // type in password
  driver.findElement(By.name("pwd")).sendKeys("password"); //在此暂时屏蔽真实口令
  
  // click 'Login' button
  driver.findElement(By.id("ctl00_cphMainContent_ucOSLoginBox_SignInButton")).click();
  
  // click 'Log off' button
  driver.findElement(By.id("ctl00_hlnkLogOff")).click();
  
  driver.quit();
}
}


作者: loveok_56    时间: 2014-12-25 21:42
WebDriver driver=new FirefoxDriver();

实例化driver不对




欢迎光临 51Testing软件测试论坛 (http://bbs.51testing.com/) Powered by Discuz! X3.2