Selenium-Java-Page Factory:从属性文件读取并在Selenium中传递值(SendKeys)

问题描述 投票:0回答:2

我在这种情况下陷入困境:

我尝试从属性文件(first.properties)中获取一些值,并传递给Selenium(sendKeys方法),为此,我准备下一个。

我已经创建了一个interface来保留属性文件的字符串。

public interface Constants {

    String key_search = "search";
}

我的财产文件:

search = "Selenium Cucumber"

这是读取程序中所有属性的类(我有多个属性文件)

public class MultiplePropertyReader {


    public static void ReadProps() {

        Properties properties = new Properties();


        try {
         //   properties.load(new FileInputStream("src/main/resources/data/zero.properties"));
            properties.load(new FileInputStream("src/main/resources/data/first.properties"));


            //First properties fields
            System.out.println("::: First Feature Property File 1 Data :::");
            System.out.println(properties.getProperty("search"));

            //Get the properties (First properties)
           String search = properties.getProperty(key_search);


        } catch (Exception e) {
            System.out.println("No properties file found...");
            e.printStackTrace();
        }
    }
}

在我的Page Factory类中,我有下一个代码,它将通过sendKeys将参数传递到特定字段。

public class Page_First extends BasePage {


    public Page_First() throws IOException {
        PageFactory.initElements(driver, this); }


    //////////////////////////////////////////////WEB ELEMENTS//////////////////////////////////////////////////////////

    @FindBy(name = "q")
    private WebElement searchText;

    @FindBy(name="btnK")
    private WebElement searchButton;


    //////////////////////////////////////////////BASE METHODS//////////////////////////////////////////////////////////

    public void startNavigation() {

      log.info("Accessing to Google");

    }

    public void search(String search) {

        searchText.sendKeys(search);
    }

    public void enterButton (){

        clickElement(searchButton);
    }
}

这是步骤定义类的传递参数的步骤

@When("I query for \"([^\"]*)\" cucumber spring selenium")
    public void I_query_for_cucumber_spring_selenium (String search)  {

        page_first.search(search);
    }

当我使用IntelliJ运行程序时,显示下一个问题:

java.lang.NullPointerException
    at org.openqa.selenium.support.pagefactory.DefaultElementLocator.findElement(DefaultElementLocator.java:69)
    at org.openqa.selenium.support.pagefactory.internal.LocatingElementHandler.invoke(LocatingElementHandler.java:38)
    at com.sun.proxy.$Proxy15.sendKeys(Unknown Source)
    at pages.Page_First.search(Page_First.java:39)
    at stepdefs.Step_First.I_query_for_cucumber_spring_selenium(Step_First.java:28)
    at ✽.When I query for "<search>" cucumber spring selenium(first.feature:10)

如果有人可以帮助我...最好的问候。

更新:我的功能文件。

Feature: Navigation Test

  As a user, I would like to make a search in Google
  So I want to navigate in the page

  Scenario: Search google to verify google search is working

    Given I go to Google
    When I query for "<search>" cucumber spring selenium
    And click search
    Then google page title should become the first page

我陷入这种情况:我试图从属性文件(first.properties)中获取一些值,然后传递给Selenium(sendKeys方法)。为此,我准备下一个。我为...

java selenium-webdriver cucumber properties-file page-factory
2个回答
0
投票

似乎您没有将任何值传递给


0
投票

请在此处粘贴您的黄瓜特征文件。@Deepak Kumar

© www.soinside.com 2019 - 2024. All rights reserved.