Forum Discussion

bs01's avatar
bs01
Occasional Contributor
4 years ago

Cucumber BDD + Serenity - Writing user defined methods

I am learning and using Cucumber BDD, with Serenity.

I am writing a global library which will have re-usable methods. These methods are accessible from all classes/java files.

 

I am struggling to understand how to access Webdriver object.

Or, if webdriver not needed, can I directly access "element" which comes with selenium??

But the below syntax is throwing error, as "element" is not correct.

1. Should I pass "driver" as parameter for every Global method

2. I access this method from Pages. Should I pass "driver" as parameter. If so, what is the correct way to pass "driver" object to the method below.

public class GlobalMethods

{

public void clickLinkWithText(String text){
System.out.println("Entered into clicklink with text >> " + text);
element(By.xpath("//a[text()='"+text+"']")).click();
}

}

No RepliesBe the first to reply