-
Notifications
You must be signed in to change notification settings - Fork 48
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to extend selenium2library in Java #79
Comments
You can create your own jar with following test library. package sample;
import java.util.List;
import javax.script.ScriptException;
import org.openqa.selenium.WebElement;
import com.github.markusbernhardt.selenium2library.Selenium2Library;
import com.github.markusbernhardt.selenium2library.keywords.BrowserManagement;
import com.github.markusbernhardt.selenium2library.keywords.Element;
import com.github.markusbernhardt.selenium2library.locators.ElementFinder;
public class ExtendedSelenium2Library {
private Selenium2Library sel2;
private BrowserManagement browserManagement;
private Element element;
public ExtendedSelenium2Library() throws ScriptException {
sel2 = (Selenium2Library) Selenium2Library.getLibraryInstance();
browserManagement = sel2.getBrowserManagement();
element = sel2.getElement();
// ...
}
public void myInputKeyword(String data) {
// call Selenium2Library api
System.out.println(browserManagement.getTitle());
System.out.println(element.getValue("name=btnK"));
// call selenium api
List<WebElement> elements = ElementFinder.find(
browserManagement.getCurrentWebDriver(), "id=lst-ib");
elements.get(0).sendKeys(data);
}
}
|
I'm trying to do this on my project but I'm getting a null WebDriver object, and not sure why. I created this class:
First weird thing is that I get this warning:
Then, if I add a breakpoint right after the Not sure if it's relevant, but since I use Maven, I haven't manually installed anything and all my project setup is in pom.xml, where I've included selenium-java from org.seleniumhq.selenium and robotframework-selenium2library-java from com.github.markusbernhardt, as well as the robotframework-maven-plugin from org.robotframework. |
Have you imported the Selenium2Library before your test library in your test case? The import order is very important.
|
I would like to know if there is proper approach to extend this library to include new keyword (supported by selenium driver) without changing the original code?
Thanks for the library.
The text was updated successfully, but these errors were encountered: