use of com.github.noraui.exception.TechnicalException in project NoraUi by NoraUi.
the class CommonSteps method doUntil.
/**
* Does steps execution until a given condition is unverified.
*
* @param actual
* actual value for global condition.
* @param expected
* expected value for global condition.
* @param key
* key of 'expected' values ('actual' values)
* @param breakCondition
* 'expected' values
* @param tries
* number of max tries (no infinity loop).
* @param conditions
* list of steps run in a loop.
*/
@Lorsque("Si '(.*)' vérifie '(.*)', je fais jusqu'à '(.*)' respecte '(.*)' avec '(.*)' essais maxi:")
@Then("If '(.*)' matches '(.*)', I do until '(.*)' respects '(.*)' with '(.*)' max tries:")
public void doUntil(String actual, String expected, String key, String breakCondition, int tries, List<GherkinConditionedLoopedStep> conditions) {
try {
if (new GherkinStepCondition("doUntilKey", expected, actual).checkCondition()) {
int i = 0;
do {
i++;
runAllStepsInLoop(conditions);
} while (!Pattern.compile(breakCondition).matcher(Context.getValue(key) == null ? "" : Context.getValue(key)).find() && i <= tries);
}
} catch (final TechnicalException e) {
throw new AssertError(Messages.getMessage(TechnicalException.TECHNICAL_SUBSTEP_ERROR_MESSAGE) + e.getMessage());
}
}
use of com.github.noraui.exception.TechnicalException in project NoraUi by NoraUi.
the class CommonSteps method whileDo.
/**
* While a given condition is verified, does steps execution.
*
* @param actual
* actual value for global condition.
* @param expected
* expected value for global condition.
* @param key
* key of 'expected' values ('actual' values)
* @param breakCondition
* 'expected' values
* @param tries
* number of max tries (no infinity loop).
* @param conditions
* list of steps run in a loop.
*/
@Lorsque("Si '(.*)' vérifie '(.*)', Tant que '(.*)' respecte '(.*)' je fais avec '(.*)' essais maxi:")
@Then("If '(.*)' matches '(.*)', While '(.*)' respects '(.*)' I do with '(.*)' max tries:")
public void whileDo(String actual, String expected, String key, String breakCondition, int tries, List<GherkinConditionedLoopedStep> conditions) {
try {
if (new GherkinStepCondition("whileDoKey", expected, actual).checkCondition()) {
int i = 0;
while (!Pattern.compile(breakCondition).matcher(Context.getValue(key) == null ? "" : Context.getValue(key)).find() && i <= tries) {
i++;
runAllStepsInLoop(conditions);
}
}
} catch (final TechnicalException e) {
throw new AssertError(Messages.getMessage(TechnicalException.TECHNICAL_SUBSTEP_ERROR_MESSAGE) + e.getMessage());
}
}
use of com.github.noraui.exception.TechnicalException in project NoraUi by NoraUi.
the class CommonSteps method clickOnAndSwitchWindow.
/**
* Click on html element and switch window when the scenario contain more one windows (one more application for example), if all 'expected' parameters equals 'actual' parameters in conditions.
*
* @param page
* The concerned page of toClick
* @param toClick
* html element
* @param windowKey
* the key of window (popup, ...) Example: 'demo.Popup1DemoPage'.
* @param conditions
* list of 'expected' values condition and 'actual' values ({@link com.github.noraui.gherkin.GherkinStepCondition}).
* @throws FailureException
* if the scenario encounters a functional error
* @throws TechnicalException
* is thrown if you have a technical error (format, configuration, datas, ...) in NoraUi.
*/
@Conditioned
@Quand("Je clique sur '(.*)-(.*)' et passe sur '(.*)' de type fenêtre[\\.|\\?]")
@When("I click on '(.*)-(.*)' and switch to '(.*)' window[\\.|\\?]")
public void clickOnAndSwitchWindow(String page, String toClick, String windowKey, List<GherkinStepCondition> conditions) throws FailureException, TechnicalException {
final String wKey = Page.getInstance(page).getApplication() + Page.getInstance(windowKey).getPageKey();
final String handleToSwitch = Context.getWindows().get(wKey);
if (handleToSwitch != null) {
Context.getDriver().switchTo().window(handleToSwitch);
// As a workaround: NoraUi specify window size manually, e.g. window_size: 1920 x 1080 (instead of .window().maximize()).
Context.getDriver().manage().window().setSize(new Dimension(1920, 1080));
Context.setMainWindow(windowKey);
} else {
try {
final Set<String> initialWindows = getDriver().getWindowHandles();
clickOn(Page.getInstance(page).getPageElementByKey('-' + toClick));
final String newWindowHandle = Context.waitUntil(WindowManager.newWindowOpens(initialWindows));
Context.addWindow(wKey, newWindowHandle);
getDriver().switchTo().window(newWindowHandle);
// As a workaround: NoraUi specify window size manually, e.g. window_size: 1920 x 1080 (instead of .window().maximize()).
Context.getDriver().manage().window().setSize(new Dimension(1920, 1080));
Context.setMainWindow(newWindowHandle);
} catch (final Exception e) {
new Result.Failure<>(e.getMessage(), Messages.format(Messages.getMessage(Messages.FAIL_MESSAGE_UNABLE_TO_SWITCH_WINDOW), windowKey), true, Page.getInstance(page).getCallBack());
}
if (!Page.getInstance(windowKey).checkPage()) {
new Result.Failure<>(windowKey, Messages.format(Messages.getMessage(Messages.FAIL_MESSAGE_UNABLE_TO_SWITCH_WINDOW), windowKey), true, Page.getInstance(page).getCallBack());
}
}
}
use of com.github.noraui.exception.TechnicalException in project NoraUi by NoraUi.
the class DriverFactory method generateGoogleChromeDriver.
/**
* Generates a chrome webdriver.
*
* @return
* A chrome webdriver
* @throws TechnicalException
* if an error occured when Webdriver setExecutable to true.
*/
private WebDriver generateGoogleChromeDriver() throws TechnicalException {
final String pathWebdriver = DriverFactory.getPath(Driver.CHROME);
if (!new File(pathWebdriver).setExecutable(true)) {
throw new TechnicalException(Messages.getMessage(TechnicalException.TECHNICAL_ERROR_MESSAGE_WEBDRIVER_SET_EXECUTABLE));
}
logger.info("Generating Chrome driver ({}) ...", pathWebdriver);
System.setProperty(Driver.CHROME.getDriverName(), pathWebdriver);
final ChromeOptions chromeOptions = new ChromeOptions();
final DesiredCapabilities capabilities = DesiredCapabilities.chrome();
capabilities.setCapability(CapabilityType.ForSeleniumServer.ENSURING_CLEAN_SESSION, true);
capabilities.setCapability(CapabilityType.UNEXPECTED_ALERT_BEHAVIOUR, UnexpectedAlertBehaviour.ACCEPT);
setLoggingLevel(capabilities);
if (Context.isHeadless()) {
chromeOptions.addArguments("--headless");
}
// Proxy configuration
if (Context.getProxy().getProxyType() != ProxyType.UNSPECIFIED && Context.getProxy().getProxyType() != ProxyType.AUTODETECT) {
capabilities.setCapability(CapabilityType.PROXY, Context.getProxy());
}
setChromeOptions(capabilities, chromeOptions);
final String withWhitelistedIps = Context.getWebdriversProperties("withWhitelistedIps");
if (withWhitelistedIps != null && !"".equals(withWhitelistedIps)) {
final ChromeDriverService service = new ChromeDriverService.Builder().withWhitelistedIps(withWhitelistedIps).withVerbose(false).build();
return new ChromeDriver(service, capabilities);
} else {
return new ChromeDriver(capabilities);
}
}
use of com.github.noraui.exception.TechnicalException in project NoraUi by NoraUi.
the class DriverFactory method getDriver.
/**
* Get selenium driver. Drivers are lazy loaded.
*
* @return selenium driver
*/
public WebDriver getDriver() {
// Driver's name is retrieved by system properties
String driverName = Context.getBrowser();
driverName = driverName != null ? driverName : DEFAULT_DRIVER;
WebDriver driver = null;
if (!drivers.containsKey(driverName)) {
try {
driver = generateWebDriver(driverName);
} catch (final TechnicalException e) {
logger.error("error DriverFactory.getDriver()", e);
}
} else {
driver = drivers.get(driverName);
}
return driver;
}
Aggregations