大家好:我正在使用 Maven/Selenium/Java 在 Cucumber 中遇到下一个问题
Given I go to Google # Step_First.I_go_to_Google()
java.lang.NullPointerException
at java.io.FileInputStream.<init>(FileInputStream.java:130)
at java.io.FileInputStream.<init>(FileInputStream.java:93)
at pages.Page_First.getURL(Page_First.java:38)
at stepdefs.Step_First.I_go_to_Google(Step_First.java:22)
at ✽.I go to Google (src/test/java/features/first.feature:8)
When I query for "<search>" cucumber spring selenium # Step_First.I_query_for_cucumber_spring_selenium(String)
And click search # Step_First.click_search()
Then google page title should become the first page # Step_First.google_page_title_should_become_the_first_page()
java.lang.NullPointerException
at java.io.FileInputStream.<init>(FileInputStream.java:130)
at java.io.FileInputStream.<init>(FileInputStream.java:93)
at pages.Page_First.getURL(Page_First.java:38)
at stepdefs.Step_First.I_go_to_Google(Step_First.java:22)
at ✽.I go to Google (src/test/java/features/first.feature:8)
这是我的功能文件:
Feature: Navigation Test
Scenario: Search google.com 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
这是我使用的Page方法:
public void getURL() throws IOException {
Properties Config = new Properties();
//Declares a variable for reading properties from a resource bundle file (*.properties)
Properties p = new Properties();
//Always the Absolute path here.
FileInputStream file = new FileInputStream(System.getProperty("/Users/xxxxxx/Documents/automation_projects/" +
"zero/src/main/resources/data/config.properties"));
Config.load(file);
driver.get(Config.getProperty("url"));
//The String inside the config.properties
String url = p.getProperty("url");
}
在我的步骤定义文件中,我有这个:
@Given("I go to Google")
public void I_go_to_Google () throws IOException {
page_first.getURL();
}
查看上面的信息,问题出现在这一行:
FileInputStream file = new FileInputStream(System.getProperty("/Users/xxxxxx/Documents/automation_projects/" +
"zero/src/main/resources/data/config.properties"));
顺便说一下,我的config.properties文件:
browser = firefox
url = https://www.google.com
有人可以帮我吗?提前致谢。