繁体   English   中英

用硒登录页面的测试用例; Java和Eclipse IDE

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

我是Selenium Webdriver,Java(Junit)和Eclipse IDE的新手。

请帮助我为登录页面提供所有测试用例。

我设法使用elenium和Junit在Eclipse IDE的测试套件中编写了一个测试用例。

供您参考的两个类是:

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

尝试使用button.click()而不是button.submit() 我已经看到了一些使用提交的问题。 此外,如果您要使用Eclipse进入Selenium Webdriver,请查看Conductor框架。 它大大简化了事情。 您的测试如下所示:

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM