简体   繁体   English

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

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

I am new to selenium webdriver, java (junit) and eclipse IDE. 我是Selenium Webdriver,Java(Junit)和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. 我设法使用elenium和Junit在Eclipse IDE的测试套件中编写了一个测试用例。

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() . 尝试使用button.click()而不是button.submit() I've seen some issues using submit. 我已经看到了一些使用提交的问题。 Furthermore, if you are getting into selenium webdriver using eclipse, check out the Conductor framework. 此外,如果您要使用Eclipse进入Selenium Webdriver,请查看Conductor框架。 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");
    }
}

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

相关问题 使用 Selenium 自动化登录页面测试用例 - Automating login page test cases using Selenium 使用Java的Selenium Webdriver(Eclipse IDE) - Selenium Webdriver using Java(Eclipse IDE) Selenium + Java:具有登录功能的测试用例的并行执行 - Selenium + Java : Parallel execution for test cases having login functionality Test cases in new folder created parallel to src/test/java in latest Eclipse IDE maven java project is not executing the test cases - Test cases in new folder created parallel to src/test/java in latest Eclipse IDE maven java project is not executing the test cases 从CMD运行Selenium IDE测试用例 - Run Selenium IDE Test Cases from CMD Selenium测试用例中的循环 - java - Cycles in Selenium test cases - java Selenium Webdriver和Eclipse Java登录GMAIL的测试用例 - Test case for Selenium Webdriver and Eclipse java to login GMAIL 从Selenium IDE以excel格式记录测试用例 - Recording test cases in excel format from Selenium IDE Selenium Java-如何登录一次并使用同一浏览器实例运行多个测试用例,而是为每个测试打开/关闭浏览器 - Selenium Java-How do I login once and run multiple test cases using the same instance of browser, instead open/close the browser for every single test Java Selenium Pararel测试案例正在运行 - Java Selenium pararel test cases running
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM