zoukankan      html  css  js  c++  java
  • Data Driven Testing

    Advantages of using data driven framework:

    • Re-usable code
    • Better test coverage
    • Less Maintenance

    E.g:  using invalid login scenario as an example. 

    1.  define a negative login method on LgoinPage.java

    //Find the locator of the error message

    By loginErrorLocator = By.id("flash-messages");

    //Define a negativeLogin method

    public void negativeLogin(String username, String password) {
    System.out.println("Entering username and password:");
    find(usernameLocator).sendKeys(username);
    find(passwordLocator).sendKeys(password);
    System.out.println("Click Logon button");
    find(submitLocator).click();


    //invoke the waitLoginError method to wait for error appear
    waitLoginError();

    }

    //define a method to wait erro msg appear, invoke the waitForVisibilityOf method defefined in baseObject.java
    public void waitLoginError() {
    waitForVisibilityOf(loginErrorLocator, 5);
    }

    //define get error msg method. invoke find method defined in baseObject.java

    public String getLoginError() {
    return find(loginErrorLocator).getText();
    }

    2. Define the data provider method on baseTest.java (this base test includes setup. teardown..)

    @DataProvider(name = "negativeLoginData")
    public static Object[][] negativeLoginData(){
    return new Object[][] {
    {"IncorrectUserName", "Password!", "Your username is invalid!"},
    {"username","incorrectPassword", "Your password is invalid!"}
    };
    }

    3. Define test method to use the dataProvider

    @Test(dataProvider="negativeLoginData")
    public void netgativeLoginTest(String username, String password, String expectedErrorMessage ) {
    LoginPage lp = new LoginPage(driver);
    lp.open();
    lp.negativeLogin(username, password);

    String errorMessage = lp.getLoginError();
    //verification
    Assert.assertTrue(errorMessage.contains(expectedErrorMessage), "Actual and expected error messages are different. Expected:"+expectedErrorMessage+"Actual:"+errorMessage);
    }

    4. Update the testng.xml to include the negative test case

    e.g.

    <test name="NegativeLogin Test">
    <classes>
    <class name="com.test.FirstTest">
    <methods>
    <include name="netgativeLoginTest"></include>
    </methods>
    </class>
    </classes>
    </test>

  • 相关阅读:
    Cuckoo Hashing
    Microsoft Windows的消息循环
    Simplex, Full-Duplex and Half-Duplex Operation
    Linux 技巧:让进程在后台运行更可靠的几种方法
    https://learnku.com/docs/go-blog/qihoo/6532 。 heap size went up to 69G, with maximum garbage collection (GC)
    Go GC: Latency Problem Solved
    Sapphire: Copying GC Without Stopping the World
    The Go Blog Getting to Go: The Journey of Go's Garbage Collector
    xml CDATA
    Joseph cicyle's algorithm
  • 原文地址:https://www.cnblogs.com/amy2012/p/11624064.html
Copyright © 2011-2022 走看看