Cucumber の新機能で、Selenium と一緒に実行します。ユーザーが最初にホームページにアクセスし、[登録] リンクをクリックして、上記のフィールドが表示されることを確認する機能ファイルを作成しました。:-
同じためのステップ定義も書かれています。しかし、機能ファイルを実行すると.
エラー、つまり " org.openqa.selenium.JavascriptException: javascript error: Cannot read property 'setAttribute' of null" が表示されます。
誰でもこの問題を解決するのを手伝ってくれますか?
私の機能ファイルのシナリオは次のとおりです:-
@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 following <fields> such as
|fields|
|First Name|
|Last Name|
|Address|
|City|
|State|
|Zip code|
|Phone|
|SSN|
|Username|
|Password|
|Confirm|
ステップ定義ファイルは次のとおりです:=
@When ("^user clicks on register link$")
public void click_register()
{
WebElement Register_link=driver.findElement(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)
{
JavascriptExecutor js=(JavascriptExecutor)driver;
js.executeScript("arguments[0].setAttribute('style', arguments[1]);",first_name, "color: blue; border: 2px solid Magenta;");
js.executeScript("arguments[0].setAttribute('style', arguments[1]);",last_name, "color: blue; border: 2px solid Magenta;");
js.executeScript("arguments[0].setAttribute('style', arguments[1]);",Address, "color: blue; border: 2px solid Magenta;");
js.executeScript("arguments[0].setAttribute('style', arguments[1]);",city, "color: blue; border: 2px solid Magenta;");
js.executeScript("arguments[0].setAttribute('style', arguments[1]);",state, "color: blue; border: 2px solid Magenta;");
js.executeScript("arguments[0].setAttribute('style', arguments[1]);",zip, "color: blue; border: 2px solid Magenta;");
js.executeScript("arguments[0].setAttribute('style', arguments[1]);",phone, "color: blue; border: 2px solid Magenta;");
js.executeScript("arguments[0].setAttribute('style', arguments[1]);",SSN, "color: blue; border: 2px solid Magenta;");
js.executeScript("arguments[0].setAttribute('style', arguments[1]);",phone, "color: blue; border: 2px solid Magenta;");
js.executeScript("arguments[0].setAttribute('style', arguments[1]);",Username, "color: blue; border: 2px solid Magenta;");
js.executeScript("arguments[0].setAttribute('style', arguments[1]);",password, "color: blue; border: 2px solid Magenta;");
js.executeScript("arguments[0].setAttribute('style', arguments[1]);",repeat_pass, "color: blue; border: 2px solid Magenta;");
}
ここでは JavascriptExecutor を使用して、要素が存在することを確認するために要素を強調表示します。これはエラー メッセージです - " org.openqa.selenium.JavascriptException: javascript error: Cannot read property 'setAttribute' of null
"。プロパティを読み取ることができないと述べています。ここではプロパティが定義されていません。
このクエリを解決するために私を助けてください。この問題の根本原因を見つけることができません。