當前位置: 首頁>>代碼示例>>Java>>正文


Java SearchContext類代碼示例

本文整理匯總了Java中org.openqa.selenium.SearchContext的典型用法代碼示例。如果您正苦於以下問題:Java SearchContext類的具體用法?Java SearchContext怎麽用?Java SearchContext使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


SearchContext類屬於org.openqa.selenium包,在下文中一共展示了SearchContext類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getByRepeaterRow

import org.openqa.selenium.SearchContext; //導入依賴的package包/類
@SProperty(name = "ng-repeat-row")
public By getByRepeaterRow(String repeaterRow) {
    String repeater = repeaterRow.split("###")[0];
    int row = Integer.valueOf(repeaterRow.split("###")[1]);
    return new ByAngularRepeaterRow(NgWebDriver.DEFAULT_ROOT_SELECTOR, repeater, false, row) {
        @Override
        public List<WebElement> findElements(SearchContext searchContext) {
            List<WebElement> elements = new ArrayList<>();
            try {
                elements.add(this.findElement(searchContext));
            } catch (Exception ex) {

            }
            return elements;
        }
    };
}
 
開發者ID:CognizantQAHub,項目名稱:Cognizant-Intelligent-Test-Scripter,代碼行數:18,代碼來源:AngularFindBy.java

示例2: findElements

import org.openqa.selenium.SearchContext; //導入依賴的package包/類
@Override
public List<WebElement> findElements(SearchContext context) {
	if (locators.length == 0) {
		return new ArrayList<WebElement>();
	}
	List<WebElement> elems = new ArrayList<WebElement>();

	for (String locator : locators) {
		By by = LocatorUtil.getBy(locator);
		elems.addAll(by.findElements(context));
		if (!elems.isEmpty()) {
			break;
		}
	}

	return elems;
}
 
開發者ID:qmetry,項目名稱:qaf,代碼行數:18,代碼來源:ByAny.java

示例3: componentIsVisible

import org.openqa.selenium.SearchContext; //導入依賴的package包/類
/**
 * Returns a 'wait' proxy that determines if this page component is visible
 * 
 * @return page component if visible; otherwise 'null'
 */
public static Coordinator<PageComponent> componentIsVisible() {
    return new Coordinator<PageComponent>() {

        @Override
        public PageComponent apply(SearchContext context) {
            PageComponent component = verifyContext(context);
            return (component.isDisplayed()) ? component : null;
        }
        
        @Override
        public String toString() {
            return "page component to be visible";
        }
    };
}
 
開發者ID:Nordstrom,項目名稱:Selenium-Foundation,代碼行數:21,代碼來源:PageComponent.java

示例4: componentIsHidden

import org.openqa.selenium.SearchContext; //導入依賴的package包/類
/**
 * Returns a 'wait' proxy that determines if this page component is hidden
 * 
 * @return page component if hidden; otherwise 'null'
 */
public static Coordinator<PageComponent> componentIsHidden() {
    return new Coordinator<PageComponent>() {

        @Override
        public PageComponent apply(SearchContext context) {
            PageComponent component = verifyContext(context);
            return (component.isInvisible()) ? component : null;
        }
        
        @Override
        public String toString() {
            return "page component to be absent or hidden";
        }
    };
}
 
開發者ID:Nordstrom,項目名稱:Selenium-Foundation,代碼行數:21,代碼來源:PageComponent.java

示例5: referenceIsRefreshed

import org.openqa.selenium.SearchContext; //導入依賴的package包/類
/**
 * Returns a 'wait' proxy that refreshes the wrapped reference of the specified robust element.
 * 
 * @param wrapper robust element wrapper
 * @return wrapped element reference (refreshed)
 */
private static Coordinator<RobustElementWrapper> referenceIsRefreshed(final RobustElementWrapper wrapper) {
    return new Coordinator<RobustElementWrapper>() {

        @Override
        public RobustElementWrapper apply(SearchContext context) {
            try {
                return acquireReference(wrapper);
            } catch (StaleElementReferenceException e) {
                ((WrapsContext) context).refreshContext(((WrapsContext) context).acquiredAt());
                return acquireReference(wrapper);
            }
        }

        @Override
        public String toString() {
            return "element reference to be refreshed";
        }
    };
    
}
 
開發者ID:Nordstrom,項目名稱:Selenium-Foundation,代碼行數:27,代碼來源:RobustElementFactory.java

示例6: contextIsSwitched

import org.openqa.selenium.SearchContext; //導入依賴的package包/類
/**
 * Returns a 'wait' proxy that switches focus to the specified context
 * 
 * @param context search context on which to focus
 * @return target search context
 */
static Coordinator<SearchContext> contextIsSwitched(final ComponentContainer context) {
    return new Coordinator<SearchContext>() {

        @Override
        public SearchContext apply(SearchContext ignore) {
            if (context.parent != null) {
                context.parent.switchTo();
            }
            
            try {
                return context.switchToContext();
            } catch (StaleElementReferenceException e) {
                return context.refreshContext(context.acquiredAt());
            }
        }
        
        @Override
        public String toString() {
            return "context to be switched";
        }
    };
}
 
開發者ID:Nordstrom,項目名稱:Selenium-Foundation,代碼行數:29,代碼來源:ComponentContainer.java

示例7: landingPageAppears

import org.openqa.selenium.SearchContext; //導入依賴的package包/類
/**
 * Returns a 'wait' proxy that determines if the expected landing page has appeared.
 * 
 * @return 'true' if the expected landing page has appeared
 */
private static Coordinator<Boolean> landingPageAppears() {
    return new Coordinator<Boolean>() {

        @Override
        public Boolean apply(SearchContext context) {
            verifyLandingPage((Page) context);
            return Boolean.TRUE;
        }
        
        @Override
        public String toString() {
            return "expected landing page to appear";
        }
    };
}
 
開發者ID:Nordstrom,項目名稱:Selenium-Foundation,代碼行數:21,代碼來源:ComponentContainer.java

示例8: newWindowIsOpened

import org.openqa.selenium.SearchContext; //導入依賴的package包/類
/**
 * Returns a 'wait' proxy that determines if a new window has opened
 * 
 * @param initialHandles initial set of window handles
 * @return new window handle; 'null' if no new window found
 */
public static Coordinator<String> newWindowIsOpened(final Set<String> initialHandles) {
    return new Coordinator<String>() {

        @Override
        public String apply(SearchContext context) {
            Set<String> currentHandles = WebDriverUtils.getDriver(context).getWindowHandles();
            currentHandles.removeAll(initialHandles);
            if (currentHandles.isEmpty()) {
                return null;
            } else {
                return currentHandles.iterator().next();
            }
        }
        
        @Override
        public String toString() {
            return "new window to be opened";
        }
    };

}
 
開發者ID:Nordstrom,項目名稱:Selenium-Foundation,代碼行數:28,代碼來源:Coordinators.java

示例9: windowIsClosed

import org.openqa.selenium.SearchContext; //導入依賴的package包/類
/**
 * Returns a 'wait' proxy that determines if the specified window has closed
 * 
 * @param windowHandle handle of window that's expected to close
 * @return 'true' if the specified window has closed; otherwise 'false'
 */
public static Coordinator<Boolean> windowIsClosed(final String windowHandle) {
    return new Coordinator<Boolean>() {

        @Override
        public Boolean apply(SearchContext context) {
            Set<String> currentHandles = WebDriverUtils.getDriver(context).getWindowHandles();
            return Boolean.valueOf( ! currentHandles.contains(windowHandle));
        }
        
        @Override
        public String toString() {
            return "window with handle '" + windowHandle + "' to be closed";
        }
    };
}
 
開發者ID:Nordstrom,項目名稱:Selenium-Foundation,代碼行數:22,代碼來源:Coordinators.java

示例10: visibilityOfElementLocated

import org.openqa.selenium.SearchContext; //導入依賴的package包/類
/**
 * Returns a 'wait' proxy that determines if the first element matched by the specified locator is visible
 * 
 * @param locator web element locator
 * @return web element reference; 'null' if the indicated element is absent or hidden
 */
public static Coordinator<WebElement> visibilityOfElementLocated(final By locator) {
    return new Coordinator<WebElement>() {

        @Override
        public WebElement apply(SearchContext context) {
            try {
                return elementIfVisible(context.findElement(locator));
            } catch (StaleElementReferenceException e) {
                return null;
            }
        }

        @Override
        public String toString() {
            return "visibility of element located by " + locator;
        }
    };

}
 
開發者ID:Nordstrom,項目名稱:Selenium-Foundation,代碼行數:26,代碼來源:Coordinators.java

示例11: visibilityOfAnyElementLocated

import org.openqa.selenium.SearchContext; //導入依賴的package包/類
/**
 * Returns a 'wait' proxy that determines if any element matched by the specified locator is visible
 * 
 * @param locator web element locator
 * @return web element reference; 'null' if no matching elements are visible
 */
public static Coordinator<WebElement> visibilityOfAnyElementLocated(final By locator) {
    return new Coordinator<WebElement>() {

        @Override
        public WebElement apply(SearchContext context) {
            try {
                List<WebElement> visible = context.findElements(locator);
                return (WebDriverUtils.filterHidden(visible)) ? null : visible.get(0);
            } catch (StaleElementReferenceException e) {
                return null;
            }
        }

        @Override
        public String toString() {
            return "visibility of element located by " + locator;
        }
    };

}
 
開發者ID:Nordstrom,項目名稱:Selenium-Foundation,代碼行數:27,代碼來源:Coordinators.java

示例12: invisibilityOfElementLocated

import org.openqa.selenium.SearchContext; //導入依賴的package包/類
/**
 * Returns a 'wait' proxy that determines if an element is either hidden or non-existent.
 *
 * @param locator web element locator
 * @return 'true' if the element is hidden or non-existent; otherwise 'false'
 */
public static Coordinator<Boolean> invisibilityOfElementLocated(final By locator) {
    return new Coordinator<Boolean>() {
        
        @Override
        public Boolean apply(SearchContext context) {
            try {
                return !(context.findElement(locator).isDisplayed());
            } catch (NoSuchElementException | StaleElementReferenceException e) {
                // NoSuchElementException: The element is not present in DOM.
                // StaleElementReferenceException: Implies that element no longer exists in the DOM.
                return true;
            }
        }

        @Override
        public String toString() {
            return "element to no longer be visible: " + locator;
        }
    };
}
 
開發者ID:Nordstrom,項目名稱:Selenium-Foundation,代碼行數:27,代碼來源:Coordinators.java

示例13: stalenessOf

import org.openqa.selenium.SearchContext; //導入依賴的package包/類
/**
 * Returns a 'wait' proxy that determines if the specified element reference has gone stale.
 *
 * @param element the element to wait for
 * @return 'false' if the element reference is still valid; otherwise 'true'
 */
public static Coordinator<Boolean> stalenessOf(final WebElement element) {
    return new Coordinator<Boolean>() {
        private final ExpectedCondition<Boolean> condition = conditionInitializer();

        // initializer for [condition] field
        private final ExpectedCondition<Boolean> conditionInitializer() {
            if (element instanceof WrapsElement) {
                return ExpectedConditions.stalenessOf(((WrapsElement) element).getWrappedElement());
            } else {
                return ExpectedConditions.stalenessOf(element);
            }
        }

        @Override
        public Boolean apply(SearchContext ignored) {
            return condition.apply(null);
        }

        @Override
        public String toString() {
            return condition.toString();
        }
    };
}
 
開發者ID:Nordstrom,項目名稱:Selenium-Foundation,代碼行數:31,代碼來源:Coordinators.java

示例14: testGetDriver

import org.openqa.selenium.SearchContext; //導入依賴的package包/類
@Test
public void testGetDriver() {
    WebDriver driver = getDriver();
    ExamplePage page = getPage();
    WebElement element = page.findElement(By.tagName("html"));
    
    assertTrue(WebDriverUtils.getDriver((SearchContext) driver) == driver);
    assertTrue(WebDriverUtils.getDriver(page) == driver);
    assertTrue(WebDriverUtils.getDriver(element) == driver);
    
    try {
        WebDriverUtils.getDriver(mock(SearchContext.class));
        fail("No exception was thrown");
    } catch (UnsupportedOperationException e) {
        assertEquals(e.getMessage(), "Unable to extract the driver from the specified context");
    }
}
 
開發者ID:Nordstrom,項目名稱:Selenium-Foundation,代碼行數:18,代碼來源:WebDriverUtilsTest.java

示例15: testBrowserName

import org.openqa.selenium.SearchContext; //導入依賴的package包/類
@Test
public void testBrowserName() {
    WebDriver driver = getDriver();
    ExamplePage page = getPage();
    WebElement element = page.findElement(By.tagName("html"));
    SeleniumConfig config = SeleniumConfig.getConfig();
    String browserName = config.getBrowserCaps().getBrowserName();
    
    assertEquals(WebDriverUtils.getBrowserName((SearchContext) driver), browserName);
    assertEquals(WebDriverUtils.getBrowserName(page), browserName);
    assertEquals(WebDriverUtils.getBrowserName(element), browserName);
    
    try {
        WebDriverUtils.getBrowserName(mock(WebDriver.class));
        fail("No exception was thrown");
    } catch (UnsupportedOperationException e) {
        assertEquals(e.getMessage(), "The specified context is unable to describe its capabilities");
    }
}
 
開發者ID:Nordstrom,項目名稱:Selenium-Foundation,代碼行數:20,代碼來源:WebDriverUtilsTest.java


注:本文中的org.openqa.selenium.SearchContext類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。