use of org.openqa.selenium.NoSuchElementException in project cerberus-source by cerberustesting.
the class ControlService method verifyTextNotInElement.
private MessageEvent verifyTextNotInElement(TestCaseExecution tCExecution, String path, String expected) {
if (LOG.isDebugEnabled()) {
LOG.debug("Control: verifyTextNotInElement on " + path + " element against value: " + expected);
}
// Get value from the path element according to the application type
String actual = null;
try {
Identifier identifier = identifierService.convertStringToIdentifier(path);
String applicationType = tCExecution.getApplicationObj().getType();
if (Application.TYPE_GUI.equalsIgnoreCase(applicationType) || Application.TYPE_APK.equalsIgnoreCase(applicationType) || Application.TYPE_IPA.equalsIgnoreCase(applicationType)) {
actual = webdriverService.getValueFromHTML(tCExecution.getSession(), identifier);
// In case of null actual value then we alert user
if (actual == null) {
MessageEvent mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_TEXTNOTINELEMENT_NULL);
mes.setDescription(mes.getDescription().replace("%STRING1%", path));
return mes;
}
// Construct the message from the actual response
MessageEvent mes = actual.equalsIgnoreCase(expected) ? new MessageEvent(MessageEventEnum.CONTROL_FAILED_TEXTNOTINELEMENT) : new MessageEvent(MessageEventEnum.CONTROL_SUCCESS_TEXTNOTINELEMENT);
mes.setDescription(mes.getDescription().replace("%STRING1%", path));
mes.setDescription(mes.getDescription().replace("%STRING2%", actual));
mes.setDescription(mes.getDescription().replace("%STRING3%", expected));
return mes;
} else if (Application.TYPE_SRV.equalsIgnoreCase(applicationType)) {
if (tCExecution.getLastServiceCalled() != null) {
String responseBody = tCExecution.getLastServiceCalled().getResponseHTTPBody();
MessageEvent mes;
switch(tCExecution.getLastServiceCalled().getResponseHTTPBodyContentType()) {
case AppService.RESPONSEHTTPBODYCONTENTTYPE_XML:
if (!xmlUnitService.isElementPresent(responseBody, path)) {
throw new NoSuchElementException("Unable to find element " + path);
}
String newPath = StringUtil.addSuffixIfNotAlready(path, "/text()");
actual = xmlUnitService.getFromXml(responseBody, newPath);
// In case of null actual value then we alert user
if (actual == null) {
mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_TEXTNOTINELEMENT_NULL);
mes.setDescription(mes.getDescription().replace("%STRING1%", path));
return mes;
}
// Construct the message from the actual response
mes = actual.equalsIgnoreCase(expected) ? new MessageEvent(MessageEventEnum.CONTROL_FAILED_TEXTNOTINELEMENT) : new MessageEvent(MessageEventEnum.CONTROL_SUCCESS_TEXTNOTINELEMENT);
mes.setDescription(mes.getDescription().replace("%STRING1%", path));
mes.setDescription(mes.getDescription().replace("%STRING2%", actual));
mes.setDescription(mes.getDescription().replace("%STRING3%", expected));
return mes;
case AppService.RESPONSEHTTPBODYCONTENTTYPE_JSON:
{
try {
actual = jsonService.getFromJson(responseBody, null, path);
} catch (Exception ex) {
mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_GENERIC);
mes.setDescription(mes.getDescription().replace("%ERROR%", ex.toString()));
return mes;
}
}
// In case of null actual value then we alert user
if (actual == null) {
mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_TEXTINELEMENT_NO_SUCH_ELEMENT);
mes.setDescription(mes.getDescription().replace("%ELEMENT%", path));
return mes;
}
// Construct the message from the actual response
mes = actual.equalsIgnoreCase(expected) ? new MessageEvent(MessageEventEnum.CONTROL_FAILED_TEXTNOTINELEMENT) : new MessageEvent(MessageEventEnum.CONTROL_SUCCESS_TEXTNOTINELEMENT);
mes.setDescription(mes.getDescription().replace("%STRING1%", path));
mes.setDescription(mes.getDescription().replace("%STRING2%", actual));
mes.setDescription(mes.getDescription().replace("%STRING3%", expected));
return mes;
default:
mes = new MessageEvent(MessageEventEnum.CONTROL_NOTEXECUTED_NOTSUPPORTED_FOR_MESSAGETYPE);
mes.setDescription(mes.getDescription().replace("%TYPE%", tCExecution.getLastServiceCalled().getResponseHTTPBodyContentType()));
mes.setDescription(mes.getDescription().replace("%CONTROL%", "verifyTextNotInElement"));
return mes;
}
} else {
MessageEvent mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_NOOBJECTINMEMORY);
return mes;
}
} else {
MessageEvent mes = new MessageEvent(MessageEventEnum.CONTROL_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION);
mes.setDescription(mes.getDescription().replace("%CONTROL%", "verifyTextNotInElement"));
mes.setDescription(mes.getDescription().replace("%APPLICATIONTYPE%", tCExecution.getApplicationObj().getType()));
return mes;
}
} catch (NoSuchElementException exception) {
MessageEvent mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_TEXTNOTINELEMENT_NO_SUCH_ELEMENT);
mes.setDescription(mes.getDescription().replace("%ELEMENT%", path));
return mes;
} catch (WebDriverException exception) {
return parseWebDriverException(exception);
}
}
use of org.openqa.selenium.NoSuchElementException 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;
}
use of org.openqa.selenium.NoSuchElementException in project selenium_java by sergueik.
the class CodeMirrorTest method test2.
// only loads first 35 lines of code
@Test(enabled = true)
public void test2() {
// Arrange
driver.get("https://codemirror.net/demo/simplemode.html");
WebElement codeElement = wait.until(ExpectedConditions.visibilityOf(driver.findElement(By.xpath("//div[@id = 'code']//div[@class='CodeMirror-code']"))));
assertThat(codeElement, notNullValue());
// Act
// brute force ?
int cnt = 0;
while (true) {
cnt++;
try {
WebElement codeLine = codeElement.findElement(By.cssSelector(String.format("pre[role='presentation']:nth-of-type(%d)", cnt)));
assertThat(codeLine, notNullValue());
executeScript("arguments[0].scrollIntoView(true);", codeLine);
highlight(codeLine);
System.err.println(codeLine.getText());
} catch (NoSuchElementException e) {
// e.printStackTrace();
break;
}
}
// Assert
}
use of org.openqa.selenium.NoSuchElementException in project irida by phac-nml.
the class ProjectSamplesPage method shareMoveSamples.
private void shareMoveSamples(String project, boolean owner) {
WebDriverWait wait = new WebDriverWait(driver, 10);
wait.until(ExpectedConditions.visibilityOf(copySamplesModal));
enterSelect2Value(project);
if (owner) {
try {
giveOwnerBtn.click();
} catch (NoSuchElementException e) {
throw new GiveOwnerNotDisplayedException();
}
}
wait.until(ExpectedConditions.elementToBeClickable(copyModalConfirmBtn));
copyModalConfirmBtn.click();
wait.until(ExpectedConditions.invisibilityOfElementLocated(By.className("t-copy-samples-modal")));
}
use of org.openqa.selenium.NoSuchElementException in project irida by phac-nml.
the class AbstractPage method get.
protected static void get(WebDriver driver, String relativeUrl) {
String url = BASE_URL + relativeUrl;
driver.get(url);
// Check to make sure that there is no server error
try {
WebElement main = driver.findElement(By.tagName("main"));
String error = main.getAttribute("data-error");
if (!Strings.isNullOrEmpty(error)) {
determineError(error);
}
} catch (NoSuchElementException e) {
logger.trace("Did not find `main` element on page when checking for errors, everything is *probably* OK.");
}
}
Aggregations