@Test public void shouldReturnFailedIfTheWebCookiesDoesNotExists() { ConnectorManager connector = mock(ConnectorManager.class); VariableStoreConnector variables = mock(VariableStoreConnector.class); given(connector.getConnector(VariableStoreConnector.class)).willReturn(variables); WebSiteConnector webSiteConnector = createWebSiteConnectorMock(null); given(connector.getConnector(WebSiteConnector.class)).willReturn(webSiteConnector); setAction.execute(connector); verify(variables, never()).set(eq(VARIABLE_NAME), anyString()); }
@Override public ExecuteResult execute(ConnectorManager connector) { VariableStoreConnector storeConnector = connector.getConnector(VariableStoreConnector.class); WebServiceConnector webServiceConnector = connector.getConnector(WebServiceConnector.class); WebSiteConnector webSiteConnector = connector.getConnector(WebSiteConnector.class); try { String cookieValue = null; if (cookieType == CookieType.WEB) { WebDriver driver = webSiteConnector.getDriver(); WebDriver.Options manage = driver.manage(); Cookie cookie = manage.getCookieNamed(value); if (cookie != null) { cookieValue = cookie.getValue(); } } else if (cookieType == CookieType.REST) { Map<String, NewCookie> cookies = webServiceConnector.getCookies(); javax.ws.rs.core.Cookie cookie = cookies.get(value); if (cookie != null) { cookieValue = cookie.getValue(); } } else { LOGGER.warn(LoggerMarkers.LEARNER, "Could not set the variable '{}' to the cookie '{}' because the type '{}' is not supported!", name, value, cookieType); return getFailedOutput(); } if (cookieValue != null) { storeConnector.set(name, cookieValue); LOGGER.info(LoggerMarkers.LEARNER, "Set the variable '{}' to the value '{}' of the cookie '{}:{}' ", name, cookieValue, cookieType, value); return getSuccessOutput(); } else { LOGGER.info(LoggerMarkers.LEARNER, "Could not set the variable '{}' to the cookie '{}:{}' because the cookie was not found!", name, cookieType, value); return getFailedOutput(); } } catch (IllegalStateException | NoSuchElementException e) { LOGGER.warn(LoggerMarkers.LEARNER, "Could not set the variable '{}' to the cookie '{}' because of an error.", name, value, e); return getFailedOutput(); } }
SetVariableByCookieAction extends SetVariableAction { @Override public ExecuteResult execute(ConnectorManager connector) { VariableStoreConnector storeConnector = connector.getConnector(VariableStoreConnector.class); WebServiceConnector webServiceConnector = connector.getConnector(WebServiceConnector.class); WebSiteConnector webSiteConnector = connector.getConnector(WebSiteConnector.class); try { String cookieValue = null; if (cookieType == CookieType.WEB) { WebDriver driver = webSiteConnector.getDriver(); WebDriver.Options manage = driver.manage(); Cookie cookie = manage.getCookieNamed(value); if (cookie != null) { cookieValue = cookie.getValue(); } } else if (cookieType == CookieType.REST) { Map<String, NewCookie> cookies = webServiceConnector.getCookies(); javax.ws.rs.core.Cookie cookie = cookies.get(value); if (cookie != null) { cookieValue = cookie.getValue(); } } else { LOGGER.warn(LoggerMarkers.LEARNER, "Could not set the variable '{}' to the cookie '{}' because the type '{}' is not supported!", name, value, cookieType); return getFailedOutput(); } if (cookieValue != null) { storeConnector.set(name, cookieValue); LOGGER.info(LoggerMarkers.LEARNER, "Set the variable '{}' to the value '{}' of the cookie '{}:{}' ", name, cookieValue, cookieType, value); return getSuccessOutput(); } else { LOGGER.info(LoggerMarkers.LEARNER, "Could not set the variable '{}' to the cookie '{}:{}' because the cookie was not found!", name, cookieType, value); return getFailedOutput(); } } catch (IllegalStateException | NoSuchElementException e) { LOGGER.warn(LoggerMarkers.LEARNER, "Could not set the variable '{}' to the cookie '{}' because of an error.", name, value, e); return getFailedOutput(); } } }
SetVariableByCookieAction extends SetVariableAction { @Override public ExecuteResult execute(ConnectorManager connector) { VariableStoreConnector storeConnector = connector.getConnector(VariableStoreConnector.class); WebServiceConnector webServiceConnector = connector.getConnector(WebServiceConnector.class); WebSiteConnector webSiteConnector = connector.getConnector(WebSiteConnector.class); try { String cookieValue = null; if (cookieType == CookieType.WEB) { WebDriver driver = webSiteConnector.getDriver(); WebDriver.Options manage = driver.manage(); Cookie cookie = manage.getCookieNamed(value); if (cookie != null) { cookieValue = cookie.getValue(); } } else if (cookieType == CookieType.REST) { Map<String, NewCookie> cookies = webServiceConnector.getCookies(); javax.ws.rs.core.Cookie cookie = cookies.get(value); if (cookie != null) { cookieValue = cookie.getValue(); } } else { LOGGER.warn(LoggerMarkers.LEARNER, "Could not set the variable '{}' to the cookie '{}' because the type '{}' is not supported!", name, value, cookieType); return getFailedOutput(); } if (cookieValue != null) { storeConnector.set(name, cookieValue); LOGGER.info(LoggerMarkers.LEARNER, "Set the variable '{}' to the value '{}' of the cookie '{}:{}' ", name, cookieValue, cookieType, value); return getSuccessOutput(); } else { LOGGER.info(LoggerMarkers.LEARNER, "Could not set the variable '{}' to the cookie '{}:{}' because the cookie was not found!", name, cookieType, value); return getFailedOutput(); } } catch (IllegalStateException | NoSuchElementException e) { LOGGER.warn(LoggerMarkers.LEARNER, "Could not set the variable '{}' to the cookie '{}' because of an error.", name, value, e); return getFailedOutput(); } }  }
SetVariableByCookieAction extends SetVariableAction { @Override public ExecuteResult execute(ConnectorManager connector) { VariableStoreConnector storeConnector = connector.getConnector(VariableStoreConnector.class); WebServiceConnector webServiceConnector = connector.getConnector(WebServiceConnector.class); WebSiteConnector webSiteConnector = connector.getConnector(WebSiteConnector.class); try { String cookieValue = null; if (cookieType == CookieType.WEB) { WebDriver driver = webSiteConnector.getDriver(); WebDriver.Options manage = driver.manage(); Cookie cookie = manage.getCookieNamed(value); if (cookie != null) { cookieValue = cookie.getValue(); } } else if (cookieType == CookieType.REST) { Map<String, NewCookie> cookies = webServiceConnector.getCookies(); javax.ws.rs.core.Cookie cookie = cookies.get(value); if (cookie != null) { cookieValue = cookie.getValue(); } } else { LOGGER.warn(LoggerMarkers.LEARNER, "Could not set the variable '{}' to the cookie '{}' because the type '{}' is not supported!", name, value, cookieType); return getFailedOutput(); } if (cookieValue != null) { storeConnector.set(name, cookieValue); LOGGER.info(LoggerMarkers.LEARNER, "Set the variable '{}' to the value '{}' of the cookie '{}:{}' ", name, cookieValue, cookieType, value); return getSuccessOutput(); } else { LOGGER.info(LoggerMarkers.LEARNER, "Could not set the variable '{}' to the cookie '{}:{}' because the cookie was not found!", name, cookieType, value); return getFailedOutput(); } } catch (IllegalStateException | NoSuchElementException e) { LOGGER.warn(LoggerMarkers.LEARNER, "Could not set the variable '{}' to the cookie '{}' because of an error.", name, value, e); return getFailedOutput(); } }  @Override ExecuteResult execute(ConnectorManager connector); CookieType getCookieType(); void setCookieType(CookieType type); }
SetVariableByCookieAction extends SetVariableAction { @Override public ExecuteResult execute(ConnectorManager connector) { VariableStoreConnector storeConnector = connector.getConnector(VariableStoreConnector.class); WebServiceConnector webServiceConnector = connector.getConnector(WebServiceConnector.class); WebSiteConnector webSiteConnector = connector.getConnector(WebSiteConnector.class); try { String cookieValue = null; if (cookieType == CookieType.WEB) { WebDriver driver = webSiteConnector.getDriver(); WebDriver.Options manage = driver.manage(); Cookie cookie = manage.getCookieNamed(value); if (cookie != null) { cookieValue = cookie.getValue(); } } else if (cookieType == CookieType.REST) { Map<String, NewCookie> cookies = webServiceConnector.getCookies(); javax.ws.rs.core.Cookie cookie = cookies.get(value); if (cookie != null) { cookieValue = cookie.getValue(); } } else { LOGGER.warn(LoggerMarkers.LEARNER, "Could not set the variable '{}' to the cookie '{}' because the type '{}' is not supported!", name, value, cookieType); return getFailedOutput(); } if (cookieValue != null) { storeConnector.set(name, cookieValue); LOGGER.info(LoggerMarkers.LEARNER, "Set the variable '{}' to the value '{}' of the cookie '{}:{}' ", name, cookieValue, cookieType, value); return getSuccessOutput(); } else { LOGGER.info(LoggerMarkers.LEARNER, "Could not set the variable '{}' to the cookie '{}:{}' because the cookie was not found!", name, cookieType, value); return getFailedOutput(); } } catch (IllegalStateException | NoSuchElementException e) { LOGGER.warn(LoggerMarkers.LEARNER, "Could not set the variable '{}' to the cookie '{}' because of an error.", name, value, e); return getFailedOutput(); } }  @Override ExecuteResult execute(ConnectorManager connector); CookieType getCookieType(); void setCookieType(CookieType type);  }