Selenium: Create selenium tests to cover the authorization on GitHub (#8395)

* Create selenium tests to cover the authorization on GitHub
* Adding removal of GitHub identity from keycloak in selenium tests

Signed-off-by: Dmytro Nochevnov <dnochevnov@codenvy.com>
6.19.x
Aleksandr Shmaraiev 2018-01-26 11:39:00 +02:00 committed by Dmytro Nochevnov
parent 6187031a6e
commit d7ac6742e2
17 changed files with 845 additions and 137 deletions

View File

@ -35,7 +35,6 @@ import org.eclipse.che.api.core.rest.DefaultHttpJsonRequestFactory;
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 @@ public class KeycloakTestAuthServiceClient implements TestAuthServiceClient {
}
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);
}
}
}

View File

@ -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);
}
}
}

View File

@ -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<Boolean>) driver -> getFieldValue(fieldLocator).equals(expectedValue));
}
public void waitAndClickOnElement(By elementLocator) {
loadPageWait.until(visibilityOfElementLocated(elementLocator)).click();
}
}

View File

@ -18,10 +18,11 @@ import static org.openqa.selenium.support.ui.ExpectedConditions.visibilityOf;
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);
}

View File

@ -23,13 +23,13 @@ import static org.openqa.selenium.support.ui.ExpectedConditions.visibilityOfElem
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 class Dashboard {
ORGANIZATIONS("Organizations"),
SETTINGS("Settings"),
CREATE_TEAM("Create Team");
private final String title;
MenuItem(String title) {
@ -244,13 +248,17 @@ public class Dashboard {
}
public void logout() {
String apiEndpoint = testDashboardUrlProvider.get().toString();
List<String> 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;
}
seleniumWebDriver.navigate().to(logoutURL + "?redirect_uri=" + redirectURL);
String logoutUrl =
format(
"%s?redirect_uri=%s#/workspaces",
testKeycloakSettingsServiceClient.read().getKeycloakLogoutEndpoint(),
testDashboardUrlProvider.get());
seleniumWebDriver.navigate().to(logoutUrl);
}
/**

View File

@ -26,7 +26,6 @@ import org.eclipse.che.selenium.core.SeleniumWebDriver;
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 class ProjectSourcePage {
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 class ProjectSourcePage {
public void waitAuthorizationPageOpened() {
new WebDriverWait(seleniumWebDriver, ELEMENT_TIMEOUT_SEC)
.until(
new ExpectedCondition<Boolean>() {
@Override
public Boolean apply(WebDriver elem) {
return loginField.isDisplayed()
&& passField.isDisplayed()
&& signInBtn.isDisplayed();
}
});
(ExpectedCondition<Boolean>)
elem ->
loginField.isDisplayed() && passField.isDisplayed() && signInBtn.isDisplayed());
}
/**

View File

@ -10,6 +10,7 @@
*/
package org.eclipse.che.selenium.pageobject.dashboard.account;
/** @author Igor Ohrimenko */
public class Account {
private String login;
private String email;

View File

@ -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 static org.eclipse.che.selenium.pageobject.dashboard.account.DashboardAcc
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 class DashboardAccount {
}
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)));
}
}

View File

@ -24,29 +24,29 @@ import static org.eclipse.che.selenium.pageobject.dashboard.account.KeycloakAcco
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 @@ public class KeycloakAccountPage {
}
public void waitAccountPageIsLoaded() {
keycloakHeaderButtons.waitAllHeaderButtonsIsVisible();
keycloakHeaderButtons.waitAllHeaderButtonsAreVisible();
waitAllBodyFieldsAndButtonsIsVisible();
}
@ -70,57 +70,57 @@ public class KeycloakAccountPage {
}
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<Boolean>)
driver ->
seleniumWebDriverUtils
seleniumWebDriverHelper
.waitAndGetElement(By.xpath(ERROR_ALERT))
.getText()
.equals(expectedText));
@ -130,7 +130,7 @@ public class KeycloakAccountPage {
loadPageWait.until(
(ExpectedCondition<Boolean>)
driver ->
seleniumWebDriverUtils
seleniumWebDriverHelper
.waitAndGetElement(By.xpath(SUCCESS_ALERT))
.getText()
.equals(expectedText));
@ -144,6 +144,6 @@ public class KeycloakAccountPage {
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));
}
}

View File

@ -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<Boolean>)
driver ->
seleniumWebDriverHelper
.waitAndGetElement(xpath(SUCCESS_ALERT))
.getText()
.equals(expectedText));
}
private void waitAllBodyFieldsAndButtonsIsVisible() {
asList(xpath(TITLE_XPATH))
.forEach(locator -> seleniumWebDriverHelper.waitElementIsVisible(locator));
}
}

View File

@ -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));
}
}

View File

@ -22,29 +22,29 @@ import static org.eclipse.che.selenium.pageobject.dashboard.account.KeycloakPass
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 @@ public class KeycloakPasswordPage {
}
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<Boolean>)
driver ->
seleniumWebDriverUtils
seleniumWebDriverHelper
.waitAndGetElement(By.xpath(ERROR_ALERT))
.getText()
.equals(expectedText));
@ -90,7 +90,7 @@ public class KeycloakPasswordPage {
loadPageWait.until(
(ExpectedCondition<Boolean>)
driver ->
seleniumWebDriverUtils
seleniumWebDriverHelper
.waitAndGetElement(By.xpath(SUCCESS_ALERT))
.getText()
.equals(expectedText));
@ -102,6 +102,6 @@ public class KeycloakPasswordPage {
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));
}
}

View File

@ -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);
}
}
}

View File

@ -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);
}
}

View File

@ -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);
}
}

View File

@ -22,7 +22,7 @@
<script language="beanshell">
<![CDATA[
boolean isTestGroupsAgreedWithRequestedGroups() {
String testGroupsVal = System.getProperty("testGroups");
String testGroupsVal = System.getProperty("testGroups");
if (testGroupsVal == null || testGroupsVal.trim().isEmpty() || groups.isEmpty()){
return true;
}
@ -55,6 +55,9 @@
<class name="org.eclipse.che.selenium.dashboard.organization.OrganizationMembersTest"/>
<class name="org.eclipse.che.selenium.dashboard.organization.RenameOrganizationTest"/>
<class name="org.eclipse.che.selenium.dashboard.organization.SystemAdminOrganizationTest"/>
<class name="org.eclipse.che.selenium.git.AuthorizeOnGithubFromDashboardTest"/>
<class name="org.eclipse.che.selenium.git.AuthorizeOnGithubFromImportTest"/>
<class name="org.eclipse.che.selenium.git.AuthorizeOnGithubFromPreferencesTest"/>
<class name="org.eclipse.che.selenium.git.CheckoutReferenceTest"/>
<class name="org.eclipse.che.selenium.git.CheckoutToRemoteBranchTest"/>
<class name="org.eclipse.che.selenium.git.CheckoutToRemoteBranchWhichAlreadyHasLinkedLocalBranchTest"/>

View File

@ -22,7 +22,7 @@
<script language="beanshell">
<![CDATA[
boolean isTestGroupsAgreedWithRequestedGroups() {
String testGroupsVal = System.getProperty("testGroups");
String testGroupsVal = System.getProperty("testGroups");
if (testGroupsVal == null || testGroupsVal.trim().isEmpty() || groups.isEmpty()){
return true;
}