Я написал файл функций и отдельный файл определения шага для того же. Вот основная работа - я хочу проверить элементы страницы «Регистрация».
Но когда я выполняю файл функций, здесь можно увидеть ошибку «Исключение нулевого указателя».
Мой файл функций
Feature: Verify the Register page
@TC2
Scenario: Verify the Register link provided on Home Page
Given user is on HomePage
When user clicks on register link
Then user should be able to view <fields> such as
|fields|
|First Name|
|Last Name|
|Address|
|City|
|State|
|Zip code|
|Phone|
|SSN|
|Username|
|Password|
|Confirm|
Мой класс Runneris:
package runner;
import org.junit.runner.RunWith;
import cucumber.api.CucumberOptions;
import cucumber.api.junit.Cucumber;
@RunWith(Cucumber.class)
@CucumberOptions(
features="D:\\Para_Bank_Cucumber\\Cucumber_Framework\\src\\main\\java\\ParaBank\\Cucumber_Framework\\Para_bank_TC_01.feature"
, glue= {"StepFiles"}
, dryRun= false
,monochrome=true
, strict=true
,tags= {"@TC2"}
)
public class Test_runner {
}
Мой файл определения шага (Код) имеет вид:
package StepFiles;
import java.util.List;
import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import DataProvider.ConfigFileReader;
import cucumber.api.DataTable;
import cucumber.api.java.en.Then;
import cucumber.api.java.en.When;
public class ParaBank_TC_02_Step {
public WebDriver driver;
ConfigFileReader configFileReader;
@FindBy(xpath="//a[contains(text(),'Register')]")
private WebElement register_link;
@When ("^user clicks on register link$")
public void click_register() throws InterruptedException
{
WebDriverWait wait=new WebDriverWait(driver,30);
wait.until(ExpectedConditions.visibilityOf(register_link));
//wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath("//a[contains(text(),'Register')]")));
register_link.click();
}
@FindBy(xpath="//table[@class='form2']/tbody/tr/td[2]/input[@id='customer.firstName']")
private WebElement first_name;
@FindBy(xpath="//table[@class='form2']/tbody/tr/td[2]/input[@id='customer.lastName']")
private WebElement last_name;
@FindBy(xpath="//table[@class='form2']/tbody/tr/td[2]/input[@id='customer.address.street']")
private WebElement Address;
@FindBy(xpath="//table[@class='form2']/tbody/tr/td[2]/input[@id='customer.address.city']")
private WebElement city;
@FindBy(xpath="//table[@class='form2']/tbody/tr/td[2]/input[@id='customer.address.state']")
private WebElement state;
@FindBy(xpath="//table[@class='form2']/tbody/tr/td[2]/input[@id='customer.address.zipCode']")
private WebElement zip;
@FindBy(xpath="//table[@class='form2']/tbody/tr/td[2]/input[@id='customer.phoneNumber']")
private WebElement phone;
@FindBy(xpath="//table[@class='form2']/tbody/tr/td[2]/input[@id='customer.ssn']")
private WebElement SSN;
@FindBy(xpath="//table[@class='form2']/tbody/tr/td[2]/input[@id='customer.username']")
private WebElement Username;
@FindBy(xpath="//table[@class='form2']/tbody/tr/td[2]/input[@id='customer.password']")
private WebElement password;
@FindBy(xpath="//table[@class='form2']/tbody/tr/td[2]/input[@id='repeatedPassword']")
private WebElement repeat_pass;
@Then ("^user should be able to view <fields> such as$")
public void verify_fields(DataTable testData)
{
List<String> all_fields=testData.asList(String.class);
for(String fields_links:all_fields)
{
WebDriverWait wait =new WebDriverWait(driver,30);
wait.until(ExpectedConditions.visibilityOf(first_name));
JavascriptExecutor js=(JavascriptExecutor)driver;
js.executeScript("arguments[0].setAttribute('style', 'color: blue; border: 2px solid Magenta;');", first_name);
wait.until(ExpectedConditions.visibilityOf(last_name));
js.executeScript("arguments[0].setAttribute('style', 'color: blue; border: 2px solid Magenta;');", last_name);
wait.until(ExpectedConditions.visibilityOf(Address));
js.executeScript("arguments[0].setAttribute('style', 'color: blue; border: 2px solid Magenta;');", Address);
wait.until(ExpectedConditions.visibilityOf(city));
js.executeScript("arguments[0].setAttribute('style', 'color: blue; border: 2px solid Magenta;');", city);
wait.until(ExpectedConditions.visibilityOf(state));
js.executeScript("arguments[0].setAttribute('style', 'color: blue; border: 2px solid Magenta;');", state);
wait.until(ExpectedConditions.visibilityOf(zip));
js.executeScript("arguments[0].setAttribute('style', 'color: blue; border: 2px solid Magenta;');", zip);
wait.until(ExpectedConditions.visibilityOf(phone));
js.executeScript("arguments[0].setAttribute('style', 'color: blue; border: 2px solid Magenta;');", phone);
wait.until(ExpectedConditions.visibilityOf(SSN));
js.executeScript("arguments[0].setAttribute('style', 'color: blue; border: 2px solid Magenta;');", SSN);
wait.until(ExpectedConditions.visibilityOf(phone));
js.executeScript("arguments[0].setAttribute('style', 'color: blue; border: 2px solid Magenta;');", phone);
wait.until(ExpectedConditions.visibilityOf(Username));
js.executeScript("arguments[0].setAttribute('style', 'color: blue; border: 2px solid Magenta;');", Username);
wait.until(ExpectedConditions.visibilityOf(password));
js.executeScript("arguments[0].setAttribute('style', 'color: blue; border: 2px solid Magenta;');", password);
wait.until(ExpectedConditions.visibilityOf(repeat_pass));
js.executeScript("arguments[0].setAttribute('style', 'color: blue; border: 2px solid Magenta;');", repeat_pass);
}
}
}
Ожидаемый результат: -
1. it should click on Register link.
2. It should highlight the elements described in javascript executor.
Фактический результат: -
NullPointerException error could be seen on a page.
Пожалуйста, помогите мне найти основную причину этой ошибки. Не удалось найти основную причину этой ошибки. Я попытался поставить wait, т.е. ожидание веб-драйвера, но не смог устранить ошибку.
Я также опубликовал свой класс Test runner для большей ясности.
Пожалуйста, помогите мне с этой ошибкой. Требуется помощь в знании существования ошибки NullPointerException.
Если я увеличувремя ожидания веб-драйвера, чтобы он мог сначала отследить элемент, а затем выполнить требуемое действие.
или существует ошибка в javaScriptExecutor.