Faker并未在我的Selenium Webdriver中创建虚假数据

时间:2018-08-28 18:03:45

标签: java maven selenium selenium-webdriver faker

我有一个小问题,因为当我使用Selenium和Java验证网页时,我的Faker不会在字段中创建虚假数据。在上面粘贴了我的代码行:

FakerData.java

package resources;

import com.github.javafaker.Faker;

public class FakerData {

    private Faker faker;

    public void DataFaker() {
         faker = new Faker();
    }

    public String getFakeEmail() {
        return faker.internet().emailAddress();
    }

}

RegisterPage.java

package pageObjects;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;

public class RegisterPage {

public WebDriver driver;

    By signin = By.xpath("//a[@title='Log in to your customer account']");
    By emailcreate = By.xpath("//input[@id='email_create']");

public RegisterPage(WebDriver driver) {

        this.driver = driver;
    }

    public WebElement getLogin() {

        return driver.findElement(signin);
    }

    public WebElement getEmailCreate() {

        return driver.findElement(emailcreate);
    }

}

RegisterUser.java

package testuj;

import java.io.IOException;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;

import java.util.Locale;
import com.github.javafaker.Faker;

import pageObjects.RegisterPage;
import resources.base;
import resources.FakerData;

public class RegisterUser extends base{

    public RegisterUser() {
        super();
    }

    private FakerData faker = new FakerData();

    public static  Logger logger  = LogManager.getLogger(RegisterUser.getName());


    @BeforeTest

    public void initialize() throws IOException {

        driver = intializeDriver();
    }

    private static Class<?> getName() {
        // TODO Auto-generated method stub
        return null;
    }


    @Test
    public void basePageNavigation() throws IOException {

        driver.get(prop.getProperty("url"));
        RegisterPage reg = new RegisterPage(driver);
        reg.getLogin().click();
        reg.getEmailCreate().sendKeys(faker.getFakeEmail());


    }


}

没有Faker,我所有的框架都运作良好。我需要创建假日期。请帮忙。问候。

0 个答案:

没有答案