Java 类org.openqa.selenium.WebDriver.TargetLocator 实例源码
项目:ats-framework
文件:HiddenHtmlPrompt.java
public HiddenHtmlPrompt( UiDriver uiDriver ) {
super(uiDriver);
HiddenBrowserDriver browserDriver = (HiddenBrowserDriver) uiDriver;
HtmlUnitDriver driver = (HtmlUnitDriver) browserDriver.getInternalObject(InternalObjectsEnum.WebDriver.name());
Field webClientField = null;
boolean fieldAccessibleState = false;
try {
TargetLocator targetLocator = driver.switchTo();
webClientField = targetLocator.getClass().getDeclaringClass().getDeclaredField("webClient");
fieldAccessibleState = webClientField.isAccessible();
webClientField.setAccessible(true);
webClient = (WebClient) webClientField.get(targetLocator.defaultContent());
} catch (Exception e) {
throw new SeleniumOperationException("Error retrieving internal Selenium web client", e);
} finally {
if (webClientField != null) {
webClientField.setAccessible(fieldAccessibleState);
}
}
}
项目:marathonv5
文件:JavaDriverTest.java
public void windowTitleWithPercentage() throws Throwable {
driver = new JavaDriver();
SwingUtilities.invokeAndWait(new Runnable() {
@Override public void run() {
frame.setTitle("My %Dialog%");
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
});
WebElement element1 = driver.findElement(By.name("click-me"));
String id1 = ((RemoteWebElement) element1).getId();
// driver.switchTo().window("My %25Dialog%25");
TargetLocator switchTo = driver.switchTo();
switchTo.window("My %Dialog%");
WebElement element2 = driver.findElement(By.name("click-me"));
String id2 = ((RemoteWebElement) element2).getId();
AssertJUnit.assertEquals(id1, id2);
}
项目:ats-framework
文件:HiddenHtmlAlert.java
public HiddenHtmlAlert( UiDriver uiDriver ) {
super(uiDriver);
HiddenBrowserDriver browserDriver = (HiddenBrowserDriver) uiDriver;
HtmlUnitDriver driver = (HtmlUnitDriver) browserDriver.getInternalObject(InternalObjectsEnum.WebDriver.name());
Field webClientField = null;
boolean fieldAccessibleState = false;
try {
TargetLocator targetLocator = driver.switchTo();
webClientField = targetLocator.getClass().getDeclaringClass().getDeclaredField("webClient");
fieldAccessibleState = webClientField.isAccessible();
webClientField.setAccessible(true);
webClient = (WebClient) webClientField.get(targetLocator.defaultContent());
} catch (Exception e) {
throw new SeleniumOperationException("Error retrieving internal Selenium web client", e);
} finally {
if (webClientField != null) {
webClientField.setAccessible(fieldAccessibleState);
}
}
}
项目:ats-framework
文件:HiddenHtmlConfirm.java
public HiddenHtmlConfirm( UiDriver uiDriver ) {
super(uiDriver);
HiddenBrowserDriver browserDriver = (HiddenBrowserDriver) uiDriver;
HtmlUnitDriver driver = (HtmlUnitDriver) browserDriver.getInternalObject(InternalObjectsEnum.WebDriver.name());
Field webClientField = null;
boolean fieldAccessibleState = false;
try {
TargetLocator targetLocator = driver.switchTo();
webClientField = targetLocator.getClass().getDeclaringClass().getDeclaredField("webClient");
fieldAccessibleState = webClientField.isAccessible();
webClientField.setAccessible(true);
webClient = (WebClient) webClientField.get(targetLocator.defaultContent());
} catch (Exception e) {
throw new SeleniumOperationException("Error retrieving internal Selenium web client", e);
} finally {
if (webClientField != null) {
webClientField.setAccessible(fieldAccessibleState);
}
}
}
项目:paxml
文件:FrameTag.java
/**
* {@inheritDoc}
*/
@Override
protected Object onCommand(Context context) {
TargetLocator tl = getSession().switchTo();
if (index >= 0) {
tl.frame(index);
}
if (StringUtils.isNotBlank(name)) {
tl.frame(name);
}
if (top != null && top) {
tl.defaultContent();
}
return null;
}
项目:webtester-core
文件:WebDriverBrowserTest.java
@Test(expected = NoSuchFrameException.class)
public void testExceptionHandlingInCaseAFrameIsNotFoundForTheGivenIndex() {
TargetLocator locator = mockTargetLocator();
NoSuchFrameException exception = createSeleniumExceptionOfClass(NoSuchFrameException.class);
doThrow(exception).when(locator).frame(INDEX);
try {
cut.setFocusOnFrame(INDEX);
} finally {
verifyLastEventFiredWasExceptionEventOf(exception);
}
}
项目:webtester-core
文件:WebDriverBrowserTest.java
@Test(expected = NoSuchFrameException.class)
public void testExceptionHandlingInCaseAFrameIsNotFoundForTheGivenNameOrId() {
TargetLocator locator = mockTargetLocator();
NoSuchFrameException exception = createSeleniumExceptionOfClass(NoSuchFrameException.class);
doThrow(exception).when(locator).frame(NAME_OR_ID);
try {
cut.setFocusOnFrame(NAME_OR_ID);
} finally {
verifyLastEventFiredWasExceptionEventOf(exception);
}
}
项目:webtester-core
文件:WebDriverBrowserTest.java
@Test(expected = NoSuchWindowException.class)
public void testExceptionHandlingInCaseAWindowIsNotFoundForTheGivenNameOrHandle() {
TargetLocator locator = mockTargetLocator();
NoSuchWindowException exception = createSeleniumExceptionOfClass(NoSuchWindowException.class);
doThrow(exception).when(locator).window(NAME_OR_HANDLE);
try {
cut.setFocusOnWindow(NAME_OR_HANDLE);
} finally {
verifyLastEventFiredWasExceptionEventOf(exception);
}
}
项目:darcy-webdriver
文件:WebDriverTargets.java
@Override
public WebDriver switchTo(TargetLocator targetLocator) {
// This is ugly :(
if (targetLocator instanceof CachingTargetLocator) {
return ((CachingTargetLocator) targetLocator).frame(parent, index);
}
parent.switchTo(targetLocator);
return targetLocator.frame(index);
}
项目:darcy-webdriver
文件:WebDriverTargets.java
@Override
public WebDriver switchTo(TargetLocator targetLocator) {
// This is ugly :(
if (targetLocator instanceof CachingTargetLocator) {
return ((CachingTargetLocator) targetLocator).frame(parent, nameOrId);
}
parent.switchTo(targetLocator);
return targetLocator.frame(nameOrId);
}
项目:darcy-webdriver
文件:WebDriverTargets.java
@Override
public WebDriver switchTo(TargetLocator targetLocator) {
// This is ugly :(
if (targetLocator instanceof CachingTargetLocator) {
return ((CachingTargetLocator) targetLocator).frame(parent, frameElement);
}
parent.switchTo(targetLocator);
return targetLocator.frame(frameElement);
}
项目:darcy-webdriver
文件:WebDriverTargets.java
@Override
public WebDriver switchTo(TargetLocator targetLocator) {
if (windowHandle == null) {
windowHandle = findWindow(targetLocator);
}
return targetLocator.window(windowHandle);
}
项目:darcy-webdriver
文件:WebDriverTargets.java
private String findWindow(TargetLocator targetLocator) {
for (String windowHandle : targetLocator.defaultContent().getWindowHandles()) {
Browser forWindowHandle = By.id(windowHandle).find(Browser.class, parentContext);
view.setContext(forWindowHandle);
if (view.isLoaded()) {
return windowHandle;
}
}
throw new NoSuchWindowException("No window in driver found which has " + view + " "
+ "currently loaded.");
}
项目:darcy-webdriver
文件:WebDriverTargets.java
@Override
public WebDriver switchTo(TargetLocator targetLocator) {
if (windowHandle == null) {
windowHandle = findWindow(targetLocator);
}
return targetLocator.window(windowHandle);
}
项目:darcy-webdriver
文件:WebDriverTargets.java
private String findWindow(TargetLocator targetLocator) {
for (String windowHandle : targetLocator.defaultContent().getWindowHandles()) {
if (targetLocator.window(windowHandle).getTitle().equals(title)) {
return windowHandle;
}
}
throw new NoSuchWindowException("No window in driver found which has title: " + title);
}
项目:darcy-webdriver
文件:WebDriverTargets.java
@Override
public WebDriver switchTo(TargetLocator targetLocator) {
if (windowHandle == null) {
windowHandle = findWindow(targetLocator);
}
return targetLocator.window(windowHandle);
}
项目:darcy-webdriver
文件:WebDriverTargets.java
private String findWindow(TargetLocator targetLocator) {
for (String windowHandle : targetLocator.defaultContent().getWindowHandles()) {
if (urlMatcher.matches(targetLocator.window(windowHandle).getCurrentUrl())) {
return windowHandle;
}
}
throw new NoSuchWindowException("No window in driver found which has url matching: " + urlMatcher);
}
项目:mineraloil-selenium
文件:WebdriverActions.java
public TargetLocator switchTo() {
return driver.switchTo();
}
项目:webtester-core
文件:WebDriverBrowserTest.java
@Test
public void testThatSwitchingToFrameWithIndexInvokesCorrectLocatorMethod() {
TargetLocator locator = mockTargetLocator();
cut.setFocusOnFrame(INDEX);
verify(locator).frame(INDEX);
}
项目:webtester-core
文件:WebDriverBrowserTest.java
@Test
public void testThatSwitchingToFrameWithNameOrIdInvokesCorrectLocatorMethod() {
TargetLocator locator = mockTargetLocator();
cut.setFocusOnFrame(NAME_OR_ID);
verify(locator).frame(NAME_OR_ID);
}
项目:webtester-core
文件:WebDriverBrowserTest.java
@Test
public void testThatSwitchingToWindowWithNameOrHanldeInvokesCorrectLocatorMethod() {
TargetLocator locator = mockTargetLocator();
cut.setFocusOnWindow(NAME_OR_HANDLE);
verify(locator).window(NAME_OR_HANDLE);
}
项目:webtester-core
文件:WebDriverBrowserTest.java
@Test
public void testThatSwitchingToDefaultContentInvokesCorrectLocatorMethod() {
TargetLocator locator = mockTargetLocator();
cut.setFocusOnDefaultContent();
verify(locator).defaultContent();
}
项目:webtester-core
文件:WebDriverBrowserTest.java
private TargetLocator mockTargetLocator() {
TargetLocator locator = mock(TargetLocator.class);
doReturn(locator).when(webDriver).switchTo();
return locator;
}
项目:darcy-webdriver
文件:WebDriverTargets.java
@Override
public WebDriver switchTo(TargetLocator targetLocator) {
return targetLocator.window(nameOrHandle);
}
项目:darcy-webdriver
文件:WebDriverTargets.java
@Override
public WebDriver switchTo(TargetLocator targetLocator) {
return targetLocator.defaultContent();
}
项目:darcy-webdriver
文件:TargetedWebDriverParentContext.java
/**
* @param myTarget Parent contexts must be targeted because frame targets depend on another,
* "parent" target. So each parent context must have its own WebDriver target that is
* associated with, because this state is used when finding frames.
* @param locator Means of finding other WebDrivers for new targets. Each new browser shares the
* same locator.
* @param knowsWindowHandles Finds open windows' handles. Must be associated with the same
* driver as the {@code locator}.
* @param elementMap Each new browser must have an element conFunction or type which can provide the current set of window
* handles of the driver associated with the locator.structor map so it may create
*/
public TargetedWebDriverParentContext(WebDriverTarget myTarget, TargetLocator locator,
KnowsWindowHandles knowsWindowHandles, ElementConstructorMap elementMap) {
this.myTarget = myTarget;
this.locator = locator;
this.knowsWindowHandles = knowsWindowHandles;
this.elementMap = elementMap;
}
项目:bobcat
文件:BobcatTargetLocator.java
/**
* Constructs TargetLocatorWrapper.
*
* @param targetLocator instance of TargetLocator.
* @param frameSwitcher instance of FrameSwitcher.
*/
public BobcatTargetLocator(TargetLocator targetLocator, FrameSwitcher frameSwitcher) {
super();
this.targetLocator = targetLocator;
this.frameSwitcher = frameSwitcher;
}
项目:darcy-webdriver
文件:WebDriverTarget.java
/**
* @throws org.openqa.selenium.NotFoundException if this target is not able to be switched to,
* as per {@link WebDriver#switchTo()} behavior.
*/
WebDriver switchTo(TargetLocator targetLocator);
项目:jfunk
文件:WebDriverTool.java
/**
* Issues a log message before executing {@link WebDriver#switchTo()}.
*
* @return A TargetLocator which can be used to select a frame or window
*/
public TargetLocator switchTo() {
LOGGER.info("Switching WebDriver...");
return webDriver.switchTo();
}