Selenium-线程中的例外" main" org.openqa.selenium.remote.UnreachableBrowserException"

时间:2015-02-03 11:52:46

标签: java selenium selenium-webdriver

我正在使用 Firefox webdriver 处理selenium,并在循环第二次运行时收到以下异常。 对于第一次循环,它正常,但在关闭浏览器(t.closeBrowser())并在第二次执行循环时,错误即将出现。

限制:管理员访问权限不存在,因此定义端口范围等的资源不适用。

            **Exception in thread "main" org.openqa.selenium.remote.UnreachableBrowserException: Error communicating with the remote browser. It may have died.**

            Build info: version: '2.44.0', revision: '76d78cf', time: '2014-10-23 20:03:00'
            System info: host: 'NODHCMSDTP1A314', ip: '10.237.212.160', os.name: 'Windows 7', os.arch: 'x86', os.version: '6.1', java.version: '1.7.0_40'
            Driver info: driver.version: RemoteWebDriver
                at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:593)
                at org.openqa.selenium.remote.RemoteWebDriver.get(RemoteWebDriver.java:304)
                at org.openqa.selenium.remote.RemoteWebDriver$RemoteNavigation.to(RemoteWebDriver.java:846)
                at WebScrapper.openTestSite(WebScrapper.java:18)
                at ReadExcel1.main(ReadExcel1.java:53)
            Caused by: org.apache.http.conn.HttpHostConnectException: Connect to 127.0.0.1:7055 [/127.0.0.1] failed: Connection refused: connect
                at org.apache.http.impl.conn.HttpClientConnectionOperator.connect(HttpClientConnectionOperator.java:140)
                at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.connect(PoolingHttpClientConnectionManager.java:318)
                at org.apache.http.impl.execchain.MainClientExec.establishRoute(MainClientExec.java:363)
                at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:219)
                at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:195)
                at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:86)
                at org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:108)
                at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:184)
                at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:72)
                at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:57)
                at org.openqa.selenium.remote.HttpCommandExecutor.fallBackExecute(HttpCommandExecutor.java:233)
                at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:184)
                at org.openqa.selenium.firefox.internal.NewProfileExtensionConnection.execute(NewProfileExtensionConnection.java:165)
                at org.openqa.selenium.firefox.FirefoxDriver$LazyCommandExecutor.execute(FirefoxDriver.java:362)
                at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:572)
                ... 4 more
            Caused by: java.net.ConnectException: Connection refused: connect
                at java.net.DualStackPlainSocketImpl.waitForConnect(Native Method)
                at java.net.DualStackPlainSocketImpl.socketConnect(Unknown Source)
                at java.net.AbstractPlainSocketImpl.doConnect(Unknown Source)
                at java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source)
                at java.net.AbstractPlainSocketImpl.connect(Unknown Source)
                at java.net.PlainSocketImpl.connect(Unknown Source)
                at java.net.SocksSocketImpl.connect(Unknown Source)
                at java.net.Socket.connect(Unknown Source)
                at org.apache.http.conn.socket.PlainConnectionSocketFactory.connectSocket(PlainConnectionSocketFactory.java:72)
                at org.apache.http.impl.conn.HttpClientConnectionOperator.connect(HttpClientConnectionOperator.java:123)... 18 more
      public class ReadExcel1
        {

         public static void main(String[] args) throws IOException, InvalidFormatException, InterruptedException
            {

                System.setProperty("webdriver.firefox.bin", "C:\\Users\\C5036344\\AppData\\Local\\Mozilla Firefox\\firefox.exe");
                 Workbook wb = WorkbookFactory.create(new FileInputStream("C:\\Users\\C5036344\\Desktop\\test_plan_selenium.xlsx"));
                    Sheet sheet = wb.getSheetAt(0);
                    WebScrapper t = new WebScrapper();
                   // call_author a=new call_author();
                    DataFormatter df = new DataFormatter();

                  //  ArrayList l = new ArrayList<String>();
                    String s = new String();
                    String a1 = new String();
                    String a2 = new String();
                    String a3 = new String();
                    String a4 = new String();
                    String a5 = new String();
                    String a6 = new String();
                    String a7 = new String();
                     int i,j;

                    for(i=1;i<sheet.getLastRowNum()+1;i++)
                    {
                        a1=null;
                        a2=null;
                        a3=null;
                        a4=null;
                        a5=null;
                        for(j=0;j<8;j++)
                        {

                            Row row = sheet.getRow(i);
                                    Cell c =row.getCell(j);
                                    if(j==0){ t.openTestSite(df.formatCellValue(c)); }
                                    else if(j==8){j++; }
                                    else if(j==1){a1=df.formatCellValue(c);}
                                    else if(j==2){a2=df.formatCellValue(c);}
                                    else if(j==3){a3=df.formatCellValue(c);}
                                    else if(j==4){a4=df.formatCellValue(c);}
                                    else if(j==5){a5=df.formatCellValue(c);}
                                    else if(j==6){a6=df.formatCellValue(c);}
                                    else if(j==7){a7=df.formatCellValue(c);}

                        }
                   t.login(a4,a5,a1,a2,a3);
//System.out.println(a4+" "+a5+" "+a1+" "+a2+" "+a3+""+a7+""+a6);

                        if(t.isTextPresent("Log Out"))
                        {
                            //System.out.println(a6);
                            t.logout(a6);
                            if(t.isTextPresent("Log Out"))
                            {
                                    t.logout(a7);
                                    sheet.getRow(i).getCell(8).setCellValue("Successfull");
                                    FileOutputStream fos=new FileOutputStream("C:\\Users\\C5036344\\Desktop\\test_plan_selenium.xlsx");
                                    wb.write(fos);
                                    fos.close();        
                            }

                           t.closeBrowser();
                        }
                        else
                            {
                             sheet.getRow(0).getCell(8).setCellValue("UnSuccessfull");
                             FileOutputStream fos=new FileOutputStream("C:\\Users\\C5036344\\Desktop\\test_plan_selenium.xlsx");
                             wb.write(fos);
                             fos.close();
                             t.closeBrowser();
                            }

                    }

            //      a.call_me();
              }

}   

0 个答案:

没有答案