List of usage examples for org.openqa.selenium WebDriver getTitle
String getTitle();
From source file:de.codecentric.janus.plugin.suite.AbstractStep.java
License:Apache License
public void waitUntilPageTitleStartsWith(final String prefix) { waitUntil(new ExpectedCondition<Boolean>() { @Override/*from w w w . j a v a 2 s . c o m*/ public Boolean apply(@Nullable WebDriver driver) { return driver.getTitle().startsWith(prefix); } }); }
From source file:de.learnlib.alex.data.entities.actions.web.CheckPageTitleAction.java
License:Apache License
@Override public ExecuteResult execute(WebSiteConnector connector) { final WebDriver driver = connector.getDriver(); final boolean result = SearchHelper.search(getTitleWithVariableValues(), driver.getTitle(), regexp); LOGGER.info(LoggerMarkers.LEARNER, "Check if the current page has title '{}' => {} (regExp: {}).", title, result, regexp);//from w w w. j a va2s .c o m return result ? getSuccessOutput() : getFailedOutput(); }
From source file:de.learnlib.alex.data.entities.actions.web.CheckPageTitleActionTest.java
License:Apache License
@Test public void shouldReturnOKIfTitleWasFoundWithoutRegex() { WebSiteConnector webSiteConnector = mock(WebSiteConnector.class); WebDriver driver = mock(WebDriver.class); given((webSiteConnector.getDriver())).willReturn(driver); given(driver.getTitle()).willReturn("Awesome Title No. 0"); CounterStoreConnector counterStoreConnector = mock(CounterStoreConnector.class); ConnectorManager connectors = mock(ConnectorManager.class); given(connectors.getConnector(WebSiteConnector.class)).willReturn(webSiteConnector); given(connectors.getConnector(CounterStoreConnector.class)).willReturn(counterStoreConnector); assertTrue(checkNode.executeAction(connectors).isSuccess()); }
From source file:de.learnlib.alex.data.entities.actions.web.CheckPageTitleActionTest.java
License:Apache License
@Test public void shouldReturnFailedIfTitleWasNotFoundWithoutRegex() { ConnectorManager connectors = mock(ConnectorManager.class); WebSiteConnector webSiteConnector = mock(WebSiteConnector.class); given(connectors.getConnector(WebSiteConnector.class)).willReturn(webSiteConnector); WebDriver driver = mock(WebDriver.class); given((webSiteConnector.getDriver())).willReturn(driver); given(driver.getTitle()).willReturn("This is the wrong title"); CounterStoreConnector counterStoreConnector = mock(CounterStoreConnector.class); given(connectors.getConnector(CounterStoreConnector.class)).willReturn(counterStoreConnector); assertFalse(checkNode.executeAction(connectors).isSuccess()); }
From source file:de.learnlib.alex.data.entities.actions.web.CheckPageTitleActionTest.java
License:Apache License
@Test public void shouldReturnOKIfTitleWasFoundWithRegex() { ConnectorManager connectors = mock(ConnectorManager.class); WebSiteConnector webSiteConnector = mock(WebSiteConnector.class); given(connectors.getConnector(WebSiteConnector.class)).willReturn(webSiteConnector); WebDriver driver = mock(WebDriver.class); given((webSiteConnector.getDriver())).willReturn(driver); given(driver.getTitle()).willReturn("Fo0obar"); checkNode.setTitle("F[o0]*bar"); checkNode.setRegexp(true);/*from w ww . ja v a 2 s . co m*/ assertTrue(checkNode.executeAction(connectors).isSuccess()); }
From source file:de.learnlib.alex.data.entities.actions.web.CheckPageTitleActionTest.java
License:Apache License
@Test public void shouldReturnFailedIfTitleWasNotFoundWithRegex() { ConnectorManager connectors = mock(ConnectorManager.class); WebSiteConnector webSiteConnector = mock(WebSiteConnector.class); given(connectors.getConnector(WebSiteConnector.class)).willReturn(webSiteConnector); WebDriver driver = mock(WebDriver.class); given((webSiteConnector.getDriver())).willReturn(driver); given(driver.getTitle()).willReturn("This is the wrong title"); checkNode.setTitle("f[o0]+bar"); checkNode.setRegexp(true);/*from ww w . java 2s . co m*/ assertFalse(checkNode.executeAction(connectors).isSuccess()); }
From source file:de.learnlib.alex.data.entities.actions.web.WaitForTitleActionTest.java
License:Apache License
@Test public void shouldWaitUntilTheTitleIsTheExpectedValue() { WebDriver driver = mock(WebDriver.class); given(webSiteConnector.getDriver()).willReturn(driver); given(driver.getTitle()).willReturn(action.getValue()); action.setWaitCriterion(WaitForTitleAction.WaitCriterion.IS); action.setMaxWaitTime(ONE_MINUTE);//from w w w .j a v a 2s. co m ExecuteResult result = action.executeAction(connectors); assertTrue(result.isSuccess()); }
From source file:de.learnlib.alex.data.entities.actions.web.WaitForTitleActionTest.java
License:Apache License
@Test public void shouldWaitUntilTheTitleContainsTheExpectedValue() { WebDriver driver = mock(WebDriver.class); given(webSiteConnector.getDriver()).willReturn(driver); given(driver.getTitle()).willReturn(action.getValue() + " - extra stuff that should not matter!"); action.setWaitCriterion(WaitForTitleAction.WaitCriterion.CONTAINS); action.setMaxWaitTime(ONE_MINUTE);//from www . ja v a2s .co m ExecuteResult result = action.executeAction(connectors); assertTrue(result.isSuccess()); }
From source file:de.learnlib.alex.data.entities.actions.web.WaitForTitleActionTest.java
License:Apache License
@Test public void shouldFailOnTimeout() { WebDriver driver = mock(WebDriver.class); given(driver.getTitle()).willReturn("test title"); given(webSiteConnector.getDriver()).willReturn(driver); action.setWaitCriterion(WaitForTitleAction.WaitCriterion.IS); action.setMaxWaitTime(0); // don't really wait to keep the test speed high ExecuteResult result = action.executeAction(connectors); assertFalse(result.isSuccess());//ww w .ja v a 2s. com }
From source file:demo.seleniumtest.Demo.java
public static void main(String[] args) { System.setProperty("webdriver.gecko.driver", "C:\\Users\\Rumyana\\Desktop\\Testing\\SeleniumDrivers\\geckodriver.exe"); System.setProperty("webdriver.chrome.driver", "C:\\Users\\Rumyana\\Desktop\\Testing\\SeleniumDrivers\\chromedriver.exe"); // Create a new instance of the Firefox driver // Notice that the remainder of the code relies on the interface, // not the implementation. //Reset the Table WebDriver driver = new ChromeDriver(); // And now use this to visit Google driver.get("http://www.google.com"); // Alternatively the same thing can be done like this // driver.navigate().to("http://www.google.com"); // Find the text input element by its name WebElement element = driver.findElement(By.name("q")); // Enter something to search for element.sendKeys("Cheese!"); // Now submit the form. WebDriver will find the form for us from the element element.submit();//from ww w . j a v a 2 s . co m // Check the title of the page System.out.println("Page title is: " + driver.getTitle()); // Google's search is rendered dynamically with JavaScript. // Wait for the page to load, timeout after 10 seconds (new WebDriverWait(driver, 10)).until(new ExpectedCondition<Boolean>() { public Boolean apply(WebDriver d) { return d.getTitle().toLowerCase().startsWith("cheese!"); } }); // Should see: "cheese! - Google Search" System.out.println("Page title is: " + driver.getTitle()); //Close the browser driver.quit(); }