I have certain list of elements that i want to highlight it. I am using POM as a design pattern. Using cucumber with Java. I am using DataTable to fetch list of records. Please guide me in the code part that i have written.
*My Feature File* :-
@TC1
Scenario: Verify the Dashboard of the Website / Home page of the website
Given user is on HomePage
Then user should be able to view following <links> such as
|links|
|Solutions|
|About Us |
|Services |
|Products |
|Locations|
|Home|
|About Us|
|Contact Us|
|ATM Services|
|Online Services|
|Register|
|Forgot link info|
I want to highlight these elements shown under links header.
How to use List as a parameter & highlight the elements? I want to define my function in homePage.java & call it under Step Definition file.
In 'src/main/java' , i have made a java class file named as "HomePage.java" where in i have defined my elements using @FindBy keyword & added some methods performing some functions .
View of my HomePage.Java
public class HomePage {
public static WebDriver driver;
/*public HomePage(WebDriver driver)
{
PageFactory.initElements(driver, this);
}*/
@FindBy(xpath="html/body/div[1]/div[2]/ul/li/a")
private List<WebElement> links;
public void user_homePage()
{
System.setProperty("webdriver.chrome.driver","D:\\chromedriver.exe");
WebDriver driver=new ChromeDriver();
driver.get("https://parabank.parasoft.com/parabank/index.htm");
//driver.manage().window().maximize();
}
public void highlight_On_Element(DataTable dt) throws Throwable
{
List<String> data=dt.asList(String.class);
{
driver.findElement(By.name(data.get(0)));
JavascriptExecutor js=(JavascriptExecutor) driver;
js.executeScript("arguments[0].setAttribute('style', arguments[1]);",data, "color: blue; border: 2px solid Magenta;");
}
In 'src/test/java', I have made a step definitions file & Test Runner class.
So view of my step definition file is:
package StepDefinitions;
import java.util.List;
import org.junit.Assert;
import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.support.FindBy;
import cucumber.api.DataTable;
import cucumber.api.java.en.Given;
import cucumber.api.java.en.Then;
import PageObjects.HomePage;
public class Steps extends HomePage
{
private HomePage home;
@Given ("^user is on HomePage$")
public void home_page()
{
HomePage home=new HomePage();
home.user_homePage();
}
@Then ("^user should be able to view following <links> such as$")
public void verify_links(DataTable dt) throws Throwable
{
// List<String> data=dt.asList(String.class);
home.highlight_On_Element(dt); // Calling func "highlight_on _element define in Home page java file.
}
}
Error is displayed when i execute either feature file / Test runner java file , the error is
java.lang.NullPointerException
the error is highlighting on step
home.highlight_On_Element(dt);
defined in step definition file .
i am new to learning cucumber by myself.
Expected Result:
I want to highlight the elements "Links" written in feature file. I have written the xpath's of following links in a form of List.
How can one use List as a parameter in a function & calling it in a step definition file . Using List i can traverse each & every element defined under header "Links" & highlight it using JavaScriptExecutor.
>, List