use of com.github.noraui.exception.TechnicalException in project NoraUi by NoraUi.
the class Step method selectCheckbox.
/**
* Checks a checkbox type element (value corresponding to key "valueKey").
*
* @param element
* Target page element
* @param valueKeyOrKey
* is valueKey (valueKey or key in context (after a save)) to match in values map
* @param values
* Values map
* @throws TechnicalException
* is thrown if you have a technical error (format, configuration, datas, ...) in NoraUi.
* Failure with {@value com.github.noraui.utils.Messages#FAIL_MESSAGE_UNABLE_TO_CHECK_ELEMENT} message (with screenshot)
* @throws FailureException
* if the scenario encounters a functional error
*/
protected void selectCheckbox(PageElement element, String valueKeyOrKey, Map<String, Boolean> values) throws TechnicalException, FailureException {
final String valueKey = Context.getValue(valueKeyOrKey) != null ? Context.getValue(valueKeyOrKey) : valueKeyOrKey;
try {
final WebElement webElement = Context.waitUntil(ExpectedConditions.elementToBeClickable(Utilities.getLocator(element)));
Boolean checkboxValue = values.get(valueKey);
if (checkboxValue == null) {
checkboxValue = values.get("Default");
}
if (webElement.isSelected() != checkboxValue.booleanValue()) {
webElement.click();
}
} catch (final Exception e) {
new Result.Failure<>(e.getMessage(), Messages.format(Messages.getMessage(Messages.FAIL_MESSAGE_UNABLE_TO_CHECK_ELEMENT), element, element.getPage().getApplication()), true, element.getPage().getCallBack());
}
}
use of com.github.noraui.exception.TechnicalException in project NoraUi by NoraUi.
the class Step method updateRadioList.
/**
* Update html radio button by value (value corresponding to key "index").
*
* @param pageElement
* Is concerned element
* @param valueKeyOrKey
* key printedValues
* @param printedValues
* contain all possible value (order by key)
* @throws TechnicalException
* is thrown if you have a technical error (format, configuration, datas, ...) in NoraUi.
* Exception with {@value com.github.noraui.utils.Messages#FAIL_MESSAGE_UNABLE_TO_SELECT_RADIO_BUTTON} message (with screenshot, with exception)
* @throws FailureException
* if the scenario encounters a functional error
*/
protected void updateRadioList(PageElement pageElement, String valueKeyOrKey, Map<String, String> printedValues) throws TechnicalException, FailureException {
final String valueKey = Context.getValue(valueKeyOrKey) != null ? Context.getValue(valueKeyOrKey) : valueKeyOrKey;
try {
final List<WebElement> radioButtons = Context.waitUntil(ExpectedConditions.presenceOfAllElementsLocatedBy(Utilities.getLocator(pageElement)));
String radioToSelect = printedValues.get(valueKey);
if (radioToSelect == null) {
radioToSelect = printedValues.get("Default");
}
for (final WebElement button : radioButtons) {
if (button.getAttribute(VALUE).equals(radioToSelect)) {
button.click();
break;
}
}
} catch (final Exception e) {
new Result.Failure<>(e.getMessage(), Messages.format(Messages.getMessage(Messages.FAIL_MESSAGE_UNABLE_TO_SELECT_RADIO_BUTTON), pageElement), true, pageElement.getPage().getCallBack());
}
}
use of com.github.noraui.exception.TechnicalException in project NoraUi by NoraUi.
the class Auth method getAuthenticationCookie.
/**
* Returns a Cookie object by retrieving data from -Dcookie maven parameter.
*
* @param domainUrl
* is url of guardian domain
* @return a Cookie with a name, value, domain and path.
* @throws TechnicalException
* with a message (no screenshot, no exception)
*/
public static Cookie getAuthenticationCookie(String domainUrl) throws TechnicalException {
if (getInstance().authCookie == null) {
String cookieStr = System.getProperty(SESSION_COOKIE);
try {
if (cookieStr != null && !"".equals(cookieStr)) {
int indexValue = cookieStr.indexOf('=');
int indexPath = cookieStr.indexOf(",path=");
String cookieName = cookieStr.substring(0, indexValue);
String cookieValue = cookieStr.substring(indexValue + 1, indexPath);
String cookieDomain = new URI(domainUrl).getHost().replaceAll("self.", "");
String cookiePath = cookieStr.substring(indexPath + 6);
getInstance().authCookie = new Cookie.Builder(cookieName, cookieValue).domain(cookieDomain).path(cookiePath).build();
logger.debug("New cookie created: {}={} on domain {}{}", cookieName, cookieValue, cookieDomain, cookiePath);
}
} catch (URISyntaxException e) {
throw new TechnicalException(Messages.getMessage(WRONG_URI_SYNTAX), e);
}
}
return getInstance().authCookie;
}
use of com.github.noraui.exception.TechnicalException in project NoraUi by NoraUi.
the class DriverFactory method generateIEDriver.
/**
* Generates an ie webdriver. Unable to use it with a proxy. Causes a crash.
*
* @return
* An ie webdriver
* @throws TechnicalException
* if an error occured when Webdriver setExecutable to true.
*/
private WebDriver generateIEDriver() throws TechnicalException {
final String pathWebdriver = DriverFactory.getPath(Driver.IE);
if (!new File(pathWebdriver).setExecutable(true)) {
throw new TechnicalException(Messages.getMessage(TechnicalException.TECHNICAL_ERROR_MESSAGE_WEBDRIVER_SET_EXECUTABLE));
}
logger.info("Generating IE driver ({}) ...", pathWebdriver);
System.setProperty(Driver.IE.getDriverName(), pathWebdriver);
final DesiredCapabilities capabilities = DesiredCapabilities.internetExplorer();
capabilities.setCapability(InternetExplorerDriver.IE_ENSURE_CLEAN_SESSION, true);
capabilities.setCapability(InternetExplorerDriver.IGNORE_ZOOM_SETTING, true);
capabilities.setCapability(InternetExplorerDriver.REQUIRE_WINDOW_FOCUS, true);
capabilities.setCapability(InternetExplorerDriver.NATIVE_EVENTS, false);
capabilities.setCapability(CapabilityType.UNEXPECTED_ALERT_BEHAVIOUR, UnexpectedAlertBehaviour.ACCEPT);
capabilities.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, true);
capabilities.setCapability("disable-popup-blocking", true);
capabilities.setJavascriptEnabled(true);
setLoggingLevel(capabilities);
// Proxy configuration
if (Context.getProxy().getProxyType() != ProxyType.UNSPECIFIED && Context.getProxy().getProxyType() != ProxyType.AUTODETECT) {
capabilities.setCapability(CapabilityType.PROXY, Context.getProxy());
}
return new InternetExplorerDriver(capabilities);
}
use of com.github.noraui.exception.TechnicalException in project NoraUi by NoraUi.
the class DriverFactory method generateFirefoxDriver.
/**
* Generates a firefox webdriver.
*
* @return
* A firefox webdriver
* @throws TechnicalException
* if an error occured when Webdriver setExecutable to true.
*/
private WebDriver generateFirefoxDriver() throws TechnicalException {
final String pathWebdriver = DriverFactory.getPath(Driver.FIREFOX);
if (!new File(pathWebdriver).setExecutable(true)) {
throw new TechnicalException(Messages.getMessage(TechnicalException.TECHNICAL_ERROR_MESSAGE_WEBDRIVER_SET_EXECUTABLE));
}
logger.info("Generating Firefox driver ({}) ...", pathWebdriver);
System.setProperty(Driver.FIREFOX.getDriverName(), pathWebdriver);
final FirefoxOptions firefoxOptions = new FirefoxOptions();
final FirefoxBinary firefoxBinary = new FirefoxBinary();
final DesiredCapabilities capabilities = DesiredCapabilities.firefox();
capabilities.setCapability(CapabilityType.ForSeleniumServer.ENSURING_CLEAN_SESSION, true);
capabilities.setCapability(CapabilityType.UNEXPECTED_ALERT_BEHAVIOUR, UnexpectedAlertBehaviour.ACCEPT);
setLoggingLevel(capabilities);
// Proxy configuration
if (Context.getProxy().getProxyType() != ProxyType.UNSPECIFIED && Context.getProxy().getProxyType() != ProxyType.AUTODETECT) {
capabilities.setCapability(CapabilityType.PROXY, Context.getProxy());
}
if (Context.isHeadless()) {
firefoxBinary.addCommandLineOptions("--headless");
firefoxOptions.setBinary(firefoxBinary);
}
firefoxOptions.setLogLevel(Level.OFF);
capabilities.setCapability(FirefoxOptions.FIREFOX_OPTIONS, firefoxOptions);
return new FirefoxDriver(capabilities);
}
Aggregations