Skip to content

Commit

Permalink
#2 Update all Features/Test-Steps/Pages due to changes in the Seafile UI
Browse files Browse the repository at this point in the history
-> The new Seafile Version now uses: React JS & Python 3
- Mainly updated the selectors of the html-elements of the pages
  • Loading branch information
helkv committed Jun 4, 2020
1 parent a520d50 commit 6dc8727
Show file tree
Hide file tree
Showing 10 changed files with 177 additions and 179 deletions.
22 changes: 10 additions & 12 deletions src/main/java/ui/components/FooterComponent.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public class FooterComponent extends BasePage {
@FindBy(linkText = "About")
private WebElement aboutLink;

@FindBy(id = "footer-img")
@FindBy(xpath = "//*[@id='footer-header']/*[contains(@class,'keeper-icon-triangle-up')]")
private WebElement footerFoldOutElement;

@FindBy(linkText = "About Keeper")
Expand All @@ -50,11 +50,11 @@ public class FooterComponent extends BasePage {
@FindBy(linkText = "Download the Keeper client for Windows, Linux, Mac, Android and iPhone")
private WebElement downloadClientLink;

@FindBy(id = "seafile-logo")
private WebElement seafileLogo;
@FindBy(xpath = "//img[@id='seafile-logo']/parent::a")
private WebElement seafileLink;

@FindBy(id = "MPDL-logo")
private WebElement mpdlLogo;
@FindBy(xpath = "//img[@id='MPDL-logo']/parent::a")
private WebElement mpdlLink;

@FindBy(linkText = "Contact Keeper Support")
private WebElement contactKeeperSupportLink;
Expand Down Expand Up @@ -87,7 +87,7 @@ public void openHelpPage() {
public void openAboutDialog() {
this.aboutLink.click();

wait.until(ExpectedConditions.elementToBeClickable(By.id("simplemodal-container")));
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//*[@class='modal-dialog']")));
}

public void openAboutKeeper() {
Expand Down Expand Up @@ -129,19 +129,17 @@ public void openDownloadClientPage() {

public String getSeafileLink() {
this.footerFoldOutElement.click();
wait.until(ExpectedConditions.elementToBeClickable(this.seafileLogo));
String onclick = this.seafileLogo.getAttribute("onclick");
wait.until(ExpectedConditions.elementToBeClickable(this.seafileLink));

String seafileLink = onclick.replace("window.open('", "").replace("');", "");
String seafileLink = this.seafileLink.getAttribute("href");
return seafileLink;
}

public String getMpdlLink() {
this.footerFoldOutElement.click();
wait.until(ExpectedConditions.elementToBeClickable(this.mpdlLogo));
String onclick = this.mpdlLogo.getAttribute("onclick");
wait.until(ExpectedConditions.elementToBeClickable(this.mpdlLink));

String mpdlLink = onclick.replace("window.open('", "").replace("');", "");
String mpdlLink = this.mpdlLink.getAttribute("href");
return mpdlLink;
}

Expand Down
61 changes: 36 additions & 25 deletions src/main/java/ui/pages/HomePage.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.springframework.beans.factory.annotation.Autowired;
Expand All @@ -32,16 +33,19 @@ public class HomePage extends BasePage {
@FindBy(id = "my-info")
private WebElement userElement;

@FindBy(id = "logout")
@FindBy(xpath = "//*[@id='user-info-popup']//a[text()='Log out']")
private WebElement logoutElement;

@FindBy(id = "my-repos")
@FindBy(xpath = "//h3[text()='My Libraries']")
private WebElement myLibrariesHeading;

@FindBy(xpath = "//div[@class='cur-view-container']")
private WebElement myLibrariesDiv;

@FindBy(xpath = "//*[@id='my-repos-toolbar']/button[contains(@class,'repo-create')]")
@FindBy(xpath = "//button[@title='New Library']")
private WebElement newLibraryButton;

@FindBy(id = "side-nav")
@FindBy(className = "side-nav")
private WebElement sideNavigationDiv;

@Autowired
Expand Down Expand Up @@ -78,28 +82,33 @@ public String lookUpUserAccountName() {
WebElement userAccountButton = driver.findElement(By.id("my-info"));
userAccountButton.click();

WebElement accountName = driver.findElement(By.xpath("//div[@class='item ovhd']/div[@class='txt']"));
WebElement accountName = driver
.findElement(By.xpath("//div[@id='account']//div[@class='item o-hidden']/div[@class='txt']"));
return accountName.getText();
}

public HomePage createNewLibrary(String newLibraryName) {
newLibraryButton.click();
WebElement newLibraryDialog = wait
.until(ExpectedConditions.visibilityOfElementLocated(By.id("simplemodal-container")));
.until(ExpectedConditions.visibilityOfElementLocated(By.className("modal-content")));

WebElement libraryNameInput = newLibraryDialog.findElement(By.id("repo-name"));
WebElement libraryNameInput = newLibraryDialog.findElement(By.id("repoName"));
libraryNameInput.sendKeys(newLibraryName);

WebElement submit = newLibraryDialog.findElement(By.className("submit"));
WebElement submit = newLibraryDialog.findElement(By.xpath(".//button[text()='Submit']"));
submit.click();

wait.until(ExpectedConditions.stalenessOf(newLibraryDialog));
// TODO: Use different waiting strategy to wait for the success of this method
// (check AJAX request!?)
wait.until(ExpectedConditions.visibilityOfAllElementsLocatedBy(
By.xpath(".//a[contains(@href,'/library/') and text()='" + newLibraryName + "']")));

return homePage;
}

public List<String> readLibraryNames() {
List<WebElement> libraryLinks = this.myLibrariesDiv.findElements(By.xpath(".//*[@class='repo-name-span']/a"));
List<WebElement> libraryLinks = this.myLibrariesDiv.findElements(By.xpath(".//a[contains(@href,'/library/')]"));

List<String> libraryNames = new ArrayList<>();
libraryLinks.forEach(libraryLink -> libraryNames.add(libraryLink.getText()));
Expand All @@ -108,20 +117,20 @@ public List<String> readLibraryNames() {
}

public HomePage deleteLibrary(String libraryName) {
WebElement firstLibraryRow = wait.until(ExpectedConditions
.elementToBeClickable(By.xpath("//*[@id='my-repos']//a[text()='" + libraryName + "']/ancestor::tr")));
WebElement firstLibraryRow = wait.until(ExpectedConditions.elementToBeClickable(
By.xpath("//div[@class='cur-view-container']//a[text()='" + libraryName + "']/ancestor::tr")));

new Actions(driver).moveToElement(firstLibraryRow).perform();
WebElement deleteButton = firstLibraryRow.findElement(By.xpath(".//a[@title='Delete']"));
((JavascriptExecutor) driver).executeScript("arguments[0].setAttribute('style','visibility:visible;');",
deleteButton);
deleteButton.click();

wait.until(ExpectedConditions.visibilityOfElementLocated(
By.xpath("//*[@id='confirm-con']//*[contains(text(),'" + libraryName + "')]")));
WebElement yesButton = wait.until(ExpectedConditions.elementToBeClickable(By.id("confirm-yes")));
yesButton.click();
By.xpath("//*[@class='modal-content']//*[contains(text(),'" + libraryName + "')]")));
WebElement confirmDeleteButton = wait.until(ExpectedConditions
.elementToBeClickable(By.xpath("//*[@class='modal-content']//button[text()='Delete']")));
confirmDeleteButton.click();

wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("my-libs-more-op")));
wait.until(ExpectedConditions.visibilityOf(myLibrariesHeading));

return homePage;
}
Expand All @@ -131,7 +140,7 @@ public LibraryPage openLibrary(String libraryName) {
WebElement libraryLink = wait.until(driver -> this.myLibrariesDiv.findElement(By.linkText(libraryName)));
libraryLink.click();

wait.until(ExpectedConditions.elementToBeClickable(By.id("share-cur-dir")));
wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//button[@title='Share']")));
wait.until(webDriver -> ((JavascriptExecutor) webDriver).executeScript("return document.readyState")
.equals("complete"));

Expand All @@ -142,26 +151,28 @@ public HomePage openMyLibraries() {
WebElement myLibrariesButton = sideNavigationDiv.findElement(By.xpath(".//a[@title='My Libraries']"));
myLibrariesButton.click();

wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("my-repos")));
wait.until(webDriver -> ((Long) (((JavascriptExecutor) webDriver).executeScript("return jQuery.active")) == 0));
wait.until(ExpectedConditions.visibilityOf(myLibrariesHeading));
// TODO: Handle waiting for AJAX differently
// wait.until(webDriver -> ((Long) (((JavascriptExecutor) webDriver).executeScript("return jQuery.active")) == 0));

return homePage;
}

public boolean aboutDialogIsOpened() {
WebElement dialog = driver.findElement(By.id("simplemodal-container"));
List<WebElement> seafileLogo = dialog.findElements(By.xpath(".//img[@title='Seafile']"));
WebElement dialog = driver.findElement(By.xpath("//*[@class='modal-dialog']"));
List<WebElement> keeperLogo = dialog.findElements(By.xpath(".//img[@title='KEEPER']"));

return !seafileLogo.isEmpty();
return !keeperLogo.isEmpty();
}

public HomePage navigateTo() {
// TODO: Rework centralized access to the Keeper URLs
driver.navigate().to(testDataProperties.getProperty("keeperUrl"));

// Waiting for the HomePage to load by waiting for My Libraries
wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("my-repos")));
wait.until(webDriver -> ((Long) (((JavascriptExecutor) webDriver).executeScript("return jQuery.active")) == 0));
wait.until(ExpectedConditions.visibilityOf(myLibrariesHeading));
// TODO: Handle waiting for AJAX differently
// wait.until(webDriver -> ((Long) (((JavascriptExecutor) webDriver).executeScript("return jQuery.active")) == 0));

return homePage;
}
Expand Down
34 changes: 17 additions & 17 deletions src/main/java/ui/pages/LibraryPage.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.springframework.beans.factory.annotation.Autowired;
Expand All @@ -32,10 +33,10 @@
@Scope(SCOPE_CUCUMBER_GLUE)
public class LibraryPage extends BasePage {

@FindBy(id = "dir-view")
@FindBy(className = "cur-view-container")
private WebElement directoryViewDiv;

@FindBy(id = "advanced-upload")
@FindBy(xpath = "//button[@title='Upload']")
private WebElement uploadButton;

@Autowired
Expand All @@ -44,7 +45,7 @@ public LibraryPage(WebDriver driver) {
}

public List<String> readFileNames() {
List<WebElement> fileLinks = this.directoryViewDiv.findElements(By.xpath(".//*[@class='dirent-name']/a"));
List<WebElement> fileLinks = this.directoryViewDiv.findElements(By.xpath(".//a[contains(@href,'/lib/')]"));

List<String> fileNames = new ArrayList<>();
fileLinks.forEach(fileLink -> fileNames.add(fileLink.getText()));
Expand All @@ -58,7 +59,7 @@ public void openMarkdownElement(String elementName) {
SeleniumUtil.switchToSecondTab(driver, wait);

wait.until(ExpectedConditions.titleContains(elementName));
wait.until(ExpectedConditions.elementToBeClickable(By.id("editButton")));
wait.until(ExpectedConditions.elementToBeClickable(By.id("parentDirectory")));
wait.until(webDriver -> ((JavascriptExecutor) webDriver).executeScript("return document.readyState")
.equals("complete"));
}
Expand All @@ -67,45 +68,44 @@ public void lockElement(String elementName) {
WebElement elementLink = this.directoryViewDiv.findElement(By.linkText(elementName));
WebElement elementRow = elementLink.findElement(By.xpath(".//ancestor::tr"));

WebElement moreOptions = elementRow.findElement(By.className("more-op-icon"));
new Actions(driver).moveToElement(elementRow).perform();
WebElement moreOptions = elementRow.findElement(By.xpath(".//*[@title='More Operations']"));
moreOptions.click();
WebElement lockFile = elementRow.findElement(By.className("lock-file"));
WebElement lockFile = elementRow.findElement(By.xpath(".//button[text()='Lock']"));
lockFile.click();

wait.until(ExpectedConditions.visibilityOfElementLocated(By.className("file-locked-icon")));
wait.until(ExpectedConditions.visibilityOfElementLocated(By.className("locked")));
}

public void unlockElement(String elementName) {
WebElement elementLink = this.directoryViewDiv.findElement(By.linkText(elementName));
WebElement elementRow = elementLink.findElement(By.xpath(".//ancestor::tr"));

WebElement moreOptions = elementRow.findElement(By.className("more-op-icon"));
new Actions(driver).moveToElement(elementRow).perform();
WebElement moreOptions = elementRow.findElement(By.xpath(".//*[@title='More Operations']"));
// Selenium has problems hover/scroll element when clicking => Use JS to click
((JavascriptExecutor) driver).executeScript("arguments[0].click();", moreOptions);
WebElement unlockFile = elementRow.findElement(By.className("unlock-file"));
WebElement unlockFile = elementRow.findElement(By.xpath(".//button[text()='Unlock']"));
unlockFile.click();

wait.until(ExpectedConditions.invisibilityOfElementLocated(By.className("file-locked-icon")));
wait.until(ExpectedConditions.invisibilityOfElementLocated(By.className("locked")));
}

public boolean lockedIconVisible(String elementName) {
WebElement elementLink = this.directoryViewDiv.findElement(By.linkText(elementName));
WebElement elementRow = elementLink.findElement(By.xpath(".//ancestor::tr"));

List<WebElement> lockIcon = elementRow.findElements(By.className("file-locked-icon"));
List<WebElement> lockIcon = elementRow.findElements(By.className("locked"));
return !lockIcon.isEmpty();
}

public void uploadFile(String fileName) {
// Check upload buttons are clickable:
this.uploadButton.click();
WebElement uploadFilesButton = driver.findElement(By.className("advanced-upload-file"));
wait.until(ExpectedConditions.elementToBeClickable(uploadFilesButton));
// Click on 'Upload' again to hide the field again
// Check upload buttons are clickable (Only to verify the buttons work):
this.uploadButton.click();
wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//li[text()='Upload Files']")));

// Upload done using the upload input element:
WebElement uploadInputElement = driver.findElement(By.id("advanced-upload-file-input"));
WebElement uploadInputElement = driver.findElement(By.className("upload-input"));
((JavascriptExecutor) driver).executeScript("arguments[0].style.visibility = 'visible';", uploadInputElement);

// FIXME: Move the extraction of the filepath to another class/method
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/ui/pages/LoginPage.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public HomePage login(String email, String password) {
this.passwordInput.sendKeys(password);

this.loginButton.click();
wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("my-libs-more-op")));
wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("account")));

return homePage;
}
Expand Down
Loading

0 comments on commit 6dc8727

Please sign in to comment.