Skip to content

Commit

Permalink
Merge branch 'chore/upgrade-selenium' into 'develop'
Browse files Browse the repository at this point in the history
OEQ-2331 - chore: upgrade to Selenium 4.x

See merge request edalex-group/development/oeq/openequella!521
  • Loading branch information
PenghaiZhang committed Feb 12, 2025
2 parents b0d11ab + 99a6ef3 commit 40e3f2b
Show file tree
Hide file tree
Showing 31 changed files with 98 additions and 70 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import java.net.MalformedURLException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.Duration;
import java.util.Date;
import java.util.List;
import java.util.Random;
Expand Down Expand Up @@ -1068,7 +1069,7 @@ private List<WebElement> getDivsByPrefix(String prefix) {
*/
private WebElement getAscMessage() {
By ascMessageXpath = By.xpath("//div[@id='ascMessage']/span");
WebDriverWait wait = new WebDriverWait(context.getDriver(), 30);
WebDriverWait wait = new WebDriverWait(context.getDriver(), Duration.ofSeconds(30));
wait.until(ExpectedConditions.visibilityOfElementLocated(ascMessageXpath));
return context.getDriver().findElement(ascMessageXpath);
}
Expand All @@ -1087,7 +1088,7 @@ private String getDivMessageForId(String id) {

private void ascEditbox(int ctrlNum, String suffix, String text) {
WebElement field = context.getDriver().findElement(By.name("c" + ctrlNum + suffix));
WebDriverWait wait = new WebDriverWait(context.getDriver(), 30);
WebDriverWait wait = new WebDriverWait(context.getDriver(), Duration.ofSeconds(30));
wait.until(ExpectedConditions.visibilityOf(field));
field.clear();
field.sendKeys(text);
Expand All @@ -1100,7 +1101,7 @@ private void ascEditbox(int ctrlNum, String suffix, String text) {
* @param text
*/
private void ascSelectDropdown(String id, String optText) {
WebDriverWait wait = new WebDriverWait(context.getDriver(), 30);
WebDriverWait wait = new WebDriverWait(context.getDriver(), Duration.ofSeconds(30));
wait.until(ExpectedConditions.presenceOfElementLocated(By.id(id)));
Select dropdown = new Select(context.getDriver().findElement(By.id(id)));
dropdown.selectByVisibleText(optText);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ public void testMyResourcesPortal() {
MyResourcesPortalSection myResources =
new MyResourcesPortalSection(context, myResourceName).get();

myResources.delete();
home = myResources.delete();
assertFalse(home.portalExists(myResourceName));
}

Expand Down Expand Up @@ -320,17 +320,14 @@ public void testRecentPortal() {
assertTrue(checkContributionExistence(waiter, recentName, liveItemName));

// Edit the portal
new MenuSection(context).home();
RecentContributionsSection recent = new RecentContributionsSection(context, recentName).get();
RecentContributionsEditPage edit = recent.edit(portal);
edit.setStatus("draft");
edit.checkSelectedCollection();
edit.save(new HomePage(context));
waiter = edit.save(new HomePage(context)).getWaiter();

// Check that the draft item is displayed
home = new MenuSection(context).home();
recent = new RecentContributionsSection(context, recentName).get();
assertTrue(recent.recentContributionExists(draftItemName));
assertTrue(checkContributionExistence(waiter, recentName, draftItemName));

String itemToQuery = context.getFullName("query item");
String description = context.getFullName("query item description");
Expand All @@ -342,7 +339,8 @@ public void testRecentPortal() {
wizard3.save().publish();

// Edit portlet for query option
home = new MenuSection(context).home();
new MenuSection(context).home();
recent = new RecentContributionsSection(context, recentName).get();
edit = recent.edit(portal);
edit.setQuery("query item");
edit.setStatus("live");
Expand All @@ -351,20 +349,17 @@ public void testRecentPortal() {

// Check that the queried item is displayed
assertTrue(checkContributionExistence(waiter, recentName, itemToQuery));
new MenuSection(context).home();
recent = new RecentContributionsSection(context, recentName).get();
assertTrue(recent.descriptionExists(description, true));

// Edit portlet for description option
home = new MenuSection(context).home();
recent = new RecentContributionsSection(context, recentName).get();
edit = recent.edit(portal);
edit.setDisplayTitleOnly(true);
edit.checkSelectedCollection();
edit.save(new HomePage(context));

// Check that the description not displayed
new MenuSection(context).home();
recent = new RecentContributionsSection(context, recentName).get();
assertFalse(recent.descriptionExists(description, false));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import com.tle.webtests.pageobject.wizard.WizardPageTab;
import com.tle.webtests.test.AbstractCleanupTest;
import java.io.IOException;
import java.time.Duration;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
Expand Down Expand Up @@ -68,7 +69,8 @@ public void notificationsSubsearchTest() throws Exception {
private void waitForIndex() throws IOException {
final String token = requestToken(OAUTH_CLIENT_ID);

WebDriverWait notificationsIndexedWaiter = new WebDriverWait(context.getDriver(), 10);
WebDriverWait notificationsIndexedWaiter =
new WebDriverWait(context.getDriver(), Duration.ofSeconds(10));
notificationsIndexedWaiter.until(
(Function<WebDriver, Boolean>)
driver -> {
Expand Down
2 changes: 1 addition & 1 deletion autotest/Tests/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ libraryDependencies ++= Seq(
"org.scala-lang" % "scala-reflect" % scalaVersion.value,
"javax.jws" % "javax.jws-api" % "1.1",
"org.apache.commons" % "commons-lang3" % "3.14.0",
"org.seleniumhq.selenium" % "selenium-java" % "3.141.59",
"org.seleniumhq.selenium" % "selenium-java" % "4.26.0",
"org.easytesting" % "fest-util" % "1.2.5",
"org.easytesting" % "fest-swing" % "1.2.1",
"xalan" % "xalan" % "2.7.3",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package com.tle.webtests.framework;

import static java.util.concurrent.TimeUnit.SECONDS;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.collect.Maps;
import com.tle.common.Check;
Expand Down Expand Up @@ -142,7 +140,6 @@ public WebDriver getDriver(Class<?> clazz) throws IOException {
} else {
binary = new FirefoxBinary();
}
binary.setTimeout(SECONDS.toMillis(120));
FirefoxProfile profile = new FirefoxProfile();
profile.addExtension(getClass(), "firebug-1.10.2-fx.xpi");
profile.addExtension(getClass(), "firepath-0.9.7-fx.xpi");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import java.net.URL;
import java.nio.file.Paths;
import java.text.MessageFormat;
import java.time.Duration;
import java.util.Properties;
import java.util.TimeZone;

Expand Down Expand Up @@ -68,8 +69,8 @@ public static String findInstitutionName(Class<?> clazz) {
return inst;
}

public int getStandardTimeout() {
return getIntProperty("timeout.standard", 30);
public Duration getStandardTimeout() {
return Duration.ofSeconds(getIntProperty("timeout.standard", 30));
}

public String getAdminPassword() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.concurrent.TimeUnit;
import java.time.Duration;
import org.openqa.selenium.By;
import org.openqa.selenium.SearchContext;
import org.openqa.selenium.StaleElementReferenceException;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.internal.WrapsElement;
import org.openqa.selenium.WrapsElement;
import org.openqa.selenium.support.ui.FluentWait;

public class RefreshingElementHandler implements InvocationHandler {
private static final FluentWait<Object> waiter =
new FluentWait<Object>(Void.class)
.withTimeout(10, TimeUnit.SECONDS)
.pollingEvery(50, TimeUnit.MILLISECONDS);
.withTimeout(Duration.ofSeconds(10))
.pollingEvery(Duration.ofMillis(50));
private LazyTemplatedElementLocator locator;
private RefreshingElementProxyCreator proxyCreator;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Proxy;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.internal.WrapsElement;
import org.openqa.selenium.WrapsElement;
import org.openqa.selenium.support.pagefactory.DefaultFieldDecorator;
import org.openqa.selenium.support.pagefactory.ElementLocator;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package com.tle.webtests.framework.setup;

import static java.util.concurrent.TimeUnit.SECONDS;

import com.tle.webtests.framework.Assert;
import com.tle.webtests.framework.PageContext;
import com.tle.webtests.framework.TestConfig;
Expand Down Expand Up @@ -175,7 +173,6 @@ private FirefoxDriver getDriver() {
} else {
binary = new FirefoxBinary();
}
binary.setTimeout(SECONDS.toMillis(120));
FirefoxProfile profile = new FirefoxProfile();
// profile.addExtension(getClass(), "firebug-1.7.3-fx.xpi");
profile.setPreference("extensions.firebug.currentVersion", "999");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import java.net.URL;
import java.net.URLEncoder;
import java.nio.file.Paths;
import java.time.Duration;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
Expand Down Expand Up @@ -56,23 +57,32 @@ public AbstractPage(
loadedElement = null;
}

public AbstractPage(PageContext context, By loadedBy, int timeOut) {
this(context, context.getDriver(), loadedBy, timeOut);
/**
* @param timeoutSeconds -1 for default timeout
*/
public AbstractPage(PageContext context, By loadedBy, int timeoutSeconds) {
this(context, context.getDriver(), loadedBy, timeoutSeconds);
}

public AbstractPage(PageContext context, SearchContext searchContext, By loadedBy) {
this(context, searchContext, loadedBy, -1);
}

public AbstractPage(PageContext context, SearchContext searchContext, By loadedBy, int timeOut) {
/**
* @param timeoutSeconds -1 for default timeout
*/
public AbstractPage(
PageContext context, SearchContext searchContext, By loadedBy, int timeoutSeconds) {
this(
context,
searchContext,
loadedBy,
new WebDriverWait(
context.getDriver(),
timeOut == -1 ? context.getTestConfig().getStandardTimeout() : timeOut,
50));
timeoutSeconds == -1
? context.getTestConfig().getStandardTimeout()
: Duration.ofSeconds(timeoutSeconds),
Duration.ofMillis(50)));
}

public AbstractPage(PageContext context, By loadedBy) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebDriverException;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.internal.WrapsElement;
import org.openqa.selenium.WrapsElement;
import org.openqa.selenium.support.ui.ExpectedCondition;
import org.openqa.selenium.support.ui.ExpectedConditions;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.tle.webtests.framework.PageContext;
import com.tle.webtests.pageobject.AbstractPage;
import java.time.Duration;
import java.util.function.Function;
import org.openqa.selenium.*;
import org.openqa.selenium.support.FindBy;
Expand Down Expand Up @@ -30,7 +31,7 @@ public void setReason(String reason) {
(Function<WebDriver, Object>)
webDriver -> {
try {
new WebDriverWait(webDriver, 1)
new WebDriverWait(webDriver, Duration.ofSeconds(1))
.until(ExpectedConditions.stalenessOf(getContinueButton()));
return false;
} catch (TimeoutException toe) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.tle.webtests.pageobject.connectors;

import com.tle.webtests.pageobject.WaitingPageObject;
import java.time.Duration;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
Expand Down Expand Up @@ -47,7 +48,8 @@ public WebDriverWait getWaiter() {

public EditBlackboardConnectorPage(ShowConnectorsPage connectorsPage) {
super(connectorsPage);
this.bbWaiter = new WebDriverWait(context.getDriver(), 60, 50);
this.bbWaiter =
new WebDriverWait(context.getDriver(), Duration.ofMinutes(1), Duration.ofMillis(50));
}

public EditBlackboardConnectorPage setUrl(String url, String user, String password) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.tle.webtests.framework.EBy;
import com.tle.webtests.framework.PageContext;
import com.tle.webtests.pageobject.AbstractPage;
import java.time.Duration;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
Expand All @@ -26,7 +27,7 @@ public DatabaseRow(PageContext context, WebElement rowElement) {
super(context);
this.rowElement = rowElement;
statusElement = rowElement.findElement(By.className("status"));
longWaiter = new WebDriverWait(context.getDriver(), 60);
longWaiter = new WebDriverWait(context.getDriver(), Duration.ofMinutes(1));
}

public void initialise() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.time.Duration;
import java.util.zip.ZipOutputStream;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
Expand Down Expand Up @@ -55,7 +56,7 @@ private WebElement getPasswordConfirmElem() {

public ImportTab(PageContext context) {
super(context, "Import institution", "Import new institution");
waiter = new WebDriverWait(context.getDriver(), 240);
waiter = new WebDriverWait(context.getDriver(), Duration.ofMinutes(4));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.google.common.base.Function;
import com.tle.webtests.framework.PageContext;
import com.tle.webtests.pageobject.AbstractPage;
import java.time.Duration;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
Expand All @@ -20,7 +21,7 @@ public class MigrationProgressDialog extends AbstractPage<MigrationProgressDialo

public MigrationProgressDialog(PageContext context) {
super(context, By.className("progress-curr-migration"));
longWaiter = new WebDriverWait(context.getDriver(), 180);
longWaiter = new WebDriverWait(context.getDriver(), Duration.ofMinutes(3));
}

public void close() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.tle.webtests.framework.PageContext;
import com.tle.webtests.pageobject.AbstractPage;
import com.tle.webtests.pageobject.WaitingPageObject;
import java.time.Duration;
import java.util.List;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
Expand Down Expand Up @@ -33,7 +34,7 @@ public StatusPage(PageContext context, WaitingPageObject<T> tab) {
}

public StatusPage(PageContext context, WaitingPageObject<T> tab, long timeout) {
super(context, new WebDriverWait(context.getDriver(), timeout));
super(context, new WebDriverWait(context.getDriver(), Duration.ofSeconds(timeout)));
mustBeVisible = false;
this.tab = tab;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.tle.webtests.framework.PageContext;
import com.tle.webtests.pageobject.AbstractPage;
import java.time.Duration;
import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.Point;
Expand Down Expand Up @@ -39,15 +40,17 @@ public MoodleBasePage(PageContext context, SearchContext searchContext, By loade
}

public MoodleBasePage(
PageContext context, SearchContext searchContext, By loadedBy, int timeOut) {
PageContext context, SearchContext searchContext, By loadedBy, int timeoutSeconds) {
this(
context,
searchContext,
loadedBy,
new WebDriverWait(
context.getDriver(),
timeOut == -1 ? context.getTestConfig().getStandardTimeout() : timeOut,
50));
timeoutSeconds == -1
? context.getTestConfig().getStandardTimeout()
: Duration.ofSeconds(timeoutSeconds),
Duration.ofMillis(50)));
}

public MoodleBasePage(PageContext context, By loadedBy) {
Expand Down
Loading

0 comments on commit 40e3f2b

Please sign in to comment.