use of org.openqa.selenium.TimeoutException in project cerberus-source by cerberustesting.
the class WebDriverService method doSeleniumActionSwitchToWindow.
@Override
public MessageEvent doSeleniumActionSwitchToWindow(Session session, Identifier identifier) {
MessageEvent message;
String windowTitle = identifier.getLocator();
String currentHandle;
// Add try catch to handle not exist anymore window (like when popup is closed).
try {
currentHandle = session.getDriver().getWindowHandle();
} catch (NoSuchWindowException exception) {
currentHandle = null;
LOG.debug("Window is closed ? " + exception.toString());
}
try {
// Get serials handles list of all browser windows
Set<String> handles = session.getDriver().getWindowHandles();
// Loop into each of them
for (String windowHandle : handles) {
if (!windowHandle.equals(currentHandle)) {
session.getDriver().switchTo().window(windowHandle);
if (checkIfExpectedWindow(session, identifier.getIdentifier(), identifier.getLocator())) {
message = new MessageEvent(MessageEventEnum.ACTION_SUCCESS_SWITCHTOWINDOW);
message.setDescription(message.getDescription().replace("%WINDOW%", windowTitle));
return message;
}
}
LOG.debug("windowHandle=" + windowHandle);
}
} catch (NoSuchElementException exception) {
LOG.debug(exception.toString());
} catch (TimeoutException exception) {
message = new MessageEvent(MessageEventEnum.ACTION_FAILED_TIMEOUT);
message.setDescription(message.getDescription().replace("%TIMEOUT%", String.valueOf(session.getCerberus_selenium_wait_element())));
LOG.warn(exception.toString());
return message;
} catch (WebDriverException exception) {
LOG.warn(exception.toString());
return parseWebDriverException(exception);
}
message = new MessageEvent(MessageEventEnum.ACTION_FAILED_SWITCHTOWINDOW_NO_SUCH_ELEMENT);
message.setDescription(message.getDescription().replace("%WINDOW%", windowTitle));
return message;
}
use of org.openqa.selenium.TimeoutException in project cerberus-source by cerberustesting.
the class WebDriverService method isElementNotVisible.
@Override
public boolean isElementNotVisible(Session session, Identifier identifier) {
By locator = this.getBy(identifier);
LOG.debug("Waiting for Element to be not visible : " + identifier.getIdentifier() + "=" + identifier.getLocator());
try {
WebDriverWait wait = new WebDriverWait(session.getDriver(), TimeUnit.MILLISECONDS.toSeconds(session.getCerberus_selenium_wait_element()));
return wait.until(ExpectedConditions.invisibilityOfElementLocated(locator));
} catch (TimeoutException exception) {
LOG.warn("Exception waiting for element to be not visible :" + exception);
return false;
}
}
use of org.openqa.selenium.TimeoutException in project cerberus-source by cerberustesting.
the class WebDriverService method doSeleniumActionMouseOver.
@Override
public MessageEvent doSeleniumActionMouseOver(Session session, Identifier identifier) {
MessageEvent message;
try {
AnswerItem answer = this.getSeleniumElement(session, identifier, true, true);
if (answer.isCodeEquals(MessageEventEnum.ACTION_SUCCESS_WAIT_ELEMENT.getCode())) {
WebElement menuHoverLink = (WebElement) answer.getItem();
if (menuHoverLink != null) {
Actions actions = new Actions(session.getDriver());
actions.moveToElement(menuHoverLink);
actions.build().perform();
message = new MessageEvent(MessageEventEnum.ACTION_SUCCESS_MOUSEOVER);
message.setDescription(message.getDescription().replace("%ELEMENT%", identifier.getIdentifier() + "=" + identifier.getLocator()));
return message;
}
}
return answer.getResultMessage();
} catch (NoSuchElementException exception) {
message = new MessageEvent(MessageEventEnum.ACTION_FAILED_MOUSEOVER_NO_SUCH_ELEMENT);
message.setDescription(message.getDescription().replace("%ELEMENT%", identifier.getIdentifier() + "=" + identifier.getLocator()));
LOG.debug(exception.toString());
return message;
} catch (TimeoutException exception) {
message = new MessageEvent(MessageEventEnum.ACTION_FAILED_TIMEOUT);
message.setDescription(message.getDescription().replace("%TIMEOUT%", String.valueOf(session.getCerberus_selenium_wait_element())));
LOG.warn(exception.toString());
return message;
} catch (WebDriverException exception) {
LOG.warn(exception.toString());
return parseWebDriverException(exception);
}
}
use of org.openqa.selenium.TimeoutException in project selenium_java by sergueik.
the class GoogleDriveTest method doLogin.
private void doLogin() {
// very similar to yandex login
// ...
// &continue=https://drive.google.com/%23&followup=https://drive.google.com/<mpl=drive&emr=1#identifier
// Given I access Google Drive
element = driver.findElement(By.cssSelector("a[href^='https://accounts.google.com/ServiceLogin']"));
highlight(element);
element.click();
System.err.println("current URL :" + driver.getCurrentUrl());
Pattern pattern = Pattern.compile(String.format("^%s.+&continue=([^&]+)&", loginURL));
Matcher matcher = pattern.matcher(driver.getCurrentUrl());
String retpath = null;
if (matcher.find()) {
try {
retpath = java.net.URLDecoder.decode(matcher.group(1).toString(), "UTF-8");
} catch (UnsupportedEncodingException e) {
// ignore
}
}
System.err.println("retpath: " + retpath);
try {
wait.until(ExpectedConditions.urlContains(loginURL));
} catch (TimeoutException e) {
System.err.println("Ignored exception " + e.toString());
}
// And I enter the username
element = driver.findElement(By.id("Email"));
highlight(element);
element.clear();
element.sendKeys(username);
driver.findElement(By.id("next")).click();
// And I enter the password
element = wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("Passwd")));
highlight(element);
element.clear();
element.sendKeys(password);
// And I sign in
driver.findElement(By.id("signIn")).click();
}
use of org.openqa.selenium.TimeoutException in project selenium_java by sergueik.
the class YandexTest method doLogin.
private String doLogin() {
// And I enter the username
WebElement element = driver.findElement(By.xpath("//form/div[1]/label/span/input"));
highlight(element);
element.clear();
element.sendKeys(username);
// Assert that input gets added to the background form
element = driver.findElement(By.cssSelector("form.new-auth-form input[name='login']"));
System.err.println("Username: " + element.getAttribute("value"));
// And I enter the password
element = driver.findElement(By.xpath("//form/div[2]/label/span/input"));
highlight(element);
element.clear();
element.sendKeys(password);
// Assert that input gets added to the background form
element = driver.findElement(By.cssSelector("form.new-auth-form input[name='passwd']"));
System.err.println("Password: " + element.getAttribute("value"));
// Evaluate the landing page URL
element = driver.findElement(By.cssSelector("form.new-auth-form span.new-auth-submit a.nb-button"));
String login_href = element.getAttribute("href");
System.err.println("Login href: " + login_href);
Pattern pattern = Pattern.compile(String.format("%s/auth/\\?mode=qr&retpath=(.+)$", loginURL));
Matcher matcher = pattern.matcher(login_href);
String retpath = null;
if (matcher.find()) {
try {
retpath = java.net.URLDecoder.decode(matcher.group(1).toString(), "UTF-8");
} catch (UnsupportedEncodingException e) {
// ignore
}
}
System.err.println("Login retpath: " + retpath);
// And I click the login button
element = driver.findElement(By.cssSelector("form.new-auth-form span.new-auth-submit button"));
highlight(element);
// String currentUrl = driver.getCurrentUrl();
element.click();
// wait until browser is away from the login page
System.err.println("Waiting to get away from " + loginURL);
try {
wait.until(ExpectedConditions.not(ExpectedConditions.urlContains(loginURL)));
} catch (TimeoutException tex) {
// verify if the page warns about the invalid credentials
try {
element = driver.findElement(By.cssSelector("div.layout-inner div.js-messages div.error-msg"));
verificationErrors.append("Getting error message " + element.getText());
System.err.println("Getting error message " + element.getText());
} catch (NoSuchElementException elex) {
// ignore
}
verificationErrors.append(tex.toString());
}
System.err.println("Waiting for " + retpath);
// wait until browser is on the landing page
wait.until(ExpectedConditions.urlContains(retpath));
// System.out.println("Page url: " + driver.getCurrentUrl());
try {
wait.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector("div.mail-App-Header div.mail-User")));
} catch (TimeoutException | UnreachableBrowserException e) {
verificationErrors.append(e.toString());
}
return retpath;
}
Aggregations