Selenium:解决Failed to start new browser session
2010-01-05 22:16
459 查看
因为项目需要,最近开始学习Selenium,发现Selenium不如它主页说的那么好,只是在处理弹出窗口上就很让人头痛。
我利用selenium-core-1.0.1来熟悉各种Java方法,但是在实际编码中遇到问题,不知道如何解决.
代码package com.thoughtworks.selenium.corebased;
import org.openqa.selenium.server.SeleniumServer;
import com.thoughtworks.selenium.DefaultSelenium;
import com.thoughtworks.selenium.SeleneseTestCase;
import com.thoughtworks.selenium.Selenium;
public class TestClick extends SeleneseTestCase {
private static final String BASE_SERVER_PATH = "C:\\selenium-core-1.0.1\\tests";
private static final String TEST_FILE =
BASE_SERVER_PATH + "\\html\\test_click_page1.html";
private Selenium browser =
new DefaultSelenium("localhost", 4444, "iexplore", TEST_FILE);
private SeleniumServer seleniumServer;
public void setUp() throws Exception{
seleniumServer = new SeleniumServer();
seleniumServer.start();
browser.start();
}
public void tearDown() throws Exception{
browser.stop();
seleniumServer.stop();
}
public void testClick() throws Throwable {
browser.open(TEST_FILE);
verifyEquals("Click here for next page", browser.getText("link"));
}
}
错误代码:
java.lang.RuntimeException: Could not start Selenium session: Failed to start new browser session: Error while launching browser
今天在一个同事的帮助下解决了这个问题,原来在定义Selenium browser = new DefaultSelenium("localhost", 4444, "iexplore", TEST_URL);的时候,TEST_URL的不同会导致DefaultSelenium启动session的时候不一样的。
比如如果TEST_URL是一个http开头的网站像:http://www.bitmotif.com,上面贴的代码就没问题,可以pass。但是当你试图打开本地的html文件,比如C:\selenium-core-1.0.1\tests\html\test_select_window.html,你就必须在定义的时候,在前面加上file:///,完整的定义如下:
private static final String BASE_SERVER_PATH = "file:///C:\\selenium-core-1.0.1\\tests";
private static final String TEST_FILE =
BASE_SERVER_PATH + "\\html\\test_click_page1.html";
原理我还没搞清楚,至少这样改了脚本可以pass:)
我利用selenium-core-1.0.1来熟悉各种Java方法,但是在实际编码中遇到问题,不知道如何解决.
代码package com.thoughtworks.selenium.corebased;
import org.openqa.selenium.server.SeleniumServer;
import com.thoughtworks.selenium.DefaultSelenium;
import com.thoughtworks.selenium.SeleneseTestCase;
import com.thoughtworks.selenium.Selenium;
public class TestClick extends SeleneseTestCase {
private static final String BASE_SERVER_PATH = "C:\\selenium-core-1.0.1\\tests";
private static final String TEST_FILE =
BASE_SERVER_PATH + "\\html\\test_click_page1.html";
private Selenium browser =
new DefaultSelenium("localhost", 4444, "iexplore", TEST_FILE);
private SeleniumServer seleniumServer;
public void setUp() throws Exception{
seleniumServer = new SeleniumServer();
seleniumServer.start();
browser.start();
}
public void tearDown() throws Exception{
browser.stop();
seleniumServer.stop();
}
public void testClick() throws Throwable {
browser.open(TEST_FILE);
verifyEquals("Click here for next page", browser.getText("link"));
}
}
错误代码:
java.lang.RuntimeException: Could not start Selenium session: Failed to start new browser session: Error while launching browser
今天在一个同事的帮助下解决了这个问题,原来在定义Selenium browser = new DefaultSelenium("localhost", 4444, "iexplore", TEST_URL);的时候,TEST_URL的不同会导致DefaultSelenium启动session的时候不一样的。
比如如果TEST_URL是一个http开头的网站像:http://www.bitmotif.com,上面贴的代码就没问题,可以pass。但是当你试图打开本地的html文件,比如C:\selenium-core-1.0.1\tests\html\test_select_window.html,你就必须在定义的时候,在前面加上file:///,完整的定义如下:
private static final String BASE_SERVER_PATH = "file:///C:\\selenium-core-1.0.1\\tests";
private static final String TEST_FILE =
BASE_SERVER_PATH + "\\html\\test_click_page1.html";
原理我还没搞清楚,至少这样改了脚本可以pass:)
相关文章推荐
- 解决ubuntu登陆失败,"Failed to start session"的问题
- 使用selenium启动火狐浏览器,解决Unable to create new remote session问题
- session_start(): Failed to initialize storage module 解决办法
- session_start(): Failed to initialize storage module 解决办法
- Fatal error: session_start(): Failed to initialize storage module: files问题解决方法
- Fatal error: session_start(): Failed to initialize storage module: files问题解决方法
- 虚拟主机运行ASP错误解决:HTTP/1.1 New Application Failed when allowSessionState is set to false in web.config
- 配置php时。提示的错误session_start(): Failed to initialize storage module解决办法
- session_start(): Failed to initialize storage module 解决办法
- ubuntu 14.04 出现failed to start session解决方法
- org.openqa.selenium.remote.UnreachableBrowserException: Could not start a new session. Possible causes are invalid address of the remote server or br
- Server Tomcat v8.0 Server at localhost failed to start.的解决方法
- PHP failed to ptrace(PEEKDATA) pid 1918: Input/output error (5)或者 increase pm.start_servers解决
- ADB server didn’t ACK * failed to start daemon *几种解决方法
- The required Server component failed to start so Tomcat is unable to start问题解决
- 出现'MySQL Daemon failed to start‘解决方法
- ADB Server Didn’t ACK ,failed to Start Daemon 解决方法
- ubuntu:错误failed to load session ubuntu的解决办法
- Server Tomcat v7.0 Server at localhost failed to start.分析解决办法
- Oracle 11gR2 RAC ohasd failed to start 解决方法