public final class WebDriverFX extends Object implements WebDriver, Executor
private staticWebDriverFX
driver; private static TestModel testModel; @org.junit.BeforeClass
public static void test() throwsInterruptedException
,Exception
{ finalURL
url = FindsByTest.class.getResource("testWithModel.html"); driver = newWebDriverFX
(url); driver.executeAndWait(newRunnable
() { @Override
public void run() { testModel = new TestModel("Hello", "World"); testModel.applyBindings(); } }); } @org.junit.Test
public void withModel() { // please note that this method is not executed in BrwsrCtx // to allow seeing updates in the Browser while debugging a testWebElement
element = driver.findElement(By
.id("target"));org.junit.Assert
.assertEquals("Hello", element.getText());WebElement
button = driver.findElement(By
.id("button")); button.click();org.junit.Assert
.assertEquals("World", element.getText());WebElement
input = driver.findElement(By
.id("input")); input.clear(); input.sendKeys("DukeScript"); button.click();org.junit.Assert
.assertEquals("DukeScript", element.getText());WebElement
findElement = driver.findElement(By
.cssSelector(".bla"));org.junit.Assert
.assertNotNull(findElement);org.junit.Assert
.assertEquals("DukeScript", findElement.getText()); }
WebDriver.ImeHandler, WebDriver.Navigation, WebDriver.Options, WebDriver.TargetLocator, WebDriver.Timeouts, WebDriver.Window
Constructor and Description |
---|
WebDriverFX(URL url)
Opens URL in a 800 * 600 Stage.
|
WebDriverFX(URL url,
double width,
double height)
Constructor that allows you to set a size for the browser window.
|
WebDriverFX(javafx.scene.web.WebView view)
Use this constructor only if you need to initialize your webview.
|
Modifier and Type | Method and Description |
---|---|
void |
close() |
void |
execute(Runnable command) |
void |
executeAndWait(Runnable command)
Executes a Runnable in BrwsrCtx and waits for it to finish.
|
WebElement |
findElement(By by) |
List<WebElement> |
findElements(By by) |
void |
get(String string) |
String |
getCurrentUrl() |
String |
getPageSource() |
String |
getTitle() |
String |
getWindowHandle() |
Set<String> |
getWindowHandles() |
WebDriver.Options |
manage() |
WebDriver.Navigation |
navigate() |
void |
quit() |
WebDriver.TargetLocator |
switchTo() |
public WebDriverFX(javafx.scene.web.WebView view) throws Exception
WebDriverFX(URL, double, double)
view
- an existing webviewException
- Might throw InterruptedException or AWTException (uses
Robot)public WebDriverFX(URL url, double width, double height) throws Exception
url
- The URL of the page to be loadedwidth
- width of the Stage
height
- height of the Stage
Exception
- Might throw InterruptedException or AWTException (uses
Robot)public String getCurrentUrl()
getCurrentUrl
in interface WebDriver
public List<WebElement> findElements(By by)
findElements
in interface SearchContext
findElements
in interface WebDriver
public WebElement findElement(By by)
findElement
in interface SearchContext
findElement
in interface WebDriver
public String getPageSource()
getPageSource
in interface WebDriver
public Set<String> getWindowHandles()
getWindowHandles
in interface WebDriver
public String getWindowHandle()
getWindowHandle
in interface WebDriver
public WebDriver.TargetLocator switchTo()
public WebDriver.Navigation navigate()
public WebDriver.Options manage()
public void executeAndWait(Runnable command) throws InterruptedException
command
- The command to executeInterruptedException
- (uses CountDownLatch)Copyright © 2017. All rights reserved.