Search in sources :

Example 21 with TechnicalException

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());
    }
}
Also used : WebElement(org.openqa.selenium.WebElement) ParseException(java.text.ParseException) FailureException(com.github.noraui.exception.FailureException) TechnicalException(com.github.noraui.exception.TechnicalException) Result(com.github.noraui.exception.Result)

Example 22 with TechnicalException

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());
    }
}
Also used : WebElement(org.openqa.selenium.WebElement) ParseException(java.text.ParseException) FailureException(com.github.noraui.exception.FailureException) TechnicalException(com.github.noraui.exception.TechnicalException) Result(com.github.noraui.exception.Result)

Example 23 with TechnicalException

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;
}
Also used : TechnicalException(com.github.noraui.exception.TechnicalException) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI)

Example 24 with TechnicalException

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);
}
Also used : TechnicalException(com.github.noraui.exception.TechnicalException) InternetExplorerDriver(org.openqa.selenium.ie.InternetExplorerDriver) DesiredCapabilities(org.openqa.selenium.remote.DesiredCapabilities) File(java.io.File)

Example 25 with TechnicalException

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);
}
Also used : FirefoxOptions(org.openqa.selenium.firefox.FirefoxOptions) TechnicalException(com.github.noraui.exception.TechnicalException) FirefoxDriver(org.openqa.selenium.firefox.FirefoxDriver) FirefoxBinary(org.openqa.selenium.firefox.FirefoxBinary) DesiredCapabilities(org.openqa.selenium.remote.DesiredCapabilities) File(java.io.File)

Aggregations

TechnicalException (com.github.noraui.exception.TechnicalException)39 FailureException (com.github.noraui.exception.FailureException)13 Result (com.github.noraui.exception.Result)12 WebElement (org.openqa.selenium.WebElement)10 IOException (java.io.IOException)9 ParseException (java.text.ParseException)9 Test (org.junit.Test)8 PageElement (com.github.noraui.application.page.Page.PageElement)6 DemoPage (com.github.noraui.application.page.demo.DemoPage)6 ArrayList (java.util.ArrayList)5 Then (cucumber.api.java.en.Then)4 File (java.io.File)4 Path (java.nio.file.Path)4 Connection (java.sql.Connection)4 PreparedStatement (java.sql.PreparedStatement)4 ResultSet (java.sql.ResultSet)4 SQLException (java.sql.SQLException)4 GherkinStepCondition (com.github.noraui.gherkin.GherkinStepCondition)3 ModelList (com.github.noraui.model.ModelList)3 Conditioned (com.github.noraui.cucumber.annotation.Conditioned)2