com.sun.proxy。$ Proxy16执行时出错

时间:2019-08-04 13:32:35

标签: maven selenium cucumber pom.xml

我正在尝试用Java进行Cucumber的第一次练习。执行时出现错误NullPointer和com.sun.proxy。$ Proxy16。

尝试升级,降级各种依赖项。

    package com.cucu.runner;

    import org.junit.runner.RunWith;

    //import cucumber.api.CucumberOptions;
    import io.cucumber.junit.Cucumber;
    import io.cucumber.junit.CucumberOptions;

    @RunWith(Cucumber.class)
    @CucumberOptions
            (
            features= {".//src/main/java/com/cucu/feature/"},
            glue="com.cucu.stepdef",
            dryRun=false,
            monochrome=true,
            plugin= {"pretty","html:test-output"}
            )

    public class TestRunner_Cucumber {
    }

Feature: LoginPage

Scenario: Successful Login with Valid Credentials

Given User launch the URL
When Page title should be "Welcome, please sign in!"
When User enters valid Username "admin@yourstore.com" and valid Password "admin"
When User clicks on LogIn button
Then User lands on the homepage and verifies the text


package com.cucu.stepdef;

import org.junit.Assert;
import org.openqa.selenium.WebDriver;

import com.cucu.configprop.TestBase;
import com.cucu.pages.LoginPage;

import cucumber.api.java.Before;
import cucumber.api.java.en.Given;
import cucumber.api.java.en.Then;
import cucumber.api.java.en.When;

public class StepDefinitions extends TestBase{

    LoginPage loginPage = new LoginPage(driver);

    @Before
    public static void Start()
    {
        initialization();
    }

    @Given("User launch the URL")
    public void user_launch_the_URL() {
        launchURL();       
    }

    @When("Page title should be \"([^\"]*)\"")
    public void Page_title_should_be(String Title) {
       String ActTitle = loginPage.titleValidation();
       System.out.println(ActTitle);
       Assert.assertSame(Title, ActTitle);
    }

    @When("User enters valid Username {string} and valid Password {string}")
    public void user_enters_valid_Username_and_valid_Password(String username, String password) {
       loginPage.enterEmail(username);
       loginPage.enterPassword(password);
    }

    @When("User clicks on LogIn button")
    public void user_clicks_on_LogIn_button() {
        loginPage.clickLogIn();
    }

    @Then("User lands on the homepage and verifies the text")
    public void user_lands_on_the_homepage_and_verifies_the_text() {
        String DisplayText = loginPage.HeaderValidation();
        Assert.assertSame("Incorrect Text", "Dashboard", DisplayText);
    }

}


package com.cucu.configprop;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Properties;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.support.ui.WebDriverWait;

import com.cucu.pages.CreateOrdersPage;
import com.cucu.pages.CreateUsersPage;
import com.cucu.pages.HomePage;
import com.cucu.pages.LoginPage;

public class TestBase {

    public static WebDriver driver;
    public static LoginPage loginPage;
    public static HomePage homePage;
    public static CreateUsersPage createUsersPage;
    public static CreateOrdersPage createOrdersPage;
    public static WebDriverWait waitTime;
    public static Properties prop;

    public TestBase()
    {
        try {
            prop = new Properties();
            FileInputStream inp = new FileInputStream("F:\\Azar\\Cucumber_Practice\\"
                    + "src\\main\\java\\com\\cucu\\configprop\\config.properties");
            prop.load(inp);
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }   
    }

    public static void initialization(){
        String browserName = prop.getProperty("browser");

        if(browserName.equals("chrome")){
            System.setProperty("webdriver.chrome.driver","F:\\Installation\\chromedriver.exe"); 
            driver = new ChromeDriver();

            driver.manage().window().maximize();
            driver.manage().deleteAllCookies();
        }
    }

    public static void launchURL()
    {
        driver.get(prop.getProperty("url"));
    }

    public static void waitDriver()
    {
        waitTime = new WebDriverWait(driver, 2000); 
    }

}

页面标题应为“欢迎使用,请登录!” #StepDefinitions.Page_title_should_be(String)       java.lang.NullPointerException     在org.openqa.selenium.support.pagefactory.DefaultElementLocator.findElement(DefaultElementLocator.java:69)     在org.openqa.selenium.support.pagefactory.internal.LocatingElementHandler.invoke(LocatingElementHandler.java:38)     com.sun.proxy。$ Proxy16.getText(未知来源)     在com.cucu.pages.LoginPage.titleValidation(LoginPage.java:39)     在com.cucu.stepdef.StepDefinitions.Page_title_should_be(StepDefinitions.java:31)

0 个答案:

没有答案