-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
213 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
101 changes: 101 additions & 0 deletions
101
...-selenium-test/src/main/java/org/eclipse/che/selenium/pageobject/git/GitRevertCommit.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
/* | ||
* Copyright (c) 2012-2017 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.git; | ||
|
||
import static org.eclipse.che.selenium.core.constant.TestTimeoutsConstants.ELEMENT_TIMEOUT_SEC; | ||
import static org.eclipse.che.selenium.core.constant.TestTimeoutsConstants.REDRAW_UI_ELEMENTS_TIMEOUT_SEC; | ||
|
||
import com.google.inject.Inject; | ||
import com.google.inject.Singleton; | ||
import org.eclipse.che.selenium.core.SeleniumWebDriver; | ||
import org.eclipse.che.selenium.pageobject.Loader; | ||
import org.openqa.selenium.By; | ||
import org.openqa.selenium.WebElement; | ||
import org.openqa.selenium.support.FindBy; | ||
import org.openqa.selenium.support.PageFactory; | ||
import org.openqa.selenium.support.ui.ExpectedConditions; | ||
import org.openqa.selenium.support.ui.WebDriverWait; | ||
|
||
/** @author Anatolii Bazko */ | ||
@Singleton | ||
public class GitRevertCommit { | ||
private static final String REVERT_COMMIT_PANEL = "gwt-debug-revert-commit-panel"; | ||
private static final String REVERT_BUTTON = "git-revert"; | ||
private static final String CANCEL_BUTTON = "git-revert-cancel"; | ||
|
||
private final SeleniumWebDriver seleniumWebDriver; | ||
private final Loader loader; | ||
|
||
@Inject | ||
public GitRevertCommit(SeleniumWebDriver seleniumWebDriver, Loader loader) { | ||
this.seleniumWebDriver = seleniumWebDriver; | ||
this.loader = loader; | ||
PageFactory.initElements(seleniumWebDriver, this); | ||
} | ||
|
||
@FindBy(id = REVERT_COMMIT_PANEL) | ||
private WebElement revertPanel; | ||
|
||
@FindBy(id = REVERT_BUTTON) | ||
private WebElement revertButton; | ||
|
||
@FindBy(id = CANCEL_BUTTON) | ||
private WebElement cancelButton; | ||
|
||
public void waitRevertPanelOpened() { | ||
new WebDriverWait(seleniumWebDriver, ELEMENT_TIMEOUT_SEC) | ||
.until(ExpectedConditions.visibilityOf(revertPanel)); | ||
} | ||
|
||
public void waitRevertPanelClosed() { | ||
new WebDriverWait(seleniumWebDriver, ELEMENT_TIMEOUT_SEC) | ||
.until(ExpectedConditions.invisibilityOfElementLocated(By.id(REVERT_COMMIT_PANEL))); | ||
} | ||
|
||
public void clickRevertButton() { | ||
new WebDriverWait(seleniumWebDriver, ELEMENT_TIMEOUT_SEC) | ||
.until(ExpectedConditions.visibilityOf(revertButton)) | ||
.click(); | ||
} | ||
|
||
public String getTopCommitRevision() { | ||
loader.waitOnClosed(); | ||
return new WebDriverWait(seleniumWebDriver, ELEMENT_TIMEOUT_SEC) | ||
.until(ExpectedConditions.visibilityOf(revertPanel)) | ||
.getText() | ||
.split("\n")[1] | ||
.replaceAll("\\.", ""); | ||
} | ||
|
||
public String getTopCommitComment() { | ||
loader.waitOnClosed(); | ||
return new WebDriverWait(seleniumWebDriver, ELEMENT_TIMEOUT_SEC) | ||
.until(ExpectedConditions.visibilityOf(revertPanel)) | ||
.getText() | ||
.split("\n")[4]; | ||
} | ||
|
||
public String getTopCommitAuthor() { | ||
loader.waitOnClosed(); | ||
return new WebDriverWait(seleniumWebDriver, ELEMENT_TIMEOUT_SEC) | ||
.until(ExpectedConditions.visibilityOf(revertPanel)) | ||
.getText() | ||
.split("\n")[3]; | ||
} | ||
|
||
public void selectRevision(String revision) { | ||
new WebDriverWait(seleniumWebDriver, REDRAW_UI_ELEMENTS_TIMEOUT_SEC) | ||
.until( | ||
ExpectedConditions.visibilityOfElementLocated( | ||
By.xpath("//*[contains(text(),'" + revision + "')]"))) | ||
.click(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
104 changes: 104 additions & 0 deletions
104
selenium/che-selenium-test/src/test/java/org/eclipse/che/selenium/git/RevertCommitTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
/* | ||
* Copyright (c) 2012-2017 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.core.constant.TestMenuCommandsConstants.Git.GIT; | ||
import static org.eclipse.che.selenium.core.constant.TestMenuCommandsConstants.Git.REVERT_COMMIT; | ||
import static org.testng.Assert.assertEquals; | ||
import static org.testng.Assert.assertTrue; | ||
|
||
import com.google.inject.Inject; | ||
import com.google.inject.name.Named; | ||
import org.eclipse.che.api.core.ConflictException; | ||
import org.eclipse.che.commons.lang.NameGenerator; | ||
import org.eclipse.che.selenium.core.client.TestGitHubServiceClient; | ||
import org.eclipse.che.selenium.core.client.TestSshServiceClient; | ||
import org.eclipse.che.selenium.core.client.TestUserPreferencesServiceClient; | ||
import org.eclipse.che.selenium.core.user.DefaultTestUser; | ||
import org.eclipse.che.selenium.core.workspace.TestWorkspace; | ||
import org.eclipse.che.selenium.pageobject.Ide; | ||
import org.eclipse.che.selenium.pageobject.Menu; | ||
import org.eclipse.che.selenium.pageobject.ProjectExplorer; | ||
import org.eclipse.che.selenium.pageobject.Wizard; | ||
import org.eclipse.che.selenium.pageobject.git.GitRevertCommit; | ||
import org.eclipse.che.selenium.pageobject.git.GitStatusBar; | ||
import org.testng.annotations.BeforeClass; | ||
import org.testng.annotations.Test; | ||
|
||
/** @author Anatolii Bazko */ | ||
public class RevertCommitTest { | ||
private static final String PROJECT_NAME = NameGenerator.generate("project", 2); | ||
|
||
@Inject private TestWorkspace ws; | ||
@Inject private Ide ide; | ||
@Inject private DefaultTestUser productUser; | ||
|
||
@Inject | ||
@Named("github.username") | ||
private String gitHubUsername; | ||
|
||
@Inject | ||
@Named("github.password") | ||
private String gitHubPassword; | ||
|
||
@Inject private ProjectExplorer projectExplorer; | ||
@Inject private Menu menu; | ||
@Inject private org.eclipse.che.selenium.pageobject.git.Git git; | ||
@Inject private TestSshServiceClient testSshServiceClient; | ||
@Inject private TestUserPreferencesServiceClient testUserPreferencesServiceClient; | ||
@Inject private TestGitHubServiceClient gitHubClientService; | ||
@Inject private GitRevertCommit gitRevertCommit; | ||
@Inject private GitStatusBar gitStatusBar; | ||
|
||
@BeforeClass | ||
public void prepare() throws Exception { | ||
uploadSshKey(); | ||
testUserPreferencesServiceClient.addGitCommitter(gitHubUsername, productUser.getEmail()); | ||
|
||
ide.open(ws); | ||
|
||
git.importJavaApp( | ||
"git@github.com:" + gitHubUsername + "/testRepo-1.git", | ||
PROJECT_NAME, | ||
Wizard.TypeProject.MAVEN); | ||
|
||
projectExplorer.waitProjectExplorer(); | ||
projectExplorer.waitItem(PROJECT_NAME); | ||
projectExplorer.selectItem(PROJECT_NAME); | ||
} | ||
|
||
@Test | ||
public void shouldRevertCommit() { | ||
menu.runCommand(GIT, REVERT_COMMIT); | ||
|
||
String revision = gitRevertCommit.getTopCommitRevision(); | ||
String comment = gitRevertCommit.getTopCommitComment(); | ||
|
||
gitRevertCommit.selectRevision(revision); | ||
gitRevertCommit.clickRevertButton(); | ||
|
||
gitStatusBar.waitMessageInGitTab("Reverted commits: - " + revision); | ||
|
||
menu.runCommand(GIT, REVERT_COMMIT); | ||
|
||
assertEquals(gitRevertCommit.getTopCommitAuthor(), gitHubUsername); | ||
assertTrue(gitRevertCommit.getTopCommitComment().contains("Revert \"" + comment + "\"")); | ||
} | ||
|
||
private void uploadSshKey() throws Exception { | ||
try { | ||
String publicKey = testSshServiceClient.generateGithubKey(); | ||
gitHubClientService.uploadPublicKey(gitHubUsername, gitHubPassword, publicKey); | ||
} catch (ConflictException ignored) { | ||
// already generated | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters