使用 htmlelements 没有发生任何动作

No actions happened using htmlelements

目前我正在从事自动化测试解决方案的实施工作。我决定选择 htmlelements,但在此实施过程中,我使用干净的 webdriver+pagefactory 进行编码,以了解 htmlelements 的优势。我不太擅长编码,几乎一开始就陷入困境。 我创建了 java classes,正如在 http://htmlelements.qatools.ru/ 上的介绍中所实现的那样。

这是我的代码:

pom.xml

    <?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>w4w</groupId>
    <artifactId>w4w</artifactId>
    <version>1.0-SNAPSHOT</version>

    <dependencies>
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-java</artifactId>
            <version>2.48.2</version>
        </dependency>
        <dependency>
            <groupId>org.testng</groupId>
            <artifactId>testng</artifactId>
            <version>6.1.1</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>ru.yandex.qatools.htmlelements</groupId>
            <artifactId>htmlelements-java</artifactId>
            <version>1.15</version>
        </dependency>
        <dependency>
            <groupId>ru.yandex.qatools.ashot</groupId>
            <artifactId>ashot</artifactId>
            <version>1.4.12</version>
        </dependency>
    </dependencies>

</project>

LoginForm.java(元素)

    package htmlelements.Elements; /**
 * Created by Asus on 06.12.2015.
 */


import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import ru.yandex.qatools.htmlelements.annotations.Name;
import ru.yandex.qatools.htmlelements.element.Button;
import ru.yandex.qatools.htmlelements.element.HtmlElement;
import ru.yandex.qatools.htmlelements.element.TextInput;


@Name("Login Form")
public class LoginForm extends HtmlElement {

    @Name("Username textbox")
    @FindBy(id = "i_user")
    private TextInput UserNameTextbox;

    @Name("Password textbox")
    @FindBy(id = "i_password")
    private TextInput PasswordTextbox;

    @Name("Login button")
    @FindBy(xpath = "//*[@Value='Login']")
    private Button LoginButton;

    public void Login(String userName, String password){
         UserNameTextbox.sendKeys(userName);
         PasswordTextbox.sendKeys(password);
         LoginButton.click();
    }
}

登录页面(页面对象):

package htmlelements.PageObjects;

import htmlelements.Elements.LoginForm;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import ru.yandex.qatools.htmlelements.annotations.Name;
import org.openqa.selenium.WebDriver;
import ru.yandex.qatools.htmlelements.element.TextInput;
import ru.yandex.qatools.htmlelements.loader.HtmlElementLoader;


/**
 * Created by Asus on 06.12.2015.
 */

@Name("Login Page")
public class LoginPage {
    private LoginForm loginForm;

    public LoginPage(WebDriver driver){
        HtmlElementLoader.populatePageObject(this, driver);
    }

    @FindBy(id = "i_user")
    public TextInput usernm;

    public void Login(String userName, String password){
        loginForm.Login(userName, password);
    }
}

MSWhtml元素(测试):

/**
 * Created by Asus on 05.12.2015.
 */

import htmlelements.PageObjects.LoginPage;
import htmlelements.PageObjects.MainMenuPage;
import htmlelements.PageObjects.MerchantServiceWorkbenchScreen;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.AfterSuite;
import org.testng.annotations.BeforeSuite;
import org.testng.annotations.Test;
import java.util.concurrent.TimeUnit;

public class MSWhtmlelements {
    private WebDriver driver;

    @BeforeSuite
    public void initDriver() throws Exception {
        System.out.println("You are testing in firefox");
        driver = new FirefoxDriver();
        driver.manage().window().maximize();
    }

    @Test
    public void trainingTest(){
        driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);

        LoginPage loginPage = new LoginPage(driver);
        MainMenuPage mainMenuPage = new MainMenuPage(driver);
        MerchantServiceWorkbenchScreen mswScreen = new MerchantServiceWorkbenchScreen(driver);

        String baseLink = "http://w4w-auto:41600/";
        driver.get(baseLink);


        loginPage.usernm.sendKeys("123123");

        loginPage.Login("epichugin", "epichugin");

        mainMenuPage.GoTo();
    }

    @AfterSuite
    public void quitDriver() throws Exception {
        driver.quit();
    }
}

因此,如您所见,我尝试调用操作 2 次: loginPage.usernm.sendKeys("123123"); - 工作正常 loginPage.Login("epichugin", "epichugin"); - 根本不起作用。甚至没有出现异常。

在 webdriver+pageobjects 的情况下,它工作得非常好和稳定。 这是我的页面对象 class 可以正常工作。对此的测试几乎相同:

/**
 * Created by Asus on 04.12.2015.
 */

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.PageFactory;


public class PageElements {
    @FindBy(id = "i_user")
    private WebElement UsernameTextbox;

    @FindBy(id = "i_password")
    private WebElement PasswordTextbox;

    @FindBy(xpath = "//*[@Value='Login']")
    private WebElement LoginButton;

    public PageElements (WebDriver driver){
        PageFactory.initElements(driver, this);
    }

    public void login (String username, String password){
        UsernameTextbox.sendKeys(username);
        PasswordTextbox.sendKeys(password);
        LoginButton.click();
    }
}

提前致谢!

您的 LoginForm class 没有 @FindBy 注释,您希望 selenium 如何找到您的登录表单?