test cases for login page using selenium ; java and Eclipse IDE

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("tuser991@yahoo.co.in");
        pass.sendKeys("abc123");
        button.submit();
    }
}

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"), "tuser991@yahoo.co.in")
        .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");
    }
}
链接地址: http://www.djcxy.com/p/52330.html

上一篇: 硒和并行化的JUnit

下一篇: 使用硒登录页面的测试用例; java和Eclipse IDE