-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Selenium: Rework the 'CheckoutReferenceTest' to run in the multi-thread mode #9368
Changes from 8 commits
41bcc5a
5964070
1112697
0a85d0f
a408773
526955f
133bce6
e154e58
7d15b6e
e23cfa9
fb66718
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,7 @@ | |
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import javax.annotation.PreDestroy; | ||
import org.apache.commons.io.IOUtils; | ||
import org.eclipse.che.commons.lang.NameGenerator; | ||
import org.kohsuke.github.GHContent; | ||
import org.kohsuke.github.GHFileNotFoundException; | ||
|
@@ -42,7 +43,7 @@ public class TestGitHubRepository { | |
private final String repoName = NameGenerator.generate("EclipseCheTestRepo-", 5); | ||
private static final Logger LOG = LoggerFactory.getLogger(TestGitHubRepository.class); | ||
|
||
private final GHRepository ghRepo; | ||
private GHRepository ghRepo; | ||
private final GitHub gitHub; | ||
|
||
/** | ||
|
@@ -67,16 +68,37 @@ public String getName() { | |
return repoName; | ||
} | ||
|
||
public String getSha1(String branchName) throws IOException { | ||
return ghRepo.getBranch(branchName).getSHA1(); | ||
} | ||
|
||
/** | ||
* Creates reference to branch, tag, ... from master branch. | ||
* Creates reference to the new branch with {@code branchName} from default branch. | ||
* | ||
* @param refName is a name of branch, tag, etc | ||
* @param branchName is a name of new branch | ||
* @return reference to the new branch | ||
* @throws IOException | ||
*/ | ||
public GHRef createBranchFromMaster(String refName) throws IOException { | ||
GHRef master = ghRepo.getRef("heads/master"); | ||
return ghRepo.createRef("refs/heads/" + refName, master.getObject().getSha()); | ||
public GHRef createBranch(String branchName) throws IOException { | ||
GHRef defaultBranch = ghRepo.getRef("heads/" + ghRepo.getDefaultBranch()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please create public method which will be return the default branch
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Which test needs it? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If there are actually no tests which need There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. He can create private method. Multiple using the same row
looks not very good There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Method name There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree |
||
return ghRepo.createRef("refs/heads/" + branchName, defaultBranch.getObject().getSha()); | ||
} | ||
|
||
/** | ||
* Creates reference to the new tag with {@code tagName} from default branch. | ||
* | ||
* @param tagName is a name of new tag | ||
* @return reference to the new tag | ||
* @throws IOException | ||
*/ | ||
public GHRef createTag(String tagName) throws IOException { | ||
GHRef defaultBranch = ghRepo.getRef("heads/" + ghRepo.getDefaultBranch()); | ||
return ghRepo.createRef("refs/tags/" + tagName, defaultBranch.getObject().getSha()); | ||
} | ||
|
||
public void setDefaultBranch(String branchName) throws IOException { | ||
ghRepo.setDefaultBranch(branchName); | ||
ghRepo = gitHub.getRepository(ghRepo.getFullName()); | ||
} | ||
|
||
/** | ||
|
@@ -211,6 +233,6 @@ private void createFile(Path pathToRootContentDirectory, Path pathToFile) throws | |
} | ||
|
||
public String getFileContent(String pathToFile) throws IOException { | ||
return ghRepo.getFileContent(pathToFile).getContent(); | ||
return IOUtils.toString(ghRepo.getFileContent(pathToFile).read(), "UTF-8"); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,31 +11,31 @@ | |
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.LOAD_PAGE_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.eclipse.che.selenium.pageobject.SeleniumWebDriverHelper; | ||
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.ExpectedCondition; | ||
import org.openqa.selenium.support.ui.ExpectedConditions; | ||
import org.openqa.selenium.support.ui.WebDriverWait; | ||
|
||
/** @author Musienko Maxim */ | ||
@Singleton | ||
public class GitHistory { | ||
private final SeleniumWebDriver seleniumWebDriver; | ||
private final Loader loader; | ||
private final SeleniumWebDriverHelper seleniumWebDriverHelper; | ||
|
||
@Inject | ||
public GitHistory(SeleniumWebDriver seleniumWebDriver, Loader loader) { | ||
this.seleniumWebDriver = seleniumWebDriver; | ||
public GitHistory( | ||
SeleniumWebDriver seleniumWebDriver, | ||
Loader loader, | ||
SeleniumWebDriverHelper seleniumWebDriverHelper) { | ||
this.loader = loader; | ||
this.seleniumWebDriverHelper = seleniumWebDriverHelper; | ||
PageFactory.initElements(seleniumWebDriver, this); | ||
} | ||
|
||
|
@@ -60,32 +60,18 @@ private interface Locators { | |
|
||
/** wait appear history form */ | ||
public void waitHistoryForm() { | ||
new WebDriverWait(seleniumWebDriver, ELEMENT_TIMEOUT_SEC) | ||
.until(ExpectedConditions.visibilityOf(historyForm)); | ||
seleniumWebDriverHelper.waitVisibility(historyForm, ELEMENT_TIMEOUT_SEC); | ||
} | ||
|
||
/** wait history form is closed */ | ||
public void waitHistoryFormToClose() { | ||
new WebDriverWait(seleniumWebDriver, LOAD_PAGE_TIMEOUT_SEC) | ||
.until(ExpectedConditions.invisibilityOfElementLocated(By.id(Locators.HISTORY_FORM_ID))); | ||
seleniumWebDriverHelper.waitInvisibility(By.id(Locators.HISTORY_FORM_ID)); | ||
} | ||
|
||
/** click on the 'Compare' button in the history form */ | ||
public void clickCompareButton() { | ||
new WebDriverWait(seleniumWebDriver, REDRAW_UI_ELEMENTS_TIMEOUT_SEC) | ||
.until(ExpectedConditions.elementToBeClickable(By.id(Locators.COMPARE_BUTTON_HISTORY))) | ||
.click(); | ||
} | ||
|
||
/** | ||
* get current value from the the editor form | ||
* | ||
* @return value of message from the editor form | ||
*/ | ||
public String getFullDescription() { | ||
new WebDriverWait(seleniumWebDriver, LOAD_PAGE_TIMEOUT_SEC) | ||
.until(ExpectedConditions.visibilityOf(historyEditor)); | ||
return historyEditor.getAttribute("value"); | ||
seleniumWebDriverHelper.waitAndClick( | ||
By.id(Locators.COMPARE_BUTTON_HISTORY), REDRAW_UI_ELEMENTS_TIMEOUT_SEC); | ||
} | ||
|
||
/** | ||
|
@@ -94,25 +80,19 @@ public String getFullDescription() { | |
* @param rowIndex is a specified number | ||
*/ | ||
public void selectHistoryRowByIndex(int rowIndex) { | ||
new WebDriverWait(seleniumWebDriver, LOAD_PAGE_TIMEOUT_SEC) | ||
.until( | ||
ExpectedConditions.visibilityOfElementLocated( | ||
By.xpath(String.format(Locators.HISTORY_ROW_NUMBER, Integer.toString(rowIndex))))) | ||
.click(); | ||
loader.waitOnClosed(); | ||
seleniumWebDriverHelper.waitAndClick( | ||
By.xpath(String.format(Locators.HISTORY_ROW_NUMBER, Integer.toString(rowIndex)))); | ||
} | ||
|
||
/** wait appear text in history list */ | ||
public void waitTextInHistoryList(final String expectedText) { | ||
new WebDriverWait(seleniumWebDriver, REDRAW_UI_ELEMENTS_TIMEOUT_SEC) | ||
.until( | ||
(ExpectedCondition<Boolean>) webDriver -> historyForm.getText().contains(expectedText)); | ||
seleniumWebDriverHelper.waitTextPresence( | ||
historyForm, expectedText, REDRAW_UI_ELEMENTS_TIMEOUT_SEC); | ||
} | ||
|
||
/** wait appearance history editor */ | ||
public void waitHistoryEditor() { | ||
new WebDriverWait(seleniumWebDriver, LOAD_PAGE_TIMEOUT_SEC) | ||
.until(ExpectedConditions.visibilityOf(historyEditor)); | ||
seleniumWebDriverHelper.waitVisibility(historyEditor); | ||
} | ||
|
||
/** | ||
|
@@ -121,39 +101,42 @@ public void waitHistoryEditor() { | |
* @param expectedContent | ||
*/ | ||
public void waitContentIntoHistoryEditor(final String expectedContent) { | ||
new WebDriverWait(seleniumWebDriver, LOAD_PAGE_TIMEOUT_SEC) | ||
.until( | ||
(ExpectedCondition<Boolean>) | ||
webDriver -> getFullDescription().contains(expectedContent)); | ||
seleniumWebDriverHelper.waitValuePresence(historyEditor, expectedContent); | ||
} | ||
|
||
public void waitCommitInHistoryForm(String text) { | ||
new WebDriverWait(seleniumWebDriver, LOAD_PAGE_TIMEOUT_SEC) | ||
.until( | ||
ExpectedConditions.visibilityOfElementLocated( | ||
By.xpath(String.format(Locators.COMMIT_INTO_HISTORY_FORM, text)))); | ||
seleniumWebDriverHelper.waitVisibility( | ||
By.xpath(String.format(Locators.COMMIT_INTO_HISTORY_FORM, text))); | ||
} | ||
|
||
public void clickCommitInHistoryForm(String text) { | ||
new WebDriverWait(seleniumWebDriver, LOAD_PAGE_TIMEOUT_SEC) | ||
.until( | ||
ExpectedConditions.visibilityOfElementLocated( | ||
By.xpath(String.format(Locators.COMMIT_INTO_HISTORY_FORM, text)))) | ||
.click(); | ||
seleniumWebDriverHelper.waitAndClick( | ||
By.xpath(String.format(Locators.COMMIT_INTO_HISTORY_FORM, text))); | ||
} | ||
|
||
public void waitCommitInHistoryFormNotPresent(String text) { | ||
new WebDriverWait(seleniumWebDriver, LOAD_PAGE_TIMEOUT_SEC) | ||
.until( | ||
ExpectedConditions.invisibilityOfElementLocated( | ||
By.xpath(String.format(Locators.COMMIT_INTO_HISTORY_FORM, text)))); | ||
seleniumWebDriverHelper.waitInvisibility( | ||
By.xpath(String.format(Locators.COMMIT_INTO_HISTORY_FORM, text))); | ||
} | ||
|
||
/** click on close button history */ | ||
public void clickOnCloseButtonHistory() { | ||
new WebDriverWait(seleniumWebDriver, REDRAW_UI_ELEMENTS_TIMEOUT_SEC) | ||
.until(ExpectedConditions.elementToBeClickable(closeButtonHistory)) | ||
.click(); | ||
seleniumWebDriverHelper.waitAndClick(closeButtonHistory, REDRAW_UI_ELEMENTS_TIMEOUT_SEC); | ||
waitHistoryFormToClose(); | ||
} | ||
|
||
public String getTopCommitRevision() { | ||
loader.waitOnClosed(); | ||
int numberOfTopRevisionCell = 0; | ||
return getGitHistoryTopContent().split("\n")[numberOfTopRevisionCell]; | ||
} | ||
|
||
/** Returns all cells from top row divided by "\n" */ | ||
private String getGitHistoryTopContent() { | ||
String rowTopIndex = Integer.toString(0); | ||
return seleniumWebDriverHelper | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is a method There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK |
||
.waitVisibility( | ||
By.xpath(String.format(Locators.HISTORY_ROW_NUMBER, rowTopIndex)), ELEMENT_TIMEOUT_SEC) | ||
.getText(); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@param branchName name of the branch which should be created
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK