diff --git a/selenium/che-selenium-test/src/main/java/org/eclipse/che/selenium/core/client/KeycloakTestAuthServiceClient.java b/selenium/che-selenium-test/src/main/java/org/eclipse/che/selenium/core/client/KeycloakTestAuthServiceClient.java index ada4ce4842f..b975bf2b4a4 100644 --- a/selenium/che-selenium-test/src/main/java/org/eclipse/che/selenium/core/client/KeycloakTestAuthServiceClient.java +++ b/selenium/che-selenium-test/src/main/java/org/eclipse/che/selenium/core/client/KeycloakTestAuthServiceClient.java @@ -35,7 +35,6 @@ import org.eclipse.che.commons.lang.IoUtil; import org.eclipse.che.commons.lang.Pair; import org.eclipse.che.selenium.core.client.KeycloakToken.TokenDetails; -import org.eclipse.che.selenium.core.provider.TestApiEndpointUrlProvider; import org.eclipse.che.selenium.core.provider.TestOfflineToAccessTokenExchangeApiEndpointUrlProvider; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -58,7 +57,6 @@ public class KeycloakTestAuthServiceClient implements TestAuthServiceClient { private static final long MIN_TOKEN_LIFETIME_SEC = 30; - private final String apiEndpoint; private final DefaultHttpJsonRequestFactory requestFactory; private final TestOfflineToAccessTokenExchangeApiEndpointUrlProvider testOfflineToAccessTokenExchangeApiEndpointUrlProvider; @@ -70,15 +68,14 @@ public class KeycloakTestAuthServiceClient implements TestAuthServiceClient { @Inject public KeycloakTestAuthServiceClient( - TestApiEndpointUrlProvider cheApiEndpointProvider, DefaultHttpJsonRequestFactory requestFactory, TestOfflineToAccessTokenExchangeApiEndpointUrlProvider - testOfflineToAccessTokenExchangeApiEndpointUrlProvider) { - this.apiEndpoint = cheApiEndpointProvider.get().toString(); + testOfflineToAccessTokenExchangeApiEndpointUrlProvider, + TestKeycloakSettingsServiceClient testKeycloakSettingsServiceClient) { this.requestFactory = requestFactory; this.gson = new Gson(); this.tokens = new ConcurrentHashMap<>(); - this.keycloakSettings = getKeycloakConfiguration(); + this.keycloakSettings = testKeycloakSettingsServiceClient.read(); this.testOfflineToAccessTokenExchangeApiEndpointUrlProvider = testOfflineToAccessTokenExchangeApiEndpointUrlProvider; } @@ -236,18 +233,4 @@ private KeycloakToken requestToken(String grandType, List> param } return token; } - - private KeycloakSettings getKeycloakConfiguration() { - try { - return gson.fromJson( - requestFactory - .fromUrl(apiEndpoint + "keycloak/settings/") - .useGetMethod() - .request() - .asString(), - KeycloakSettings.class); - } catch (ApiException | IOException | JsonSyntaxException ex) { - throw new RuntimeException("Error during retrieving Che Keycloak configuration: ", ex); - } - } } diff --git a/selenium/che-selenium-test/src/main/java/org/eclipse/che/selenium/core/client/TestKeycloakSettingsServiceClient.java b/selenium/che-selenium-test/src/main/java/org/eclipse/che/selenium/core/client/TestKeycloakSettingsServiceClient.java new file mode 100644 index 00000000000..62f1fa301aa --- /dev/null +++ b/selenium/che-selenium-test/src/main/java/org/eclipse/che/selenium/core/client/TestKeycloakSettingsServiceClient.java @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2012-2018 Red Hat, Inc. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Red Hat, Inc. - initial API and implementation + */ +package org.eclipse.che.selenium.core.client; + +import static java.lang.String.format; + +import com.google.gson.Gson; +import com.google.gson.JsonSyntaxException; +import com.google.inject.Inject; +import java.io.IOException; +import org.eclipse.che.api.core.ApiException; +import org.eclipse.che.api.core.rest.DefaultHttpJsonRequestFactory; +import org.eclipse.che.selenium.core.provider.TestApiEndpointUrlProvider; + +/** @author Dmytro Nochevnov */ +public class TestKeycloakSettingsServiceClient { + + private final String keycloakSettingsServiceUrl; + private final DefaultHttpJsonRequestFactory requestFactory; + private final Gson gson; + + @Inject + public TestKeycloakSettingsServiceClient( + TestApiEndpointUrlProvider cheApiEndpointProvider, + DefaultHttpJsonRequestFactory requestFactory, + Gson gson) { + this.keycloakSettingsServiceUrl = format("%skeycloak/settings/", cheApiEndpointProvider.get()); + this.requestFactory = requestFactory; + this.gson = gson; + } + + public KeycloakSettings read() { + try { + return gson.fromJson( + requestFactory.fromUrl(keycloakSettingsServiceUrl).useGetMethod().request().asString(), + KeycloakSettings.class); + } catch (ApiException | IOException | JsonSyntaxException ex) { + throw new RuntimeException("Error during retrieving Che Keycloak configuration: ", ex); + } + } +} diff --git a/selenium/che-selenium-test/src/main/java/org/eclipse/che/selenium/pageobject/SeleniumWebDriverHelper.java b/selenium/che-selenium-test/src/main/java/org/eclipse/che/selenium/pageobject/SeleniumWebDriverHelper.java new file mode 100644 index 00000000000..8af22ab16b7 --- /dev/null +++ b/selenium/che-selenium-test/src/main/java/org/eclipse/che/selenium/pageobject/SeleniumWebDriverHelper.java @@ -0,0 +1,63 @@ +/* + * Copyright (c) 2012-2018 Red Hat, Inc. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Red Hat, Inc. - initial API and implementation + */ +package org.eclipse.che.selenium.pageobject; + +import static org.eclipse.che.selenium.core.constant.TestTimeoutsConstants.LOAD_PAGE_TIMEOUT_SEC; +import static org.openqa.selenium.support.ui.ExpectedConditions.visibilityOfElementLocated; + +import com.google.inject.Inject; +import com.google.inject.Singleton; +import org.eclipse.che.selenium.core.SeleniumWebDriver; +import org.openqa.selenium.By; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.support.ui.ExpectedCondition; +import org.openqa.selenium.support.ui.WebDriverWait; + +/** @author Igor Ohrimenko */ +@Singleton +public class SeleniumWebDriverHelper { + protected final SeleniumWebDriver seleniumWebDriver; + protected final WebDriverWait loadPageWait; + + @Inject + protected SeleniumWebDriverHelper(SeleniumWebDriver seleniumWebDriver) { + this.seleniumWebDriver = seleniumWebDriver; + this.loadPageWait = new WebDriverWait(seleniumWebDriver, LOAD_PAGE_TIMEOUT_SEC); + } + + public void setFieldValue(By fieldLocator, String value) { + waitAndGetElement(fieldLocator).clear(); + waitFieldValue(fieldLocator, ""); + waitAndGetElement(fieldLocator).sendKeys(value); + waitFieldValue(fieldLocator, value); + } + + public void waitElementIsVisible(By elementLocator) { + loadPageWait.until(visibilityOfElementLocated(elementLocator)); + } + + public String getFieldValue(By fieldLocator) { + return waitAndGetElement(fieldLocator).getAttribute("value"); + } + + public WebElement waitAndGetElement(By locator) { + return loadPageWait.until(visibilityOfElementLocated(locator)); + } + + public void waitFieldValue(By fieldLocator, String expectedValue) { + loadPageWait.until( + (ExpectedCondition) driver -> getFieldValue(fieldLocator).equals(expectedValue)); + } + + public void waitAndClickOnElement(By elementLocator) { + loadPageWait.until(visibilityOfElementLocated(elementLocator)).click(); + } +} diff --git a/selenium/che-selenium-test/src/main/java/org/eclipse/che/selenium/pageobject/dashboard/CheMultiuserAdminDashboard.java b/selenium/che-selenium-test/src/main/java/org/eclipse/che/selenium/pageobject/dashboard/CheMultiuserAdminDashboard.java index ce3aaca288c..1ec17dc5120 100644 --- a/selenium/che-selenium-test/src/main/java/org/eclipse/che/selenium/pageobject/dashboard/CheMultiuserAdminDashboard.java +++ b/selenium/che-selenium-test/src/main/java/org/eclipse/che/selenium/pageobject/dashboard/CheMultiuserAdminDashboard.java @@ -18,10 +18,11 @@ import com.google.inject.Inject; import com.google.inject.Singleton; +import com.google.inject.name.Named; import org.eclipse.che.selenium.core.SeleniumWebDriver; +import org.eclipse.che.selenium.core.client.TestKeycloakSettingsServiceClient; import org.eclipse.che.selenium.core.entrance.Entrance; import org.eclipse.che.selenium.core.provider.TestDashboardUrlProvider; -import org.eclipse.che.selenium.core.provider.TestIdeUrlProvider; import org.eclipse.che.selenium.core.user.TestUser; import org.eclipse.che.selenium.pageobject.TestWebElementRenderChecker; import org.eclipse.che.selenium.pageobject.site.LoginPage; @@ -43,19 +44,21 @@ public class CheMultiuserAdminDashboard extends Dashboard { public CheMultiuserAdminDashboard( SeleniumWebDriver seleniumWebDriver, TestUser defaultUser, - TestIdeUrlProvider testIdeUrlProvider, TestDashboardUrlProvider testDashboardUrlProvider, Entrance entrance, LoginPage loginPage, - TestWebElementRenderChecker testWebElementRenderChecker) { + TestWebElementRenderChecker testWebElementRenderChecker, + TestKeycloakSettingsServiceClient testKeycloakSettingsServiceClient, + @Named("che.multiuser") boolean isMultiuser) { super( seleniumWebDriver, defaultUser, - testIdeUrlProvider, testDashboardUrlProvider, entrance, loginPage, - testWebElementRenderChecker); + testWebElementRenderChecker, + testKeycloakSettingsServiceClient, + isMultiuser); PageFactory.initElements(seleniumWebDriver, this); } diff --git a/selenium/che-selenium-test/src/main/java/org/eclipse/che/selenium/pageobject/dashboard/Dashboard.java b/selenium/che-selenium-test/src/main/java/org/eclipse/che/selenium/pageobject/dashboard/Dashboard.java index 4603caed009..2b64e39adfb 100644 --- a/selenium/che-selenium-test/src/main/java/org/eclipse/che/selenium/pageobject/dashboard/Dashboard.java +++ b/selenium/che-selenium-test/src/main/java/org/eclipse/che/selenium/pageobject/dashboard/Dashboard.java @@ -23,13 +23,13 @@ import com.google.inject.Inject; import com.google.inject.Singleton; -import java.util.Arrays; +import com.google.inject.name.Named; import java.util.List; import javax.annotation.PreDestroy; import org.eclipse.che.selenium.core.SeleniumWebDriver; +import org.eclipse.che.selenium.core.client.TestKeycloakSettingsServiceClient; import org.eclipse.che.selenium.core.entrance.Entrance; import org.eclipse.che.selenium.core.provider.TestDashboardUrlProvider; -import org.eclipse.che.selenium.core.provider.TestIdeUrlProvider; import org.eclipse.che.selenium.core.user.TestUser; import org.eclipse.che.selenium.core.utils.WaitUtils; import org.eclipse.che.selenium.pageobject.TestWebElementRenderChecker; @@ -46,28 +46,31 @@ public class Dashboard { protected final SeleniumWebDriver seleniumWebDriver; protected final TestUser defaultUser; - private final TestIdeUrlProvider testIdeUrlProvider; private final TestDashboardUrlProvider testDashboardUrlProvider; private final Entrance entrance; private final LoginPage loginPage; private final TestWebElementRenderChecker testWebElementRenderChecker; + private final TestKeycloakSettingsServiceClient testKeycloakSettingsServiceClient; + private final boolean isMultiuser; @Inject public Dashboard( SeleniumWebDriver seleniumWebDriver, TestUser defaultUser, - TestIdeUrlProvider testIdeUrlProvider, TestDashboardUrlProvider testDashboardUrlProvider, Entrance entrance, LoginPage loginPage, - TestWebElementRenderChecker testWebElementRenderChecker) { + TestWebElementRenderChecker testWebElementRenderChecker, + TestKeycloakSettingsServiceClient testKeycloakSettingsServiceClient, + @Named("che.multiuser") boolean isMultiuser) { this.seleniumWebDriver = seleniumWebDriver; this.defaultUser = defaultUser; - this.testIdeUrlProvider = testIdeUrlProvider; this.testDashboardUrlProvider = testDashboardUrlProvider; this.entrance = entrance; this.loginPage = loginPage; this.testWebElementRenderChecker = testWebElementRenderChecker; + this.testKeycloakSettingsServiceClient = testKeycloakSettingsServiceClient; + this.isMultiuser = isMultiuser; PageFactory.initElements(seleniumWebDriver, this); } @@ -80,6 +83,7 @@ public enum MenuItem { ORGANIZATIONS("Organizations"), SETTINGS("Settings"), CREATE_TEAM("Create Team"); + private final String title; MenuItem(String title) { @@ -244,13 +248,17 @@ public void open(String userName, String userPassword) { } public void logout() { - String apiEndpoint = testDashboardUrlProvider.get().toString(); - List api = Arrays.asList(apiEndpoint.split(":")); - String logoutApiEndpoint = api.get(0) + ":" + api.get(1); - String logoutURL = logoutApiEndpoint + ":5050/auth/realms/che/protocol/openid-connect/logout"; - String redirectURL = logoutApiEndpoint + ":8080/dashboard/#/workspaces"; + if (!isMultiuser) { + return; + } + + String logoutUrl = + format( + "%s?redirect_uri=%s#/workspaces", + testKeycloakSettingsServiceClient.read().getKeycloakLogoutEndpoint(), + testDashboardUrlProvider.get()); - seleniumWebDriver.navigate().to(logoutURL + "?redirect_uri=" + redirectURL); + seleniumWebDriver.navigate().to(logoutUrl); } /** diff --git a/selenium/che-selenium-test/src/main/java/org/eclipse/che/selenium/pageobject/dashboard/ProjectSourcePage.java b/selenium/che-selenium-test/src/main/java/org/eclipse/che/selenium/pageobject/dashboard/ProjectSourcePage.java index d28108336a6..fe2ae4b71bb 100644 --- a/selenium/che-selenium-test/src/main/java/org/eclipse/che/selenium/pageobject/dashboard/ProjectSourcePage.java +++ b/selenium/che-selenium-test/src/main/java/org/eclipse/che/selenium/pageobject/dashboard/ProjectSourcePage.java @@ -26,7 +26,6 @@ import org.eclipse.che.selenium.core.action.ActionsFactory; import org.openqa.selenium.By; import org.openqa.selenium.TimeoutException; -import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.support.FindBy; import org.openqa.selenium.support.PageFactory; @@ -267,14 +266,19 @@ public void clickOnConnectGithubAccountButton() { public boolean isGithubProjectsListDisplayed() { try { - return new WebDriverWait(seleniumWebDriver, LOAD_PAGE_TIMEOUT_SEC) - .until(visibilityOfElementLocated(By.xpath(Locators.GITHUB_PROJECTS_LIST))) - .isDisplayed(); + waitGithubProjectList(); + return true; } catch (TimeoutException ex) { return false; } } + public void waitGithubProjectList() { + new WebDriverWait(seleniumWebDriver, LOAD_PAGE_TIMEOUT_SEC) + .until(visibilityOfElementLocated(By.xpath(Locators.GITHUB_PROJECTS_LIST))) + .isDisplayed(); + } + public void selectProjectFromList(String projectName) { WebElement project = seleniumWebDriver.findElement( @@ -287,14 +291,9 @@ public void selectProjectFromList(String projectName) { public void waitAuthorizationPageOpened() { new WebDriverWait(seleniumWebDriver, ELEMENT_TIMEOUT_SEC) .until( - new ExpectedCondition() { - @Override - public Boolean apply(WebDriver elem) { - return loginField.isDisplayed() - && passField.isDisplayed() - && signInBtn.isDisplayed(); - } - }); + (ExpectedCondition) + elem -> + loginField.isDisplayed() && passField.isDisplayed() && signInBtn.isDisplayed()); } /** diff --git a/selenium/che-selenium-test/src/main/java/org/eclipse/che/selenium/pageobject/dashboard/account/Account.java b/selenium/che-selenium-test/src/main/java/org/eclipse/che/selenium/pageobject/dashboard/account/Account.java index 0b4ffe56a8a..bd79a259763 100644 --- a/selenium/che-selenium-test/src/main/java/org/eclipse/che/selenium/pageobject/dashboard/account/Account.java +++ b/selenium/che-selenium-test/src/main/java/org/eclipse/che/selenium/pageobject/dashboard/account/Account.java @@ -10,6 +10,7 @@ */ package org.eclipse.che.selenium.pageobject.dashboard.account; +/** @author Igor Ohrimenko */ public class Account { private String login; private String email; diff --git a/selenium/che-selenium-test/src/main/java/org/eclipse/che/selenium/pageobject/dashboard/account/DashboardAccount.java b/selenium/che-selenium-test/src/main/java/org/eclipse/che/selenium/pageobject/dashboard/account/DashboardAccount.java index 1144e94509e..dcab5c5c6a3 100644 --- a/selenium/che-selenium-test/src/main/java/org/eclipse/che/selenium/pageobject/dashboard/account/DashboardAccount.java +++ b/selenium/che-selenium-test/src/main/java/org/eclipse/che/selenium/pageobject/dashboard/account/DashboardAccount.java @@ -11,7 +11,6 @@ package org.eclipse.che.selenium.pageobject.dashboard.account; import static java.util.Arrays.asList; -import static org.eclipse.che.selenium.core.constant.TestTimeoutsConstants.LOAD_PAGE_TIMEOUT_SEC; import static org.eclipse.che.selenium.pageobject.dashboard.account.DashboardAccount.Locators.EDIT_BUTTON; import static org.eclipse.che.selenium.pageobject.dashboard.account.DashboardAccount.Locators.EMAIL_FIELD; import static org.eclipse.che.selenium.pageobject.dashboard.account.DashboardAccount.Locators.FIRST_NAME_FIELD; @@ -20,31 +19,25 @@ import com.google.inject.Inject; import com.google.inject.Singleton; -import org.eclipse.che.selenium.core.SeleniumWebDriver; import org.eclipse.che.selenium.core.user.CheSecondTestUser; +import org.eclipse.che.selenium.pageobject.SeleniumWebDriverHelper; import org.openqa.selenium.By; -import org.openqa.selenium.support.ui.WebDriverWait; +/** @author Igor Ohrimenko */ @Singleton public class DashboardAccount { - private final SeleniumWebDriver seleniumWebDriver; private final CheSecondTestUser cheSecondTestUser; - private final WebDriverWait loadPageWait; - private final SeleniumWebDriverUtils seleniumWebDriverUtils; + private final SeleniumWebDriverHelper seleniumWebDriverHelper; @Inject public DashboardAccount( - SeleniumWebDriver seleniumWebDriver, - CheSecondTestUser cheSecondTestUser, - SeleniumWebDriverUtils seleniumWebDriverUtils) { - this.seleniumWebDriver = seleniumWebDriver; + CheSecondTestUser cheSecondTestUser, SeleniumWebDriverHelper seleniumWebDriverHelper) { this.cheSecondTestUser = cheSecondTestUser; - this.seleniumWebDriverUtils = seleniumWebDriverUtils; - this.loadPageWait = new WebDriverWait(seleniumWebDriver, LOAD_PAGE_TIMEOUT_SEC); + this.seleniumWebDriverHelper = seleniumWebDriverHelper; } - protected interface Locators { + interface Locators { String EMAIL_FIELD = "//input[@name='email']"; String LOGIN_FIELD = "//input[@name='login_name']"; String FIRST_NAME_FIELD = "//input[@name='first_name']"; @@ -76,31 +69,31 @@ public Account getCurrentFieldsValue() { } public String getEmailFieldValue() { - return seleniumWebDriverUtils.getFieldValue(By.xpath(EMAIL_FIELD)); + return seleniumWebDriverHelper.getFieldValue(By.xpath(EMAIL_FIELD)); } public String getLoginFieldValue() { - return seleniumWebDriverUtils.getFieldValue(By.xpath(LOGIN_FIELD)); + return seleniumWebDriverHelper.getFieldValue(By.xpath(LOGIN_FIELD)); } public String getFirstNameFieldValue() { - return seleniumWebDriverUtils.getFieldValue(By.xpath(FIRST_NAME_FIELD)); + return seleniumWebDriverHelper.getFieldValue(By.xpath(FIRST_NAME_FIELD)); } public String getLastNameFieldValue() { - return seleniumWebDriverUtils.getFieldValue(By.xpath(LAST_NAME_FIELD)); + return seleniumWebDriverHelper.getFieldValue(By.xpath(LAST_NAME_FIELD)); } public String getTitle() { - return seleniumWebDriverUtils.waitAndGetElement(By.id(Locators.TITLE_ID)).getText(); + return seleniumWebDriverHelper.waitAndGetElement(By.id(Locators.TITLE_ID)).getText(); } public void clickOnEditButton() { - seleniumWebDriverUtils.waitAndClickOnElement(By.xpath(EDIT_BUTTON)); + seleniumWebDriverHelper.waitAndClickOnElement(By.xpath(EDIT_BUTTON)); } public void waitPageIsLoaded() { asList(EMAIL_FIELD, LOGIN_FIELD, FIRST_NAME_FIELD, LAST_NAME_FIELD, EDIT_BUTTON) - .forEach(locator -> seleniumWebDriverUtils.waitElementIsVisible(By.xpath(locator))); + .forEach(locator -> seleniumWebDriverHelper.waitElementIsVisible(By.xpath(locator))); } } diff --git a/selenium/che-selenium-test/src/main/java/org/eclipse/che/selenium/pageobject/dashboard/account/KeycloakAccountPage.java b/selenium/che-selenium-test/src/main/java/org/eclipse/che/selenium/pageobject/dashboard/account/KeycloakAccountPage.java index 19d5e7035a8..73ab9d5e2a7 100644 --- a/selenium/che-selenium-test/src/main/java/org/eclipse/che/selenium/pageobject/dashboard/account/KeycloakAccountPage.java +++ b/selenium/che-selenium-test/src/main/java/org/eclipse/che/selenium/pageobject/dashboard/account/KeycloakAccountPage.java @@ -24,29 +24,29 @@ import com.google.inject.Inject; import com.google.inject.Singleton; import org.eclipse.che.selenium.core.SeleniumWebDriver; +import org.eclipse.che.selenium.pageobject.SeleniumWebDriverHelper; import org.openqa.selenium.By; import org.openqa.selenium.support.ui.ExpectedCondition; import org.openqa.selenium.support.ui.WebDriverWait; +/** @author Igor Ohrimenko */ @Singleton public class KeycloakAccountPage { - private SeleniumWebDriver seleniumWebDriver; - private SeleniumWebDriverUtils seleniumWebDriverUtils; - private KeycloakHeaderButtons keycloakHeaderButtons; - private WebDriverWait loadPageWait; + private final SeleniumWebDriverHelper seleniumWebDriverHelper; + private final KeycloakHeaderButtons keycloakHeaderButtons; + private final WebDriverWait loadPageWait; @Inject protected KeycloakAccountPage( SeleniumWebDriver seleniumWebDriver, - SeleniumWebDriverUtils seleniumWebDriverUtils, + SeleniumWebDriverHelper seleniumWebDriverHelper, KeycloakHeaderButtons keycloakHeaderButtons) { - this.seleniumWebDriver = seleniumWebDriver; - this.seleniumWebDriverUtils = seleniumWebDriverUtils; + this.seleniumWebDriverHelper = seleniumWebDriverHelper; this.keycloakHeaderButtons = keycloakHeaderButtons; this.loadPageWait = new WebDriverWait(seleniumWebDriver, LOAD_PAGE_TIMEOUT_SEC); } - protected interface AccountPageLocators { + interface AccountPageLocators { String USERNAME_FIELD_ID = "username"; String EMAIL_FIELD_ID = "email"; String FIRST_NAME_FIELD_ID = "firstName"; @@ -60,7 +60,7 @@ protected interface AccountPageLocators { } public void waitAccountPageIsLoaded() { - keycloakHeaderButtons.waitAllHeaderButtonsIsVisible(); + keycloakHeaderButtons.waitAllHeaderButtonsAreVisible(); waitAllBodyFieldsAndButtonsIsVisible(); } @@ -70,57 +70,57 @@ public Account getAllFieldsValue() { } public String getUserNameValue() { - return seleniumWebDriverUtils.getFieldValue(By.id(USERNAME_FIELD_ID)); + return seleniumWebDriverHelper.getFieldValue(By.id(USERNAME_FIELD_ID)); } public String getEmailValue() { - return seleniumWebDriverUtils.getFieldValue(By.id(EMAIL_FIELD_ID)); + return seleniumWebDriverHelper.getFieldValue(By.id(EMAIL_FIELD_ID)); } public String getFirstNameValue() { - return seleniumWebDriverUtils.getFieldValue(By.id(FIRST_NAME_FIELD_ID)); + return seleniumWebDriverHelper.getFieldValue(By.id(FIRST_NAME_FIELD_ID)); } public String getLastNameValue() { - return seleniumWebDriverUtils.getFieldValue(By.id(LAST_NAME_FIELD_ID)); + return seleniumWebDriverHelper.getFieldValue(By.id(LAST_NAME_FIELD_ID)); } public void setUserNameValue(String value) { - seleniumWebDriverUtils.setFieldValue(By.id(USERNAME_FIELD_ID), value); + seleniumWebDriverHelper.setFieldValue(By.id(USERNAME_FIELD_ID), value); } public void setEmailValue(String value) { - seleniumWebDriverUtils.setFieldValue(By.id(EMAIL_FIELD_ID), value); + seleniumWebDriverHelper.setFieldValue(By.id(EMAIL_FIELD_ID), value); } public void setFirstNameValue(String value) { - seleniumWebDriverUtils.setFieldValue(By.id(FIRST_NAME_FIELD_ID), value); + seleniumWebDriverHelper.setFieldValue(By.id(FIRST_NAME_FIELD_ID), value); } public void setLastNameValue(String value) { - seleniumWebDriverUtils.setFieldValue(By.id(LAST_NAME_FIELD_ID), value); + seleniumWebDriverHelper.setFieldValue(By.id(LAST_NAME_FIELD_ID), value); } public boolean usernameFieldIsDisabled() { - return seleniumWebDriverUtils + return seleniumWebDriverHelper .waitAndGetElement(By.id(USERNAME_FIELD_ID)) .getAttribute("disabled") .equals("true"); } public void clickOnSaveButton() { - seleniumWebDriverUtils.waitAndClickOnElement(By.xpath(SAVE_BUTTON)); + seleniumWebDriverHelper.waitAndClickOnElement(By.xpath(SAVE_BUTTON)); } public void clickOnCancelButton() { - seleniumWebDriverUtils.waitAndClickOnElement(By.xpath(CANCEL_BUTTON)); + seleniumWebDriverHelper.waitAndClickOnElement(By.xpath(CANCEL_BUTTON)); } public void waitTextInErrorAlert(String expectedText) { loadPageWait.until( (ExpectedCondition) driver -> - seleniumWebDriverUtils + seleniumWebDriverHelper .waitAndGetElement(By.xpath(ERROR_ALERT)) .getText() .equals(expectedText)); @@ -130,7 +130,7 @@ public void waitTextInSuccessAlert(String expectedText) { loadPageWait.until( (ExpectedCondition) driver -> - seleniumWebDriverUtils + seleniumWebDriverHelper .waitAndGetElement(By.xpath(SUCCESS_ALERT)) .getText() .equals(expectedText)); @@ -144,6 +144,6 @@ private void waitAllBodyFieldsAndButtonsIsVisible() { By.id(EMAIL_FIELD_ID), By.id(FIRST_NAME_FIELD_ID), By.id(LAST_NAME_FIELD_ID)) - .forEach(locator -> seleniumWebDriverUtils.waitElementIsVisible(locator)); + .forEach(locator -> seleniumWebDriverHelper.waitElementIsVisible(locator)); } } diff --git a/selenium/che-selenium-test/src/main/java/org/eclipse/che/selenium/pageobject/dashboard/account/KeycloakFederatedIdentitiesPage.java b/selenium/che-selenium-test/src/main/java/org/eclipse/che/selenium/pageobject/dashboard/account/KeycloakFederatedIdentitiesPage.java new file mode 100644 index 00000000000..8977349d3ac --- /dev/null +++ b/selenium/che-selenium-test/src/main/java/org/eclipse/che/selenium/pageobject/dashboard/account/KeycloakFederatedIdentitiesPage.java @@ -0,0 +1,111 @@ +/* + * Copyright (c) 2012-2018 Red Hat, Inc. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Red Hat, Inc. - initial API and implementation + */ +package org.eclipse.che.selenium.pageobject.dashboard.account; + +import static java.lang.String.format; +import static java.util.Arrays.asList; +import static org.eclipse.che.selenium.core.constant.TestTimeoutsConstants.LOAD_PAGE_TIMEOUT_SEC; +import static org.eclipse.che.selenium.pageobject.dashboard.account.KeycloakFederatedIdentitiesPage.Locators.GITHUB_INPUT_XPATH; +import static org.eclipse.che.selenium.pageobject.dashboard.account.KeycloakFederatedIdentitiesPage.Locators.GITHUB_REMOVE_BUTTON_ID; +import static org.eclipse.che.selenium.pageobject.dashboard.account.KeycloakFederatedIdentitiesPage.Locators.TITLE_XPATH; +import static org.eclipse.che.selenium.pageobject.dashboard.account.KeycloakPasswordPage.PasswordLocators.SUCCESS_ALERT; +import static org.openqa.selenium.By.xpath; + +import com.google.inject.Inject; +import com.google.inject.Singleton; +import javax.ws.rs.NotSupportedException; +import org.eclipse.che.selenium.core.SeleniumWebDriver; +import org.eclipse.che.selenium.core.client.TestKeycloakSettingsServiceClient; +import org.eclipse.che.selenium.pageobject.SeleniumWebDriverHelper; +import org.openqa.selenium.By; +import org.openqa.selenium.support.ui.ExpectedCondition; +import org.openqa.selenium.support.ui.WebDriverWait; + +/** @author Dmytro Nochevnov */ +@Singleton +public class KeycloakFederatedIdentitiesPage { + + private static final String IDENTITY_PROVIDER_REMOVED_SUCCESSFULLY_MESSAGE = + "Identity provider removed successfully."; + + private static final NotSupportedException NOT_SUPPORTED_EXCEPTION = + new NotSupportedException( + "Keycloak Federated Identities page can be used in Multi User Eclipse Che only."); + + private final WebDriverWait loadPageWait; + private final SeleniumWebDriver seleniumWebDriver; + private final SeleniumWebDriverHelper seleniumWebDriverHelper; + private final KeycloakHeaderButtons keycloakHeaderButtons; + private final TestKeycloakSettingsServiceClient testKeycloakSettingsServiceClient; + + @Inject + public KeycloakFederatedIdentitiesPage( + SeleniumWebDriver seleniumWebDriver, + SeleniumWebDriverHelper seleniumWebDriverHelper, + KeycloakHeaderButtons keycloakHeaderButtons, + TestKeycloakSettingsServiceClient testKeycloakSettingsServiceClient) { + this.seleniumWebDriver = seleniumWebDriver; + this.seleniumWebDriverHelper = seleniumWebDriverHelper; + this.keycloakHeaderButtons = keycloakHeaderButtons; + this.testKeycloakSettingsServiceClient = testKeycloakSettingsServiceClient; + this.loadPageWait = new WebDriverWait(seleniumWebDriver, LOAD_PAGE_TIMEOUT_SEC); + } + + interface Locators { + String GITHUB_REMOVE_BUTTON_ID = "remove-github"; + String TITLE_XPATH = "//div[@id='tab-content']//h2[text()='Federated Identities']"; + String GITHUB_INPUT_XPATH = "//form[//label/text()='GitHub']//input"; + } + + public void open() { + String identityPageUrl = + format( + "%s/identity", testKeycloakSettingsServiceClient.read().getKeycloakProfileEndpoint()); + + seleniumWebDriver.navigate().to(identityPageUrl); + waitPageIsLoaded(); + } + + public void ensureGithubIdentityIsAbsent() { + if (!getGitHubIdentityFieldValue().isEmpty()) { + removeGithubIdentity(); + } + } + + public String getGitHubIdentityFieldValue() { + return seleniumWebDriverHelper.getFieldValue(By.xpath(GITHUB_INPUT_XPATH)); + } + + public void removeGithubIdentity() { + seleniumWebDriverHelper.waitAndClickOnElement(By.id(GITHUB_REMOVE_BUTTON_ID)); + waitTextInSuccessAlert(IDENTITY_PROVIDER_REMOVED_SUCCESSFULLY_MESSAGE); + } + + private void waitPageIsLoaded() { + keycloakHeaderButtons.waitAllHeaderButtonsAreVisible(); + waitAllBodyFieldsAndButtonsIsVisible(); + } + + private void waitTextInSuccessAlert(String expectedText) { + loadPageWait.until( + (ExpectedCondition) + driver -> + seleniumWebDriverHelper + .waitAndGetElement(xpath(SUCCESS_ALERT)) + .getText() + .equals(expectedText)); + } + + private void waitAllBodyFieldsAndButtonsIsVisible() { + asList(xpath(TITLE_XPATH)) + .forEach(locator -> seleniumWebDriverHelper.waitElementIsVisible(locator)); + } +} diff --git a/selenium/che-selenium-test/src/main/java/org/eclipse/che/selenium/pageobject/dashboard/account/KeycloakHeaderButtons.java b/selenium/che-selenium-test/src/main/java/org/eclipse/che/selenium/pageobject/dashboard/account/KeycloakHeaderButtons.java index 111788782fc..159943130da 100644 --- a/selenium/che-selenium-test/src/main/java/org/eclipse/che/selenium/pageobject/dashboard/account/KeycloakHeaderButtons.java +++ b/selenium/che-selenium-test/src/main/java/org/eclipse/che/selenium/pageobject/dashboard/account/KeycloakHeaderButtons.java @@ -10,67 +10,88 @@ */ package org.eclipse.che.selenium.pageobject.dashboard.account; -import static org.eclipse.che.selenium.pageobject.dashboard.account.KeycloakHeaderButtons.ButtonsLocators.ACCOUNT_BUTTON; -import static org.eclipse.che.selenium.pageobject.dashboard.account.KeycloakHeaderButtons.ButtonsLocators.APPLICATIONS_BUTTON; -import static org.eclipse.che.selenium.pageobject.dashboard.account.KeycloakHeaderButtons.ButtonsLocators.AUTHENTICATOR_BUTTON; -import static org.eclipse.che.selenium.pageobject.dashboard.account.KeycloakHeaderButtons.ButtonsLocators.PASSWORD_BUTTON; -import static org.eclipse.che.selenium.pageobject.dashboard.account.KeycloakHeaderButtons.ButtonsLocators.SESSIONS_BUTTON; +import static org.openqa.selenium.By.xpath; import com.google.inject.Inject; import com.google.inject.Singleton; import java.util.Arrays; +import org.eclipse.che.selenium.pageobject.SeleniumWebDriverHelper; import org.openqa.selenium.By; +/** @author Igor Ohrimenko */ @Singleton public class KeycloakHeaderButtons { - private SeleniumWebDriverUtils seleniumWebDriverUtils; + private enum Button { + ACCOUNT("Account"), + PASSWORD("Password"), + AUTHENTICATOR("Authenticator"), + FEDERATED_IDENTITIES("Federated Identity"), + SESSIONS("Sessions"), + APPLICATIONS("Applications"); - @Inject - public KeycloakHeaderButtons(SeleniumWebDriverUtils seleniumWebDriverUtils) { - this.seleniumWebDriverUtils = seleniumWebDriverUtils; + private static final String BUTTON_XPATH_TEMPLATE = "//div[@id='tabs-menu']//a[text()='%s']"; + + private String text; + + Button(String text) { + this.text = text; + } + + private By getXpath() { + return xpath(String.format(BUTTON_XPATH_TEMPLATE, text)); + } } - protected interface ButtonsLocators { - String ACCOUNT_BUTTON = "//div[@id='tabs-menu']//a[text()='Account']"; - String PASSWORD_BUTTON = "//div[@id='tabs-menu']//a[text()='Password']"; - String AUTHENTICATOR_BUTTON = "//div[@id='tabs-menu']//a[text()='Authenticator']"; - String SESSIONS_BUTTON = "//div[@id='tabs-menu']//a[text()='Sessions']"; - String APPLICATIONS_BUTTON = "//div[@id='tabs-menu']//a[text()='Applications']"; + private SeleniumWebDriverHelper seleniumWebDriverHelper; + + @Inject + public KeycloakHeaderButtons(SeleniumWebDriverHelper seleniumWebDriverHelper) { + this.seleniumWebDriverHelper = seleniumWebDriverHelper; } /** click on the "Account" button in the header oh the page */ public void clickOnAccountButton() { - seleniumWebDriverUtils.waitAndClickOnElement(By.xpath(ACCOUNT_BUTTON)); + clickOnButton(Button.ACCOUNT); } /** click on the "Password" button in the header oh the page */ public void clickOnPasswordButton() { - seleniumWebDriverUtils.waitAndClickOnElement(By.xpath(PASSWORD_BUTTON)); + clickOnButton(Button.PASSWORD); } /** click on the "Authenticator" button in the header oh the page */ public void clickOnAuthenticatorButton() { - seleniumWebDriverUtils.waitAndClickOnElement(By.xpath(AUTHENTICATOR_BUTTON)); + clickOnButton(Button.AUTHENTICATOR); + } + + /** click on the "Federated Identity" button in the header oh the page */ + public void clickOnFederatedIdentitiesButton() { + clickOnButton(Button.FEDERATED_IDENTITIES); } /** click on the "Session" button in the header oh the page */ public void clickOnSessionsButton() { - seleniumWebDriverUtils.waitAndClickOnElement(By.xpath(SESSIONS_BUTTON)); + clickOnButton(Button.SESSIONS); } /** click on the "Application" button in the header oh the page */ public void clickOnApplicationsButton() { - seleniumWebDriverUtils.waitAndClickOnElement(By.xpath(APPLICATIONS_BUTTON)); + clickOnButton(Button.APPLICATIONS); + } + + private void clickOnButton(Button button) { + seleniumWebDriverHelper.waitAndClickOnElement(button.getXpath()); } /** wait until all buttons which placed in the header of the page will be visible */ - public void waitAllHeaderButtonsIsVisible() { + public void waitAllHeaderButtonsAreVisible() { Arrays.asList( - By.xpath(ACCOUNT_BUTTON), - By.xpath(PASSWORD_BUTTON), - By.xpath(AUTHENTICATOR_BUTTON), - By.xpath(SESSIONS_BUTTON), - By.xpath(APPLICATIONS_BUTTON)) - .forEach(locator -> seleniumWebDriverUtils.waitElementIsVisible(locator)); + Button.ACCOUNT.getXpath(), + Button.PASSWORD.getXpath(), + Button.AUTHENTICATOR.getXpath(), + Button.FEDERATED_IDENTITIES.getXpath(), + Button.SESSIONS.getXpath(), + Button.APPLICATIONS.getXpath()) + .forEach(locator -> seleniumWebDriverHelper.waitElementIsVisible(locator)); } } diff --git a/selenium/che-selenium-test/src/main/java/org/eclipse/che/selenium/pageobject/dashboard/account/KeycloakPasswordPage.java b/selenium/che-selenium-test/src/main/java/org/eclipse/che/selenium/pageobject/dashboard/account/KeycloakPasswordPage.java index 536fc2279ad..263561dfc6d 100644 --- a/selenium/che-selenium-test/src/main/java/org/eclipse/che/selenium/pageobject/dashboard/account/KeycloakPasswordPage.java +++ b/selenium/che-selenium-test/src/main/java/org/eclipse/che/selenium/pageobject/dashboard/account/KeycloakPasswordPage.java @@ -22,29 +22,29 @@ import com.google.inject.Inject; import com.google.inject.Singleton; import org.eclipse.che.selenium.core.SeleniumWebDriver; +import org.eclipse.che.selenium.pageobject.SeleniumWebDriverHelper; import org.openqa.selenium.By; import org.openqa.selenium.support.ui.ExpectedCondition; import org.openqa.selenium.support.ui.WebDriverWait; +/** @author Igor Ohrimenko */ @Singleton public class KeycloakPasswordPage { - private SeleniumWebDriver seleniumWebDriver; - private WebDriverWait loadPageWait; - private SeleniumWebDriverUtils seleniumWebDriverUtils; - private KeycloakHeaderButtons keycloakHeaderButtons; + private final WebDriverWait loadPageWait; + private final SeleniumWebDriverHelper seleniumWebDriverHelper; + private final KeycloakHeaderButtons keycloakHeaderButtons; @Inject public KeycloakPasswordPage( SeleniumWebDriver seleniumWebDriver, - SeleniumWebDriverUtils seleniumWebDriverUtils, + SeleniumWebDriverHelper seleniumWebDriverHelper, KeycloakHeaderButtons keycloakHeaderButtons) { - this.seleniumWebDriver = seleniumWebDriver; - this.seleniumWebDriverUtils = seleniumWebDriverUtils; + this.seleniumWebDriverHelper = seleniumWebDriverHelper; this.keycloakHeaderButtons = keycloakHeaderButtons; this.loadPageWait = new WebDriverWait(seleniumWebDriver, LOAD_PAGE_TIMEOUT_SEC); } - protected interface PasswordLocators { + interface PasswordLocators { String PASSWORD_FIELD_ID = "password"; String NEW_PASSWORD_FIELD_ID = "password-new"; String NEW_PASSWORD_CONFIRMATION_ID = "password-confirm"; @@ -56,31 +56,31 @@ protected interface PasswordLocators { } public void waitPasswordPageIsLoaded() { - keycloakHeaderButtons.waitAllHeaderButtonsIsVisible(); + keycloakHeaderButtons.waitAllHeaderButtonsAreVisible(); waitAllBodyFieldsAndButtonsIsVisible(); } public void setPasswordFieldValue(String value) { - seleniumWebDriverUtils.setFieldValue(By.id(PASSWORD_FIELD_ID), value); + seleniumWebDriverHelper.setFieldValue(By.id(PASSWORD_FIELD_ID), value); } public void setNewPasswordFieldValue(String value) { - seleniumWebDriverUtils.setFieldValue(By.id(NEW_PASSWORD_FIELD_ID), value); + seleniumWebDriverHelper.setFieldValue(By.id(NEW_PASSWORD_FIELD_ID), value); } public void setNewPasswordConfirmationFieldValue(String value) { - seleniumWebDriverUtils.setFieldValue(By.id(NEW_PASSWORD_CONFIRMATION_ID), value); + seleniumWebDriverHelper.setFieldValue(By.id(NEW_PASSWORD_CONFIRMATION_ID), value); } public void clickOnSavePasswordButton() { - seleniumWebDriverUtils.waitAndClickOnElement(By.xpath(SAVE_BUTTON)); + seleniumWebDriverHelper.waitAndClickOnElement(By.xpath(SAVE_BUTTON)); } public void waitTextInErrorAlert(String expectedText) { loadPageWait.until( (ExpectedCondition) driver -> - seleniumWebDriverUtils + seleniumWebDriverHelper .waitAndGetElement(By.xpath(ERROR_ALERT)) .getText() .equals(expectedText)); @@ -90,7 +90,7 @@ public void waitTextInSuccessAlert(String expectedText) { loadPageWait.until( (ExpectedCondition) driver -> - seleniumWebDriverUtils + seleniumWebDriverHelper .waitAndGetElement(By.xpath(SUCCESS_ALERT)) .getText() .equals(expectedText)); @@ -102,6 +102,6 @@ private void waitAllBodyFieldsAndButtonsIsVisible() { By.id(NEW_PASSWORD_FIELD_ID), By.id(NEW_PASSWORD_CONFIRMATION_ID), By.xpath(SAVE_BUTTON)) - .forEach(locator -> seleniumWebDriverUtils.waitElementIsVisible(locator)); + .forEach(locator -> seleniumWebDriverHelper.waitElementIsVisible(locator)); } } diff --git a/selenium/che-selenium-test/src/test/java/org/eclipse/che/selenium/git/AuthorizeOnGithubFromDashboardTest.java b/selenium/che-selenium-test/src/test/java/org/eclipse/che/selenium/git/AuthorizeOnGithubFromDashboardTest.java new file mode 100644 index 00000000000..3ee86c329c6 --- /dev/null +++ b/selenium/che-selenium-test/src/test/java/org/eclipse/che/selenium/git/AuthorizeOnGithubFromDashboardTest.java @@ -0,0 +1,124 @@ +/* + * Copyright (c) 2012-2018 Red Hat, Inc. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Red Hat, Inc. - initial API and implementation + */ +package org.eclipse.che.selenium.git; + +import static org.eclipse.che.selenium.pageobject.dashboard.ProjectSourcePage.Sources.GITHUB; +import static org.testng.Assert.assertEquals; + +import com.google.inject.Inject; +import com.google.inject.name.Named; +import org.eclipse.che.selenium.core.SeleniumWebDriver; +import org.eclipse.che.selenium.core.TestGroup; +import org.eclipse.che.selenium.core.client.TestGitHubServiceClient; +import org.eclipse.che.selenium.core.client.TestWorkspaceServiceClient; +import org.eclipse.che.selenium.core.user.TestUser; +import org.eclipse.che.selenium.pageobject.ProjectExplorer; +import org.eclipse.che.selenium.pageobject.dashboard.Dashboard; +import org.eclipse.che.selenium.pageobject.dashboard.NewWorkspace; +import org.eclipse.che.selenium.pageobject.dashboard.ProjectSourcePage; +import org.eclipse.che.selenium.pageobject.dashboard.account.KeycloakFederatedIdentitiesPage; +import org.eclipse.che.selenium.pageobject.dashboard.workspaces.Workspaces; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.testng.annotations.AfterClass; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +/** @author Aleksandr Shmaraev */ +public class AuthorizeOnGithubFromDashboardTest { + private static final Logger LOG = + LoggerFactory.getLogger(AuthorizeOnGithubFromDashboardTest.class); + + @Inject + @Named("github.username") + private String gitHubUsername; + + @Inject + @Named("github.password") + private String gitHubPassword; + + @Inject + @Named("che.multiuser") + private boolean isMultiuser; + + @Inject private Dashboard dashboard; + @Inject private Workspaces workspaces; + @Inject private TestUser defaultTestUser; + @Inject private ProjectExplorer projectExplorer; + @Inject private NewWorkspace newWorkspace; + @Inject private ProjectSourcePage projectSourcePage; + @Inject private SeleniumWebDriver seleniumWebDriver; + @Inject private TestWorkspaceServiceClient workspaceServiceClient; + @Inject private TestGitHubServiceClient gitHubClientService; + @Inject private KeycloakFederatedIdentitiesPage keycloakFederatedIdentitiesPage; + + @BeforeClass(groups = TestGroup.MULTIUSER) + @AfterClass(groups = TestGroup.MULTIUSER) + private void removeGitHubIdentity() { + dashboard.open(); // to login + keycloakFederatedIdentitiesPage.open(); + keycloakFederatedIdentitiesPage.ensureGithubIdentityIsAbsent(); + assertEquals(keycloakFederatedIdentitiesPage.getGitHubIdentityFieldValue(), ""); + } + + @BeforeClass + private void revokeGithubOauthToken() { + try { + gitHubClientService.deleteAllGrants(gitHubUsername, gitHubPassword); + } catch (Exception e) { + LOG.warn("There was an error of revoking the github oauth token.", e); + } + } + + @Test + public void checkAuthorizationOnGithubWhenLoadProjectList() { + dashboard.open(); + + String ideWin = seleniumWebDriver.getWindowHandle(); + + dashboard.waitDashboardToolbarTitle(); + dashboard.selectWorkspacesItemOnDashboard(); + workspaces.clickOnAddWorkspaceBtn(); + newWorkspace.waitToolbar(); + + projectSourcePage.clickOnAddOrImportProjectButton(); + projectSourcePage.selectSourceTab(GITHUB); + projectSourcePage.clickOnConnectGithubAccountButton(); + + // login to github + seleniumWebDriver.switchToNoneCurrentWindow(ideWin); + projectSourcePage.waitAuthorizationPageOpened(); + projectSourcePage.typeLogin(gitHubUsername); + projectSourcePage.typePassword(gitHubPassword); + projectSourcePage.clickOnSignInButton(); + + // authorize on github.com + projectSourcePage.waitAuthorizeBtn(); + projectSourcePage.clickOnAuthorizeBtn(); + seleniumWebDriver.switchTo().window(ideWin); + + projectSourcePage.waitGithubProjectList(); + + // check that repeat of getting of github projects list doesn't require authorization + seleniumWebDriver.navigate().refresh(); + newWorkspace.waitToolbar(); + + projectSourcePage.clickOnAddOrImportProjectButton(); + projectSourcePage.selectSourceTab(GITHUB); + projectSourcePage.waitGithubProjectList(); + + // check GitHub identity is present in Keycloak account management page + if (isMultiuser) { + keycloakFederatedIdentitiesPage.open(); + assertEquals(keycloakFederatedIdentitiesPage.getGitHubIdentityFieldValue(), gitHubUsername); + } + } +} diff --git a/selenium/che-selenium-test/src/test/java/org/eclipse/che/selenium/git/AuthorizeOnGithubFromImportTest.java b/selenium/che-selenium-test/src/test/java/org/eclipse/che/selenium/git/AuthorizeOnGithubFromImportTest.java new file mode 100644 index 00000000000..2fd8fc99d75 --- /dev/null +++ b/selenium/che-selenium-test/src/test/java/org/eclipse/che/selenium/git/AuthorizeOnGithubFromImportTest.java @@ -0,0 +1,192 @@ +/* + * Copyright (c) 2012-2018 Red Hat, Inc. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Red Hat, Inc. - initial API and implementation + */ +package org.eclipse.che.selenium.git; + +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.fail; + +import com.google.inject.Inject; +import com.google.inject.name.Named; +import org.eclipse.che.selenium.core.SeleniumWebDriver; +import org.eclipse.che.selenium.core.TestGroup; +import org.eclipse.che.selenium.core.client.TestGitHubServiceClient; +import org.eclipse.che.selenium.core.client.TestUserPreferencesServiceClient; +import org.eclipse.che.selenium.core.constant.TestMenuCommandsConstants; +import org.eclipse.che.selenium.core.workspace.TestWorkspace; +import org.eclipse.che.selenium.pageobject.AskDialog; +import org.eclipse.che.selenium.pageobject.Events; +import org.eclipse.che.selenium.pageobject.GitHub; +import org.eclipse.che.selenium.pageobject.Ide; +import org.eclipse.che.selenium.pageobject.ImportProjectFromLocation; +import org.eclipse.che.selenium.pageobject.Loader; +import org.eclipse.che.selenium.pageobject.Menu; +import org.eclipse.che.selenium.pageobject.Preferences; +import org.eclipse.che.selenium.pageobject.ProjectExplorer; +import org.eclipse.che.selenium.pageobject.dashboard.Dashboard; +import org.eclipse.che.selenium.pageobject.dashboard.account.KeycloakFederatedIdentitiesPage; +import org.eclipse.che.selenium.pageobject.machineperspective.MachineTerminal; +import org.openqa.selenium.TimeoutException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.testng.annotations.AfterClass; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +/** @author Aleksandr Shmaraev */ +public class AuthorizeOnGithubFromImportTest { + private static final Logger LOG = LoggerFactory.getLogger(AuthorizeOnGithubFromImportTest.class); + private static final String GITHUB_COM = "github.com"; + + @Inject private TestWorkspace ws; + @Inject private Ide ide; + + @Inject + @Named("github.username") + private String gitHubUsername; + + @Inject + @Named("github.password") + private String gitHubPassword; + + @Inject + @Named("che.multiuser") + private boolean isMultiuser; + + @Inject private ProjectExplorer projectExplorer; + @Inject private MachineTerminal terminal; + @Inject private Menu menu; + @Inject private ImportProjectFromLocation importProject; + @Inject private Preferences preferences; + @Inject private SeleniumWebDriver seleniumWebDriver; + @Inject private AskDialog askDialog; + @Inject private GitHub gitHub; + @Inject private TestGitHubServiceClient gitHubClientService; + @Inject private Loader loader; + @Inject private Events events; + @Inject private TestUserPreferencesServiceClient testUserPreferencesServiceClient; + @Inject private Dashboard dashboard; + @Inject private KeycloakFederatedIdentitiesPage keycloakFederatedIdentitiesPage; + + @BeforeClass(groups = TestGroup.MULTIUSER) + @AfterClass(groups = TestGroup.MULTIUSER) + private void removeGitHubIdentity() { + dashboard.open(); // to login + keycloakFederatedIdentitiesPage.open(); + keycloakFederatedIdentitiesPage.ensureGithubIdentityIsAbsent(); + assertEquals(keycloakFederatedIdentitiesPage.getGitHubIdentityFieldValue(), ""); + } + + @BeforeClass + private void revokeGithubOauthToken() { + try { + gitHubClientService.deleteAllGrants(gitHubUsername, gitHubPassword); + } catch (Exception e) { + LOG.warn("There was an error of revoking the github oauth token.", e); + } + } + + @BeforeClass + private void deletePrivateSshKey() throws Exception { + ide.open(ws); + projectExplorer.waitProjectExplorer(); + terminal.waitTerminalTab(); + + openPreferencesVcsForm(); + + if (preferences.isSshKeyIsPresent(GITHUB_COM)) { + preferences.deleteSshKeyByHost(GITHUB_COM); + } + + preferences.clickOnCloseBtn(); + } + + @Test + public void checkAuthorizationOnGitHubWhenImportProject() throws Exception { + ide.open(ws); + String ideWin = seleniumWebDriver.getWindowHandle(); + + menu.runCommand( + TestMenuCommandsConstants.Workspace.WORKSPACE, + TestMenuCommandsConstants.Workspace.IMPORT_PROJECT); + importProject.waitMainForm(); + importProject.selectGitHubSourceItem(); + importProject.clickLoadRepoBtn(); + + // login to github + try { + askDialog.waitFormToOpen(25); + } catch (TimeoutException ex) { + importProject.closeWithIcon(); + events.clickEventLogBtn(); + events.waitExpectedMessage("Failed to authorize application on GitHub"); + fail("Known issue https://github.com/eclipse/che/issues/8288", ex); + } + + askDialog.clickOkBtn(); + askDialog.waitFormToClose(); + seleniumWebDriver.switchToNoneCurrentWindow(ideWin); + + gitHub.waitAuthorizationPageOpened(); + gitHub.typeLogin(gitHubUsername); + gitHub.typePass(gitHubPassword); + gitHub.clickOnSignInButton(); + + // authorize on github.com + gitHub.waitAuthorizeBtn(); + gitHub.clickOnAuthorizeBtn(); + seleniumWebDriver.switchTo().window(ideWin); + loader.waitOnClosed(); + + importProject.selectItemInAccountList( + gitHubClientService.getName(gitHubUsername, gitHubPassword)); + importProject.closeWithIcon(); + + // check load repo if an application is authorized + openPreferencesVcsForm(); + preferences.waitSshKeyIsPresent(GITHUB_COM); + preferences.deleteSshKeyByHost(GITHUB_COM); + preferences.clickOnCloseBtn(); + + menu.runCommand( + TestMenuCommandsConstants.Workspace.WORKSPACE, + TestMenuCommandsConstants.Workspace.IMPORT_PROJECT); + importProject.waitMainForm(); + importProject.selectGitHubSourceItem(); + importProject.clickLoadRepoBtn(); + importProject.selectItemInAccountList( + gitHubClientService.getName(gitHubUsername, gitHubPassword)); + importProject.selectProjectByName("AngularJS"); + + try { + importProject.clickImportBtn(); + } catch (TimeoutException ex) { + importProject.closeWithIcon(); + events.clickEventLogBtn(); + events.waitExpectedMessage("Can't store ssh key. Unable get private ssh key"); + fail("Known issue https://github.com/eclipse/che/issues/6765", ex); + } + + // check GitHub identity is present in Keycloak account management page + if (isMultiuser) { + keycloakFederatedIdentitiesPage.open(); + assertEquals(keycloakFederatedIdentitiesPage.getGitHubIdentityFieldValue(), gitHubUsername); + } + } + + private void openPreferencesVcsForm() { + menu.runCommand( + TestMenuCommandsConstants.Profile.PROFILE_MENU, + TestMenuCommandsConstants.Profile.PREFERENCES); + preferences.waitPreferencesForm(); + preferences.waitMenuInCollapsedDropdown(Preferences.DropDownSshKeysMenu.VCS); + preferences.selectDroppedMenuByName(Preferences.DropDownSshKeysMenu.VCS); + } +} diff --git a/selenium/che-selenium-test/src/test/java/org/eclipse/che/selenium/git/AuthorizeOnGithubFromPreferencesTest.java b/selenium/che-selenium-test/src/test/java/org/eclipse/che/selenium/git/AuthorizeOnGithubFromPreferencesTest.java new file mode 100644 index 00000000000..75c23d1306b --- /dev/null +++ b/selenium/che-selenium-test/src/test/java/org/eclipse/che/selenium/git/AuthorizeOnGithubFromPreferencesTest.java @@ -0,0 +1,158 @@ +/* + * Copyright (c) 2012-2018 Red Hat, Inc. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Red Hat, Inc. - initial API and implementation + */ +package org.eclipse.che.selenium.git; + +import static org.testng.Assert.assertEquals; + +import com.google.inject.Inject; +import com.google.inject.name.Named; +import org.eclipse.che.selenium.core.SeleniumWebDriver; +import org.eclipse.che.selenium.core.TestGroup; +import org.eclipse.che.selenium.core.client.TestGitHubServiceClient; +import org.eclipse.che.selenium.core.client.TestUserPreferencesServiceClient; +import org.eclipse.che.selenium.core.constant.TestMenuCommandsConstants; +import org.eclipse.che.selenium.core.workspace.TestWorkspace; +import org.eclipse.che.selenium.pageobject.AskDialog; +import org.eclipse.che.selenium.pageobject.Events; +import org.eclipse.che.selenium.pageobject.GitHub; +import org.eclipse.che.selenium.pageobject.Ide; +import org.eclipse.che.selenium.pageobject.ImportProjectFromLocation; +import org.eclipse.che.selenium.pageobject.Loader; +import org.eclipse.che.selenium.pageobject.Menu; +import org.eclipse.che.selenium.pageobject.Preferences; +import org.eclipse.che.selenium.pageobject.ProjectExplorer; +import org.eclipse.che.selenium.pageobject.dashboard.Dashboard; +import org.eclipse.che.selenium.pageobject.dashboard.account.KeycloakFederatedIdentitiesPage; +import org.eclipse.che.selenium.pageobject.machineperspective.MachineTerminal; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.testng.annotations.AfterClass; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +/** @author Aleksandr Shmaraev */ +public class AuthorizeOnGithubFromPreferencesTest { + private static final String GITHUB_COM = "github.com"; + private static final Logger LOG = + LoggerFactory.getLogger(AuthorizeOnGithubFromPreferencesTest.class); + + @Inject private TestWorkspace ws; + @Inject private Ide ide; + + @Inject + @Named("github.username") + private String gitHubUsername; + + @Inject + @Named("github.password") + private String gitHubPassword; + + @Inject + @Named("che.multiuser") + private boolean isMultiuser; + + @Inject private ProjectExplorer projectExplorer; + @Inject private MachineTerminal terminal; + @Inject private Menu menu; + @Inject private ImportProjectFromLocation importProject; + @Inject private Preferences preferences; + @Inject private SeleniumWebDriver seleniumWebDriver; + @Inject private AskDialog askDialog; + @Inject private GitHub gitHub; + @Inject private TestGitHubServiceClient gitHubClientService; + @Inject private Loader loader; + @Inject private Events events; + @Inject private TestUserPreferencesServiceClient testUserPreferencesServiceClient; + @Inject private Dashboard dashboard; + @Inject private KeycloakFederatedIdentitiesPage keycloakFederatedIdentitiesPage; + + @BeforeClass(groups = TestGroup.MULTIUSER) + @AfterClass(groups = TestGroup.MULTIUSER) + private void removeGitHubIdentity() { + dashboard.open(); // to login + keycloakFederatedIdentitiesPage.open(); + keycloakFederatedIdentitiesPage.ensureGithubIdentityIsAbsent(); + assertEquals(keycloakFederatedIdentitiesPage.getGitHubIdentityFieldValue(), ""); + } + + @BeforeClass + private void revokeGithubOauthToken() { + try { + gitHubClientService.deleteAllGrants(gitHubUsername, gitHubPassword); + } catch (Exception e) { + LOG.warn("There was an error of revoking the github oauth token.", e); + } + } + + @BeforeClass + private void deletePrivateSshKey() throws Exception { + ide.open(ws); + projectExplorer.waitProjectExplorer(); + terminal.waitTerminalTab(); + + // open Preferences Vcs Form + openPreferencesVcsForm(); + if (preferences.isSshKeyIsPresent(GITHUB_COM)) { + preferences.deleteSshKeyByHost(GITHUB_COM); + } + + preferences.clickOnCloseBtn(); + } + + @Test + public void checkAuthorizationOnGithubWhenUploadSshKey() throws Exception { + String ideWin = seleniumWebDriver.getWindowHandle(); + + // generate and upload github ssh key + ide.open(ws); + openPreferencesVcsForm(); + preferences.clickOnGenerateAndUploadToGitHub(); + + // login to github + askDialog.waitFormToOpen(25); + askDialog.clickOkBtn(); + askDialog.waitFormToClose(); + seleniumWebDriver.switchToNoneCurrentWindow(ideWin); + + gitHub.waitAuthorizationPageOpened(); + gitHub.typeLogin(gitHubUsername); + gitHub.typePass(gitHubPassword); + gitHub.clickOnSignInButton(); + + // authorize on github.com + gitHub.waitAuthorizeBtn(); + gitHub.clickOnAuthorizeBtn(); + seleniumWebDriver.switchTo().window(ideWin); + loader.waitOnClosed(); + preferences.waitSshKeyIsPresent(GITHUB_COM); + + // check that repeat of upload of ssh-key doesn't require authorization + preferences.deleteSshKeyByHost(GITHUB_COM); + preferences.clickOnGenerateAndUploadToGitHub(); + loader.waitOnClosed(); + preferences.waitSshKeyIsPresent(GITHUB_COM); + + // check GitHub identity is present in Keycloak account management page + if (isMultiuser) { + keycloakFederatedIdentitiesPage.open(); + assertEquals(keycloakFederatedIdentitiesPage.getGitHubIdentityFieldValue(), gitHubUsername); + } + } + + private void openPreferencesVcsForm() { + menu.runCommand( + TestMenuCommandsConstants.Profile.PROFILE_MENU, + TestMenuCommandsConstants.Profile.PREFERENCES); + preferences.waitPreferencesForm(); + preferences.waitMenuInCollapsedDropdown(Preferences.DropDownSshKeysMenu.VCS); + preferences.selectDroppedMenuByName(Preferences.DropDownSshKeysMenu.VCS); + } +} diff --git a/selenium/che-selenium-test/src/test/resources/suites/CheOneThreadTestsSuite.xml b/selenium/che-selenium-test/src/test/resources/suites/CheOneThreadTestsSuite.xml index cf193d9eaad..b17c6053396 100644 --- a/selenium/che-selenium-test/src/test/resources/suites/CheOneThreadTestsSuite.xml +++ b/selenium/che-selenium-test/src/test/resources/suites/CheOneThreadTestsSuite.xml @@ -22,7 +22,7 @@