use of org.cerberus.exception.CerberusException in project cerberus-source by cerberustesting.
the class RecorderService method recordSeleniumLog.
@Override
public TestCaseExecutionFile recordSeleniumLog(TestCaseExecution testCaseExecution) {
TestCaseExecutionFile object = null;
// Used for logging purposes
String logPrefix = Infos.getInstance().getProjectNameAndVersion() + " - ";
if (testCaseExecution.getApplicationObj().getType().equals(Application.TYPE_GUI)) {
if (testCaseExecution.getSeleniumLog() == 2 || (testCaseExecution.getSeleniumLog() == 1 && !testCaseExecution.getControlStatus().equals("OK"))) {
LOG.debug(logPrefix + "Starting to save Selenium log file.");
try {
Recorder recorder = this.initFilenames(testCaseExecution.getId(), null, null, null, null, null, null, null, 0, "selenium_log", "txt", false);
File dir = new File(recorder.getFullPath());
dir.mkdirs();
File file = new File(recorder.getFullFilename());
try (FileOutputStream fileOutputStream = new FileOutputStream(file)) {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
DataOutputStream out = new DataOutputStream(baos);
for (String element : this.webdriverService.getSeleniumLog(testCaseExecution.getSession())) {
out.writeBytes(element);
}
byte[] bytes = baos.toByteArray();
fileOutputStream.write(bytes);
out.close();
baos.close();
fileOutputStream.close();
// Index file created to database.
object = testCaseExecutionFileFactory.create(0, testCaseExecution.getId(), recorder.getLevel(), "Selenium log", recorder.getRelativeFilenameURL(), "TXT", "", null, "", null);
testCaseExecutionFileService.save(object);
} catch (FileNotFoundException ex) {
LOG.error(logPrefix + ex.toString());
} catch (IOException ex) {
LOG.error(logPrefix + ex.toString());
}
LOG.debug(logPrefix + "Selenium log recorded in : " + recorder.getRelativeFilenameURL());
} catch (CerberusException ex) {
LOG.error(logPrefix + ex.toString());
}
}
} else {
LOG.debug(logPrefix + "Selenium Log not recorded because test on non GUI application");
}
return object;
}
use of org.cerberus.exception.CerberusException in project cerberus-source by cerberustesting.
the class SeleniumServerService method startServer.
@Override
public void startServer(TestCaseExecution tCExecution) throws CerberusException {
// message used for log purposes
String logPrefix = "[" + tCExecution.getTest() + " - " + tCExecution.getTestCase() + "] ";
try {
LOG.info(logPrefix + "Start Robot Server (Selenium, Appium or Sikuli)");
/**
* Set Session
*/
LOG.debug(logPrefix + "Setting the session.");
String system = tCExecution.getApplicationObj().getSystem();
/**
* Get the parameters that will be used to set the servers
* (selenium/appium) If timeout has been defined at the execution
* level, set the selenium & appium wait element with this value,
* else, take the one from parameter
*/
Integer cerberus_selenium_pageLoadTimeout, cerberus_selenium_implicitlyWait, cerberus_selenium_setScriptTimeout, cerberus_selenium_wait_element, cerberus_appium_wait_element, cerberus_selenium_action_click_timeout;
if (!tCExecution.getTimeout().isEmpty()) {
cerberus_selenium_wait_element = Integer.valueOf(tCExecution.getTimeout());
cerberus_appium_wait_element = Integer.valueOf(tCExecution.getTimeout());
} else {
cerberus_selenium_wait_element = parameterService.getParameterIntegerByKey("cerberus_selenium_wait_element", system, 90000);
cerberus_appium_wait_element = parameterService.getParameterIntegerByKey("cerberus_appium_wait_element", system, 90000);
}
cerberus_selenium_pageLoadTimeout = parameterService.getParameterIntegerByKey("cerberus_selenium_pageLoadTimeout", system, 90000);
cerberus_selenium_implicitlyWait = parameterService.getParameterIntegerByKey("cerberus_selenium_implicitlyWait", system, 0);
cerberus_selenium_setScriptTimeout = parameterService.getParameterIntegerByKey("cerberus_selenium_setScriptTimeout", system, 90000);
cerberus_selenium_action_click_timeout = parameterService.getParameterIntegerByKey("cerberus_selenium_action_click_timeout", system, 90000);
LOG.debug(logPrefix + "TimeOut defined on session : " + cerberus_selenium_wait_element);
Session session = new Session();
session.setCerberus_selenium_implicitlyWait(cerberus_selenium_implicitlyWait);
session.setCerberus_selenium_pageLoadTimeout(cerberus_selenium_pageLoadTimeout);
session.setCerberus_selenium_setScriptTimeout(cerberus_selenium_setScriptTimeout);
session.setCerberus_selenium_wait_element(cerberus_selenium_wait_element);
session.setCerberus_appium_wait_element(cerberus_appium_wait_element);
session.setCerberus_selenium_action_click_timeout(cerberus_selenium_action_click_timeout);
session.setHost(tCExecution.getSeleniumIP());
session.setHostUser(tCExecution.getSeleniumIPUser());
session.setHostPassword(tCExecution.getSeleniumIPPassword());
session.setPort(tCExecution.getPort());
tCExecution.setSession(session);
LOG.debug(logPrefix + "Session is set.");
/**
* SetUp Capabilities
*/
LOG.debug(logPrefix + "Set Capabilities");
DesiredCapabilities caps = this.setCapabilities(tCExecution);
session.setDesiredCapabilities(caps);
LOG.debug(logPrefix + "Set Capabilities - retreived");
/**
* SetUp Proxy
*/
String hubUrl = StringUtil.cleanHostURL(SeleniumServerService.getBaseUrl(StringUtil.formatURLCredential(tCExecution.getSession().getHostUser(), tCExecution.getSession().getHostPassword()) + session.getHost(), session.getPort())) + "/wd/hub";
LOG.debug(logPrefix + "Hub URL :" + hubUrl);
URL url = new URL(hubUrl);
HttpCommandExecutor executor = null;
boolean isProxy = proxyService.useProxy(hubUrl, system);
if (isProxy) {
String proxyHost = parameterService.getParameterStringByKey("cerberus_proxy_host", system, DEFAULT_PROXY_HOST);
int proxyPort = parameterService.getParameterIntegerByKey("cerberus_proxy_port", system, DEFAULT_PROXY_PORT);
HttpClientBuilder builder = HttpClientBuilder.create();
HttpHost proxy = new HttpHost(proxyHost, proxyPort);
builder.setProxy(proxy);
if (parameterService.getParameterBooleanByKey("cerberus_proxyauthentification_active", system, DEFAULT_PROXYAUTHENT_ACTIVATE)) {
String proxyUser = parameterService.getParameterStringByKey("cerberus_proxyauthentification_user", system, DEFAULT_PROXYAUTHENT_USER);
String proxyPassword = parameterService.getParameterStringByKey("cerberus_proxyauthentification_password", system, DEFAULT_PROXYAUTHENT_PASSWORD);
CredentialsProvider credsProvider = new BasicCredentialsProvider();
credsProvider.setCredentials(new AuthScope(proxyHost, proxyPort), new UsernamePasswordCredentials(proxyUser, proxyPassword));
if (url.getUserInfo() != null && !url.getUserInfo().isEmpty()) {
credsProvider.setCredentials(new AuthScope(url.getHost(), (url.getPort() > 0 ? url.getPort() : url.getDefaultPort())), new UsernamePasswordCredentials(tCExecution.getSession().getHostUser(), tCExecution.getSession().getHostPassword()));
}
builder.setDefaultCredentialsProvider(credsProvider);
}
Factory factory = new MyHttpClientFactory(builder);
executor = new HttpCommandExecutor(new HashMap<String, CommandInfo>(), url, factory);
}
/**
* SetUp Driver
*/
LOG.debug(logPrefix + "Set Driver");
WebDriver driver = null;
AppiumDriver appiumDriver = null;
if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_GUI)) {
if (caps.getPlatform().is(Platform.ANDROID)) {
if (executor == null) {
appiumDriver = new AndroidDriver(url, caps);
} else {
appiumDriver = new AndroidDriver(executor, caps);
}
driver = (WebDriver) appiumDriver;
} else if (caps.getPlatform().is(Platform.MAC)) {
if (executor == null) {
appiumDriver = new IOSDriver(url, caps);
} else {
appiumDriver = new IOSDriver(executor, caps);
}
driver = (WebDriver) appiumDriver;
} else // Any Other
{
if (executor == null) {
driver = new RemoteWebDriver(url, caps);
} else {
driver = new RemoteWebDriver(executor, caps);
}
}
} else if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_APK)) {
if (executor == null) {
appiumDriver = new AndroidDriver(url, caps);
} else {
appiumDriver = new AndroidDriver(executor, caps);
}
driver = (WebDriver) appiumDriver;
} else if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_IPA)) {
if (executor == null) {
appiumDriver = new IOSDriver(url, caps);
} else {
appiumDriver = new IOSDriver(executor, caps);
}
driver = (WebDriver) appiumDriver;
} else if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_FAT)) {
/**
* Check sikuli extension is reachable
*/
if (!sikuliService.isSikuliServerReachable(session)) {
MessageGeneral mes = new MessageGeneral(MessageGeneralEnum.VALIDATION_FAILED_SIKULI_COULDNOTCONNECT);
mes.setDescription(mes.getDescription().replace("%SSIP%", tCExecution.getSeleniumIP()));
mes.setDescription(mes.getDescription().replace("%SSPORT%", tCExecution.getSeleniumPort()));
throw new CerberusException(mes);
}
/**
* If CountryEnvParameter IP is set, open the App
*/
if (!tCExecution.getCountryEnvironmentParameters().getIp().isEmpty()) {
sikuliService.doSikuliActionOpenApp(session, tCExecution.getCountryEnvironmentParameters().getIp());
}
}
/**
* Defining the timeout at the driver level. Only in case of not
* Appium Driver (see
* https://github.com/vertigo17/Cerberus/issues/754)
*/
if (driver != null && appiumDriver == null) {
driver.manage().timeouts().pageLoadTimeout(cerberus_selenium_pageLoadTimeout, TimeUnit.MILLISECONDS);
driver.manage().timeouts().implicitlyWait(cerberus_selenium_implicitlyWait, TimeUnit.MILLISECONDS);
driver.manage().timeouts().setScriptTimeout(cerberus_selenium_setScriptTimeout, TimeUnit.MILLISECONDS);
}
tCExecution.getSession().setDriver(driver);
tCExecution.getSession().setAppiumDriver(appiumDriver);
/**
* If Gui application, maximize window Get IP of Node in case of
* remote Server. Maximize does not work for chrome browser We also
* get the Real UserAgent from the browser.
*/
if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_GUI) && !caps.getPlatform().equals(Platform.ANDROID)) {
if (!caps.getBrowserName().equals(BrowserType.CHROME)) {
driver.manage().window().maximize();
}
getIPOfNode(tCExecution);
/**
* If screenSize is defined, set the size of the screen.
*/
String targetScreensize = getScreenSizeToUse(tCExecution.getTestCaseObj().getScreenSize(), tCExecution.getScreenSize());
LOG.debug("Selenium resolution : " + targetScreensize);
if ((!StringUtil.isNullOrEmpty(targetScreensize)) && targetScreensize.contains("*")) {
Integer screenWidth = Integer.valueOf(targetScreensize.split("\\*")[0]);
Integer screenLength = Integer.valueOf(targetScreensize.split("\\*")[1]);
setScreenSize(driver, screenWidth, screenLength);
LOG.debug("Selenium resolution Activated : " + screenWidth + "*" + screenLength);
}
tCExecution.setScreenSize(getScreenSize(driver));
tCExecution.setRobotDecli(tCExecution.getRobotDecli().replace("%SCREENSIZE%", tCExecution.getScreenSize()));
String userAgent = (String) ((JavascriptExecutor) driver).executeScript("return navigator.userAgent;");
tCExecution.setUserAgent(userAgent);
}
tCExecution.getSession().setStarted(true);
} catch (CerberusException exception) {
LOG.error(logPrefix + exception.toString(), exception);
throw new CerberusException(exception.getMessageError());
} catch (MalformedURLException exception) {
LOG.error(logPrefix + exception.toString(), exception);
MessageGeneral mes = new MessageGeneral(MessageGeneralEnum.VALIDATION_FAILED_URL_MALFORMED);
mes.setDescription(mes.getDescription().replace("%URL%", tCExecution.getSession().getHost() + ":" + tCExecution.getSession().getPort()));
throw new CerberusException(mes);
} catch (UnreachableBrowserException exception) {
LOG.error(logPrefix + exception.toString(), exception);
MessageGeneral mes = new MessageGeneral(MessageGeneralEnum.VALIDATION_FAILED_SELENIUM_COULDNOTCONNECT);
mes.setDescription(mes.getDescription().replace("%SSIP%", tCExecution.getSeleniumIP()));
mes.setDescription(mes.getDescription().replace("%SSPORT%", tCExecution.getSeleniumPort()));
mes.setDescription(mes.getDescription().replace("%ERROR%", exception.toString()));
throw new CerberusException(mes);
} catch (Exception exception) {
LOG.error(logPrefix + exception.toString(), exception);
MessageGeneral mes = new MessageGeneral(MessageGeneralEnum.EXECUTION_FA_SELENIUM);
mes.setDescription(mes.getDescription().replace("%MES%", exception.toString()));
throw new CerberusException(mes);
}
}
use of org.cerberus.exception.CerberusException in project cerberus-source by cerberustesting.
the class TestDataLibDataService method compareListAndUpdateInsertDeleteElements.
@Override
public Answer compareListAndUpdateInsertDeleteElements(Integer testDataLibId, List<TestDataLibData> newList) {
Answer ans = new Answer(null);
MessageEvent msg1 = new MessageEvent(MessageEventEnum.GENERIC_OK);
Answer finalAnswer = new Answer(msg1);
List<TestDataLibData> oldList = new ArrayList();
try {
oldList = this.convert(this.readByVarious(testDataLibId, null, null, null));
} catch (CerberusException ex) {
LOG.error(ex);
}
/**
* Update and Create all objects database Objects from newList
*/
List<TestDataLibData> listToUpdateOrInsert = new ArrayList(newList);
listToUpdateOrInsert.removeAll(oldList);
List<TestDataLibData> listToUpdateOrInsertToIterate = new ArrayList(listToUpdateOrInsert);
for (TestDataLibData objectDifference : listToUpdateOrInsertToIterate) {
for (TestDataLibData objectInDatabase : oldList) {
if (objectDifference.hasSameKey(objectInDatabase)) {
ans = this.update(objectDifference);
finalAnswer = AnswerUtil.agregateAnswer(finalAnswer, (Answer) ans);
listToUpdateOrInsert.remove(objectDifference);
}
}
}
/**
* Delete all objects database Objects that do not exist from newList
*/
List<TestDataLibData> listToDelete = new ArrayList(oldList);
listToDelete.removeAll(newList);
List<TestDataLibData> listToDeleteToIterate = new ArrayList(listToDelete);
for (TestDataLibData tcsDifference : listToDeleteToIterate) {
for (TestDataLibData tcsInPage : newList) {
if (tcsDifference.hasSameKey(tcsInPage)) {
listToDelete.remove(tcsDifference);
}
}
}
if (!listToDelete.isEmpty()) {
ans = this.deleteList(listToDelete);
finalAnswer = AnswerUtil.agregateAnswer(finalAnswer, (Answer) ans);
}
// We insert only at the end (after deletion of all potencial enreg - linked with #1281)
if (!listToUpdateOrInsert.isEmpty()) {
ans = this.createList(listToUpdateOrInsert);
finalAnswer = AnswerUtil.agregateAnswer(finalAnswer, (Answer) ans);
}
return finalAnswer;
}
use of org.cerberus.exception.CerberusException in project cerberus-source by cerberustesting.
the class CampaignLabelService method compareListAndUpdateInsertDeleteElements.
@Override
public Answer compareListAndUpdateInsertDeleteElements(String campaign, List<CampaignLabel> newList) {
Answer ans = new Answer(null);
MessageEvent msg1 = new MessageEvent(MessageEventEnum.GENERIC_OK);
Answer finalAnswer = new Answer(msg1);
List<CampaignLabel> oldList = new ArrayList();
try {
oldList = this.convert(this.readByVarious(campaign));
} catch (CerberusException ex) {
LOG.error(ex);
}
/**
* Update and Create all objects database Objects from newList
*/
List<CampaignLabel> listToUpdateOrInsert = new ArrayList(newList);
listToUpdateOrInsert.removeAll(oldList);
List<CampaignLabel> listToUpdateOrInsertToIterate = new ArrayList(listToUpdateOrInsert);
for (CampaignLabel objectDifference : listToUpdateOrInsertToIterate) {
for (CampaignLabel objectInDatabase : oldList) {
if (objectDifference.hasSameKey(objectInDatabase)) {
ans = this.update(objectDifference);
finalAnswer = AnswerUtil.agregateAnswer(finalAnswer, (Answer) ans);
listToUpdateOrInsert.remove(objectDifference);
}
}
}
/**
* Delete all objects database Objects that do not exist from newList
*/
List<CampaignLabel> listToDelete = new ArrayList(oldList);
listToDelete.removeAll(newList);
List<CampaignLabel> listToDeleteToIterate = new ArrayList(listToDelete);
for (CampaignLabel tcsDifference : listToDeleteToIterate) {
for (CampaignLabel tcsInPage : newList) {
if (tcsDifference.hasSameKey(tcsInPage)) {
listToDelete.remove(tcsDifference);
}
}
}
if (!listToDelete.isEmpty()) {
ans = this.deleteList(listToDelete);
finalAnswer = AnswerUtil.agregateAnswer(finalAnswer, (Answer) ans);
}
// We insert only at the end (after deletion of all potencial enreg - linked with #1281)
if (!listToUpdateOrInsert.isEmpty()) {
ans = this.createList(listToUpdateOrInsert);
finalAnswer = AnswerUtil.agregateAnswer(finalAnswer, (Answer) ans);
}
return finalAnswer;
}
use of org.cerberus.exception.CerberusException in project cerberus-source by cerberustesting.
the class CountryEnvironmentParametersService method compareListAndUpdateInsertDeleteElements.
@Override
public Answer compareListAndUpdateInsertDeleteElements(String system, String application, List<CountryEnvironmentParameters> newList) {
Answer ans = new Answer(null);
MessageEvent msg1 = new MessageEvent(MessageEventEnum.GENERIC_OK);
Answer finalAnswer = new Answer(msg1);
List<CountryEnvironmentParameters> oldList = new ArrayList();
try {
oldList = this.convert(this.readByVarious(system, null, null, application));
} catch (CerberusException ex) {
LOG.error(ex);
}
/**
* Update and Create all objects database Objects from newList
*/
List<CountryEnvironmentParameters> listToUpdateOrInsert = new ArrayList(newList);
listToUpdateOrInsert.removeAll(oldList);
List<CountryEnvironmentParameters> listToUpdateOrInsertToIterate = new ArrayList(listToUpdateOrInsert);
for (CountryEnvironmentParameters objectDifference : listToUpdateOrInsertToIterate) {
for (CountryEnvironmentParameters objectInDatabase : oldList) {
if (objectDifference.hasSameKey(objectInDatabase)) {
ans = this.update(objectDifference);
finalAnswer = AnswerUtil.agregateAnswer(finalAnswer, (Answer) ans);
listToUpdateOrInsert.remove(objectDifference);
}
}
}
/**
* Delete all objects database Objects that do not exist from newList
*/
List<CountryEnvironmentParameters> listToDelete = new ArrayList(oldList);
listToDelete.removeAll(newList);
List<CountryEnvironmentParameters> listToDeleteToIterate = new ArrayList(listToDelete);
for (CountryEnvironmentParameters tcsDifference : listToDeleteToIterate) {
for (CountryEnvironmentParameters tcsInPage : newList) {
if (tcsDifference.hasSameKey(tcsInPage)) {
listToDelete.remove(tcsDifference);
}
}
}
if (!listToDelete.isEmpty()) {
ans = this.deleteList(listToDelete);
finalAnswer = AnswerUtil.agregateAnswer(finalAnswer, (Answer) ans);
}
// We insert only at the end (after deletion of all potencial enreg - linked with #1281)
if (!listToUpdateOrInsert.isEmpty()) {
ans = this.createList(listToUpdateOrInsert);
finalAnswer = AnswerUtil.agregateAnswer(finalAnswer, (Answer) ans);
}
return finalAnswer;
}
Aggregations