Peijie
Peijie

Reputation: 3

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.

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." 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();
}

}

Upvotes: 0

Views: 781

Answers (1)

vincentcjl
vincentcjl

Reputation: 46

Have you made sure that the path for

webdriver.chrome.driver

is set up correctly?

Do you download the driver from Selenium Chrome Driver?

Upvotes: 2

Related Questions