[英]Selenium 2 in Java JUnit Test Error: Could not start a new session
I'm designing a website login test program in Java by using Selenium2. 我正在使用Selenium2设计一个Java的网站登录测试程序。
When I run it in JUnit in NetBeans, error shows up: "testLogin(JUnitTest.LoginTest): Could not start a new session. Possible causes are invalid address of the remote server or browser start-up failure." 当我在NetBeans中的JUnit中运行时,出现错误:“testLogin(JUnitTest.LoginTest):无法启动新会话。可能的原因是远程服务器的无效地址或浏览器启动失败。” Any idea about this? 对此有何想法? Thank you! 谢谢! Note: I have not thought of ways of testing login result, so the assertions are not going to work for now. 注意:我没有想过测试登录结果的方法,因此断言暂时不起作用。
My code: 我的代码:
public class LoginTest {
private static WebDriver driver;
private static String baseUrl;
private static String loginUrl;
@Before
public void setUp() {
baseUrl = "https://web.kitchology.com/kitchology/";
loginUrl = "https://web.kitchology.com/kitchology/faces/Home.xhtml";
System.setProperty("webdriver.chrome.driver", "E:\\Google\\Chrome\\Application\\Chrome.exe");
driver = new ChromeDriver();
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
driver.get(baseUrl);
driver.findElement(By.id("j_idt16:sitepassword")).sendKeys("sitepass");
driver.findElement(By.id("j_idt16:j_idt19")).click();
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
}
@Test
public void testLogin() throws Exception {
driver.get(loginUrl);
driver.findElement(By.id("j_idt16:loginLink")).click();
driver.findElement(By.id("login")).clear();//clear any previous text
driver.findElement(By.id("j_idt16:loginForm:username")).sendKeys("myuser");
driver.findElement(By.id("j_idt16:loginForm:password")).sendKeys("mypass");
driver.findElement(By.id("j_idt16:loginForm:j_idt28")).submit();
assert("Welcome to Kitchology!" == driver.getTitle());
assert("" == WelcomePage.getWelcomeMessage());
}
@Test
public void testFailedLogin() throws Exception {
driver.get(loginUrl);
driver.findElement(By.id("j_idt16:loginLink")).click();
driver.findElement(By.id("login")).clear();//clear any previous text
driver.findElement(By.id("j_idt16:loginForm:username")).sendKeys("myuser");
driver.findElement(By.id("j_idt16:loginForm:password")).sendKeys("mypass");
driver.findElement(By.id("j_idt16:loginForm:j_idt28")).submit();
assert("" == FailedPage.getErrorMessage());
}
@After
public void after() {
driver.quit();
}
} }
Have you made sure that the path for 你有没有确定的路径
webdriver.chrome.driver webdriver.chrome.driver
is set up correctly? 设置正确吗?
Do you download the driver from Selenium Chrome Driver ? 你从Selenium Chrome Driver下载驱动程序吗?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.