本文整理汇总了Java中org.openqa.selenium.internal.WrapsDriver类的典型用法代码示例。如果您正苦于以下问题:Java WrapsDriver类的具体用法?Java WrapsDriver怎么用?Java WrapsDriver使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
WrapsDriver类属于org.openqa.selenium.internal包,在下文中一共展示了WrapsDriver类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: mockElement
import org.openqa.selenium.internal.WrapsDriver; //导入依赖的package包/类
/**
* Create mocked {@link WebElement} object.
*
* @param type element type
* @param value element value
* @param isCheckbox 'true' is checkbox is desired; otherwise 'false'
* @return mocked WebElement object
*/
private static WebElement mockElement(String type, String value, boolean isCheckbox) {
WebElement element = mock(WebElement.class, withSettings().extraInterfaces(WrapsDriver.class));
when(element.getTagName()).thenReturn(type);
if (isCheckbox) {
when(element.getAttribute("type")).thenReturn("checkbox");
when(element.getAttribute("value")).thenReturn("isSelected: " + value);
when(element.isSelected()).thenReturn(Boolean.parseBoolean(value));
} else {
when(element.getAttribute("type")).thenReturn("text");
when(element.getAttribute("value")).thenReturn(value);
when(element.isSelected()).thenReturn(false);
}
WebDriver driver = mockDriver();
when(((WrapsDriver) element).getWrappedDriver()).thenReturn(driver);
return element;
}
示例2: constructor_WrapsDriver_Test
import org.openqa.selenium.internal.WrapsDriver; //导入依赖的package包/类
@Test
public void constructor_WrapsDriver_Test() {
// null
ManagedWebDriverContext managedWebDriverContext = new ManagedWebDriverContext((WrapsDriver) null);
assertEquals(WebDriverManager.getDriverContext(), managedWebDriverContext.getDriverContext());
assertEquals(WebDriverManager.getDriverContext().getWrappedDriver(), managedWebDriverContext.getDriverContext().getWrappedDriver());
// non-null
WebDriver webDriver = Mock.getWebDriver();
WrapsDriver wrapsDriver = Mock.wrapsDriver(webDriver);
managedWebDriverContext = new ManagedWebDriverContext(wrapsDriver);
assertEquals(wrapsDriver, managedWebDriverContext.getDriverContext());
assertEquals(webDriver, managedWebDriverContext.getDriverContext().getWrappedDriver());
}
示例3: setAndGetDriverContextTest
import org.openqa.selenium.internal.WrapsDriver; //导入依赖的package包/类
@Test
public void setAndGetDriverContextTest() {
ManagedWebDriverContext managedWebDriverContext = new ManagedWebDriverContext();
managedWebDriverContext.setDriverContext(null);
assertNull(managedWebDriverContext.getDriverContext());
WebDriver webDriver = Mock.getWebDriver();
WrapsDriver wrapsDriver = Mock.wrapsDriver(webDriver);
managedWebDriverContext.setDriverContext(wrapsDriver);
assertEquals(wrapsDriver, managedWebDriverContext.getDriverContext());
assertEquals(webDriver, managedWebDriverContext.getDriverContext().getWrappedDriver());
assertEquals(webDriver, managedWebDriverContext.getWrappedDriver());
}
示例4: toStringTest
import org.openqa.selenium.internal.WrapsDriver; //导入依赖的package包/类
@Test
public void toStringTest() {
ManagedWebDriverContext managedWebDriverContext = new ManagedWebDriverContext(Mock.wrapsDriver(Mock.getWebDriver()));
assertEquals("ManagedWebDriverContext [driverContext=" + managedWebDriverContext.getDriverContext() + "]", managedWebDriverContext.toString());
managedWebDriverContext = new ManagedWebDriverContext((WrapsDriver) null);
assertEquals("ManagedWebDriverContext [driverContext=" + managedWebDriverContext.getDriverContext() + "]", managedWebDriverContext.toString());
managedWebDriverContext = new ManagedWebDriverContext(Mock.getWebDriver());
assertEquals("ManagedWebDriverContext [driverContext=" + managedWebDriverContext.getDriverContext() + "]", managedWebDriverContext.toString());
managedWebDriverContext = new ManagedWebDriverContext((WebDriver) null);
assertEquals("ManagedWebDriverContext [driverContext=" + managedWebDriverContext.getDriverContext() + "]", managedWebDriverContext.toString());
managedWebDriverContext = new ManagedWebDriverContext();
assertEquals("ManagedWebDriverContext [driverContext=" + managedWebDriverContext.getDriverContext() + "]", managedWebDriverContext.toString());
}
示例5: unpackWebDriverFromSearchContext
import org.openqa.selenium.internal.WrapsDriver; //导入依赖的package包/类
/**
* This method extract an instance of {@link org.openqa.selenium.WebDriver} from the given
* {@link org.openqa.selenium.SearchContext}.
* @param searchContext is an instance of {@link org.openqa.selenium.SearchContext}
* It may be the instance of {@link org.openqa.selenium.WebDriver}
* or {@link org.openqa.selenium.WebElement} or some other user's
* extension/implementation.
* Note: if you want to use your own implementation then it should implement
* {@link org.openqa.selenium.internal.WrapsDriver} or
* {@link org.openqa.selenium.internal.WrapsElement}
* @return the instance of {@link org.openqa.selenium.WebDriver}.
* Note: if the given {@link org.openqa.selenium.SearchContext} is not
* {@link org.openqa.selenium.WebDriver} and it doesn't implement
* {@link org.openqa.selenium.internal.WrapsDriver} or
* {@link org.openqa.selenium.internal.WrapsElement} then this method returns
* null.
*
*/
public static WebDriver unpackWebDriverFromSearchContext(SearchContext searchContext) {
if (searchContext instanceof WebDriver) {
return (WebDriver) searchContext;
}
if (searchContext instanceof WrapsDriver) {
return unpackWebDriverFromSearchContext(
((WrapsDriver) searchContext).getWrappedDriver());
}
// Search context it is not only Webdriver. Webelement is search context
// too.
// RemoteWebElement and MobileElement implement WrapsDriver
if (searchContext instanceof WrapsElement) {
return unpackWebDriverFromSearchContext(
((WrapsElement) searchContext).getWrappedElement());
}
return null;
}
示例6: getJavascriptExecutor
import org.openqa.selenium.internal.WrapsDriver; //导入依赖的package包/类
/**
* Obtains executor based on Selenium context.
* @param searchContext context in which javascript should be executed.
* @return JavascriptExecutor based on search context.
* @throws IllegalArgumentException when no executor could be obtained from context.
*/
public static JavascriptExecutor getJavascriptExecutor(SearchContext searchContext) {
JavascriptExecutor executor = null;
if (searchContext instanceof JavascriptExecutor) {
executor = (JavascriptExecutor) searchContext;
} else {
if (searchContext instanceof WrapsDriver) {
WrapsDriver wraps = (WrapsDriver) searchContext;
WebDriver wrapped = wraps.getWrappedDriver();
if (wrapped instanceof JavascriptExecutor) {
executor = (JavascriptExecutor) wrapped;
}
}
}
if (executor == null) {
throw new IllegalArgumentException("Unable to get: " + JavascriptExecutor.class.getName()
+ " from: " + searchContext.getClass().getName());
}
return executor;
}
示例7: apply
import org.openqa.selenium.internal.WrapsDriver; //导入依赖的package包/类
@Override
public boolean apply(final WebElement element) {
try {
WebDriver driver = ((WrapsDriver) element).getWrappedDriver();
JavascriptExecutor js = (JavascriptExecutor) driver;
Boolean jQuery = (Boolean) js.executeScript("return (typeof jQuery !== 'undefined');");
if (!jQuery) {
logger.warn("Unable to apply the EventListenerRegisteredCondition as jQuery is undefined.");
return true;
}
@SuppressWarnings("unchecked")
Map<String, Object> registeredListeners = (Map<String, Object>) js.executeScript("return $._data($(arguments[0])[0], 'events')", element);
if (registeredListeners == null)
return false;
for (Map.Entry<String, Object> listener : registeredListeners.entrySet()) {
logger.debug("DomEvent listener [" + listener.getKey() + "] registered.");
if (listener.getKey().equals(event.getName())) {
return true;
}
}
return false;
} catch (NullPointerException | WebDriverException e) {
return false;
}
}
示例8: getDriver
import org.openqa.selenium.internal.WrapsDriver; //导入依赖的package包/类
/**
* Get the driver associated with the specified search context
*
* @param context search context
* @return search context driver
*/
public static WebDriver getDriver(SearchContext context) {
if (context instanceof WebDriver) {
return (WebDriver) context;
} else if (context instanceof WrapsDriver) {
return ((WrapsDriver) context).getWrappedDriver();
} else {
throw new UnsupportedOperationException("Unable to extract the driver from the specified context");
}
}
示例9: ManagedWebDriverContext
import org.openqa.selenium.internal.WrapsDriver; //导入依赖的package包/类
public ManagedWebDriverContext(WrapsDriver driverContext) {
if (driverContext == null) {
this.driverContext = WebDriverManager.getDriverContext();
} else {
this.driverContext = driverContext;
}
}
示例10: constructor_WrapsDriver_String_Test
import org.openqa.selenium.internal.WrapsDriver; //导入依赖的package包/类
@Test
public void constructor_WrapsDriver_String_Test() {
AbstractPageObjects abstractPageObjects = new AbstractPageObjects((WrapsDriver) null, null);
assertEquals(null, abstractPageObjects.getUrl());
abstractPageObjects = new AbstractPageObjects((WrapsDriver) null, "test");
assertEquals("test", abstractPageObjects.getUrl());
}
示例11: wrapsDriver
import org.openqa.selenium.internal.WrapsDriver; //导入依赖的package包/类
public static WrapsDriver wrapsDriver(WebDriver webDriver) {
return new WrapsDriver() {
@Override
public WebDriver getWrappedDriver() {
return webDriver;
}
};
}
示例12: intercept
import org.openqa.selenium.internal.WrapsDriver; //导入依赖的package包/类
/**
* Look at
* {@link net.sf.cglib.proxy.MethodInterceptor#intercept(Object, Method, Object[], MethodProxy)}
*/
public Object intercept(Object obj, Method method, Object[] args, MethodProxy proxy)
throws Throwable {
if (Object.class.equals(method.getDeclaringClass())) {
return proxy.invokeSuper(obj, args);
}
if (WrapsDriver.class.isAssignableFrom(method.getDeclaringClass()) && method.getName()
.equals("getWrappedDriver")) {
return driver;
}
WebElement realElement = locator.findElement();
return getObject(realElement, method, args);
}
示例13: getUnwrappedDriver
import org.openqa.selenium.internal.WrapsDriver; //导入依赖的package包/类
protected WebDriver getUnwrappedDriver() {
WebDriver toReturn = getDriver();
while (toReturn instanceof WrapsDriver) {
toReturn = ((WrapsDriver) toReturn).getWrappedDriver();
}
return toReturn;
}
示例14: highlightElement
import org.openqa.selenium.internal.WrapsDriver; //导入依赖的package包/类
public static void highlightElement(final WebElement element) {
for (int i = 0; i < 5; i++) {
final WrapsDriver wrappedElement = (WrapsDriver) element;
final JavascriptExecutor driver = (JavascriptExecutor) wrappedElement.getWrappedDriver();
driver.executeScript(
"arguments[0].setAttribute('style', arguments[1])", element, "visibility:hidden;");
// driver.executeScript("arguments[0].setAttribute('style', arguments[1]);", element, "");
}
}
示例15: apply
import org.openqa.selenium.internal.WrapsDriver; //导入依赖的package包/类
@Override
public boolean apply(final WebElement element) {
try {
WebDriver driver = ((WrapsDriver) element).getWrappedDriver();
JavascriptExecutor js = (JavascriptExecutor) driver;
return (Boolean) js
.executeScript(
"var rect = arguments[0].getBoundingClientRect();"
+ "return (rect.top >= 0 && rect.left >= 0 && rect.bottom <= (window.innerHeight || document.documentElement.clientHeight) && rect.right <= (window.innerWidth || document.documentElement.clientWidth));",
element);
} catch (NullPointerException | WebDriverException e) {
return false;
}
}