Я работаю в проекте на основе огурца, TestNG, Selenium, и у меня есть страница PageObject, как показано ниже
package com.testing.pageobject;
import java.util.List;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.PageFactory;
import com.testing.components.SearchResultComponent;
import com.testing.stepdefinitions.BaseClass;
public class ShoppingPage extends BaseClass {
public ShoppingPage(RemoteWebDriver driver) {
super();
this.driver=driver;
PageFactory.initElements(driver, this);
}
@FindBy(xpath="//div[@class='sh-dlr__list-result']")
private List<SearchResultComponent> SearchResult;
@FindBy(xpath="//span[@class='qa708e IYWnmd']")
private List<WebElement> ResultListView;
@FindBy(xpath="//span[@class='Ytbez']")
private List<WebElement> ResultGridView;
public List<SearchResultComponent> getSearchResult() {
return SearchResult;
}
public List<WebElement> getResultListView() {
return ResultListView;
}
public List<WebElement> getResultGridView() {
return ResultGridView;
}
}
, и страница моего компонента, как показано ниже
package com.testing.components;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.PageFactory;
import com.testing.stepdefinitions.BaseClass;
public class SearchResultComponent extends BaseClass {
public SearchResultComponent(RemoteWebDriver driver) {
super();
this.driver=driver;
PageFactory.initElements(driver, this);
}
@FindBy(xpath="//a[@class='AGVhpb']")
private WebElement productName;
@FindBy(xpath="//span[@class='O8U6h']")
private WebElement productPrice;
@FindBy(xpath="//div[@class='vq3ore']")
private WebElement productStars;
@FindBy(xpath="//img[@class='TL92Hc']")
private WebElement productImage;
@FindBy(xpath="//div[@class='hBUZL CPJBKe']")
private WebElement productDescription;
public WebElement getProductName() {
return productName;
}
public WebElement getProductPrice() {
return productPrice;
}
public WebElement getProductStars() {
return productStars;
}
public WebElement getProductImage() {
return productImage;
}
public WebElement getProductDescription() {
return productDescription;
}
}
Мой шаг огурцаопределение:
@When("search for product less than {int}")
public void search_for_product_less_than(Integer int1) {
ShoppingPage myshopping = new ShoppingPage(driver);
List<SearchResultComponent> SearchResults = myshopping.getSearchResult();
for(SearchResultComponent myResult:SearchResults) {
System.out.println(myResult.getProductName());
}
}
Постановка задачи:
При попытке получить getSearchResult () в определении шага я получаю ошибку с нулевой точкой. Не уверен, почему какие-то мысли, как это исправить?