0

I am new to selenium webdriver, java (junit) and eclipse IDE.

Please help me to provide all the test cases for the login page.

I have managed to write one test case in the test suite in eclipse IDE using selenium and Junit.

for your reference the two classes are:

import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;  
import junit.textui.TestRunner;

public class TestSuite1 extends TestCase {    
    public static Test suite() {  
        TestSuite suite = new TestSuite();  

        suite.addTestSuite(TestCase1.class);
        //suite.addTestSuite((Case1) Testcase1.newInstance());  
        //suite.addTestSuite(TestCase1.newInstance());             
        return suite;  
    }  

    public static void main(String arg[]) {
        TestRunner.run(suite());
    }
}

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.WebElement;

import com.thoughtworks.selenium.SeleneseTestCase;

public class TestCase1 extends SeleneseTestCase {
    public void setUp() throws Exception {  
        login();
    }

    public void login() {
        WebDriver driver = new FirefoxDriver();
        driver.get("http://");
        WebElement id = driver.findElement(By.name("username"));
        WebElement pass = driver.findElement(By.name("password"));
        WebElement button = driver.findElement(By.xpath("/html/body/div/div/div[2]/div/form/p[3]/input"));         

        id.sendKeys("[email protected]");
        pass.sendKeys("abc123");
        button.submit();
    }
}
1
  • 2
    I think this question is very unclear.
    – The Onin
    Jan 31, 2017 at 18:50

1 Answer 1

5

Try using button.click() instead of button.submit(). I've seen some issues using submit. Furthermore, if you are getting into selenium webdriver using eclipse, check out the Conductor framework. It simplifies things greatly. Your test would look like:

@Config(url="http://mypage/login", browser=Browser.FIREFOX)
public class TestCase1 extends Locomotive {
    @Test
    public void login() {
        setText(By.name("username"), "[email protected]")
        .setText(By.name("password"), "abc123")
        .click(By.xpath("/html/body/div/div/div[2]/div/form/p[3]/input"))

        .validateTextPresent("You are now logged in");
    }
}

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.