Драйвер selenium webdriver имеет значение nullJAVA

Программисты JAVA общаются здесь
Ответить
Anonymous
 Драйвер selenium webdriver имеет значение null

Сообщение Anonymous »

У меня есть тестирование пользовательского интерфейса огурца.
Scenario is:
Scenario : user booking one service successfully
Given I login as a new user of visfuture
When select location and confirm
And select service "Biometric Screening (20 mins)" and confirm
And select date "2024-04-30" and time "09:00 AM" then confirm
And confirm the oppointment
Then the oppointment should confirmed

Определение шага
public class userBookOneService {
public static WebDriver driver;
private userLoginPage userLogin; // Declare the loginPage object
private userLocationPage userLocation;
private userServicePage userService;
private userConfirmPage userConfirm;
private userReviewPage userReview;
private userSchedulingPage userSchedule;

@Before
public void setup() throws Exception{
// You can use either Firefox or Chrome as needed
System.setProperty("webdriver.chrome.driver", "C:\\chromedriver.exe");
driver = new FirefoxDriver();
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
driver.manage().window().maximize();
driver.get("https://baseUrl");
}

@Given("^I login as a new user of visfuture$")
public void navigate_to_admin_web_page() {
// Initialize the loginPage object
userLogin = new userLoginPage(driver);
driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(2));
userLogin.inputUserFirstName("auto");
userLogin.inputUserLastName("tester");

long currentTimeMillis = System.currentTimeMillis();
String currentTimeString = Long.toString(currentTimeMillis);
userLogin.inputUserEmail("test"+currentTimeString+"@gmail.com");
userLogin.clickBookingButton();

}

@When("^select location and confirm$")
public void select_location_and_confirm() {

userLocation = new userLocationPage(driver);
driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(2));

userLocation.locationSelect("Visfuture Toronto");
userLocation.clickLocationNext();

}

@When("^select service \"([^\"]*)\" and confirm$")
public void select_service_one_and_confirm(String preferService) {

userService = new userServicePage(driver);
driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(2));

userService.selectService(preferService);
userService.clickServiceNext();
driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(2));
}

@When("^select date \"([^\"]*)\" and time \"([^\"]*)\" then confirm$")
public void select_date_and_time_then_confirm(String preferDate, String preferTime) {

userSchedule = new userSchedulingPage(driver);
driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(2));

userSchedule.selectDate(preferDate);
userSchedule.selectPeriodwithTime(preferTime);

}

@When("^confirm the oppointment$")
public void confirm_the_oppointment() {
userConfirm = new userConfirmPage(driver);
driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(2));
userConfirm.confirmAppointment();
}

@Then("^the oppointment should confirmed&")
public void the_oppointment_should_confirmed_and_showing_booked_service_like_following(DataTable bookedServices) {
userReview = new userReviewPage(driver);
driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(2));
userReview.verifyReviewTitle();
userReview.verifyServices(bookedServices);
}
}

Показывает сообщение об ошибке:
actions.userBookOneService.select_date_and_time_then_confirm(java.lang.String,java.lang.String)
[31mjava.lang.NullPointerException: невозможно вызвать «org.openqa.selenium.WebDriver.findElements(org.openqa.selenium.By)», потому что «this.driver» имеет значение null
в pageFactory.userSchedulingPage.(userSchedulingPage.java:49)
в действиях .userBookOneService.select_date_and_time_then_confirm(userBookOneService.java:90)
at ✽.выберите дату «2024-04-30» и время «09:00», затем подтвердите (file:///C:/Users/JimZhao/ VF/FE-BDD/src/test/resources/features/UserBookOneService.feature:7)
Проблема отладки находится на этапе " userSchedule = new userSchedulingPage(driver);"
при передаче " userSchedule = new userSchedulingPage(driver);" this.driver по-прежнему имеет значение null
public class userSchedulingPage {

private WebDriver driver; // Declare a class-level WebDriver variable

// Constructor to initialize the WebDriver instance
public userSchedulingPage(WebDriver driver) {
this.driver = driver;
}

//status "t-available": gray waiting select, "t-active": orange on selecting; "t-done": green selected
//return true if status of scheduling selection step match expected
public boolean varifyLoactionTab(String locationStatus) {
WebElement locationStep = driver.findElement(By.xpath("//div[@class='booking-steps']/div[3]"));
String locationClassName = locationStep.getAttribute("class");

if(locationClassName == locationStatus) {
return true;
}else {
return false;
}

}

При запуске «public userServicePage (драйвер WebDriver)» процесс не переходит в « this.driver = driver;»
На других страницах то же самое структура, нет этой проблемы. нравится:
public class userServicePage {

private WebDriver driver; // Declare a class-level WebDriver variable

// Constructor to initialize the WebDriver instance
public userServicePage(WebDriver driver) {
this.driver = driver;
}

//status "t-available": gray waiting select, "t-active": orange on selecting; "t-done": green selected
//return true if status of location selection step
public boolean varifyLoactionTab(String locationStatus) {
WebElement locationStep = driver.findElement(By.xpath("//div[@class='booking-steps']/div[1]"));
String locationClassName = locationStep.getAttribute("class");

if(locationClassName == locationStatus) {
return true;
}else {
return false;
}

}


Подробнее здесь: https://stackoverflow.com/questions/783 ... er-is-null
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «JAVA»