下面是我的方案的運行後得到的錯誤: -步驟:「我點擊馬上加入」不具有匹配的膠水代碼越來越當我將鼠標放置在臺階上
@scenario
Scenario: creating a account to user # /Users/ajaysithagari/Documents/workspace/Selenium_Cucumber/features/signup.feature:6
Given I am landing on nike homepage # CommonStepDefination.i_am_landing_on_nike_homepage()
And I click on join now # SignupStepDefination.i_click_on_join_now()
java.lang.NullPointerException
at pages.Signup.join(Signup.java:12)
at step_defination.SignupStepDefination.i_click_on_join_now(SignupStepDefination.java:13)
at ✽.And I click on join now(/Users/ajaysithagari/Documents/workspace/Selenium_Cucumber/features/signup.feature:8)
When I provide the user the user details to join # SignupStepDefination.i_provide_the_user_the_user_details_to_join()
Then I need to see the user details # SignupStepDefination.i_need_to_see_the_user_details()
1 Scenarios (1 failed)
4 Steps (1 failed, 2 skipped, 1 passed)
0m8.658s
這裏我的情況: - @feature 特點:爲了上申請 用戶需要創建帳戶
@scenario 方案:創建一個帳戶來考慮,我降落在耐克的主頁用戶 我點擊馬上加入 當我提供的用戶的用戶信息加入 然後,我需要看用戶詳細信息
Here is step defination for "given":-
package step_defination;
;
import cucumber.api.java.en.Given;
import utils.BrowserandDriver;
public class CommonStepDefination {
String PageURL = "xxxxx";
int ImplicitWait = 15;
int pageLoadTimeOut = 30;
String browserName = "safari";
BrowserandDriver BD = new BrowserandDriver();
@Before
public void launchBrowser()
{
BD.launchBrowser(browserName);
BD.maximizeBrowser();
BD.setImplicitWait(ImplicitWait);
BD.setPageLoadTimeout(pageLoadTimeOut);
}
@Given("^I am landing on nike homepage$")
public void i_am_landing_on_nike_homepage() throws Throwable {
BD.launchApp(PageURL);
}
@After
public void tearDown(Scenario scenario) {
BD.tearDown(scenario);
}
}
Here is my step defination:-
package step_defination;
import cucumber.api.java.en.And;
import cucumber.api.java.en.Then;
import cucumber.api.java.en.When;
import pages.Signup;
public class SignupStepDefination {
@And("^I click on join now$")
public void i_click_on_join_now() throws Throwable {
Signup sign = new Signup();
sign.join();
}
@When("^I provide the user the user details to join$")
public void i_provide_the_user_the_user_details_to_join() throws Throwable {
}
@Then("^I need to see the user details$")
public void i_need_to_see_the_user_details() throws Throwable {
}
Here is my page:-
package pages;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
public class Signup {
public static WebDriver driver;
public void join()
{
driver.findElement(By.xpath("/html/body/div[7]/nav/div[1]/ul[2]/li[2]/button")).click();
}
}
每一件事情是好的,但是當我鼠標懸停在功能的文件,我得到這個錯誤的步驟(假設工作但是,當時然後不工作)步驟'我現在單擊加入'沒有匹配的膠水代碼@feature功能:爲了註冊用戶需要創建帳戶
@scenario場景:創建一個帳戶用戶鑑於我登陸耐克首頁我現在點擊加入當我提供用戶的用戶詳細信息加入然後我需要看到用戶的詳細信息
選擇它你的'Signup'類聲明瞭一個靜態字段'WebDriver driver',但你永遠不會初始化它。這就是當你試圖調用'driver.findElement()'時會得到'NullPointerException'的原因' –
[什麼是NullPointerException,以及如何修復它?](https://stackoverflow.com/questions/ 218384/what-is-a-nullpointerexception-and-how-do-i-fix-it) –
我有問題嗎?我已經初始化了BrowserandDriver中的WebDriver驅動程序,但是如何使用此軟件包中的WebDriver驅動程序(BrowserandDriver)。我不想在每個包中初始化webdriver。謝謝 – Ajay