Skip to content

Commit 2ea60dc

Browse files
authored
Update Selenium reference to v.4.36.0 (#54) +semver: feature
- Fix javadocs issues Stabilize tests: - Add workaround to handle System UI isn't responding dialog - Wikipedia donate banner handling - set timeout to configure Android task - use different ADO agent and Android images
1 parent ae2f2fb commit 2ea60dc

File tree

9 files changed

+66
-20
lines changed

9 files changed

+66
-20
lines changed

azure-pipelines.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ trigger:
22
- master
33

44
pool:
5-
vmImage: 'macOS-latest'
5+
vmImage: 'macOS-14'
66

77
jobs:
88
- job: sonar
@@ -44,6 +44,7 @@ jobs:
4444
pollingTimeoutSec: '300'
4545

4646
- job: tests
47+
timeoutInMinutes: 60
4748
displayName: Run tests
4849
strategy:
4950
maxParallel: 2
@@ -55,11 +56,12 @@ jobs:
5556

5657
variables:
5758
ANDROID_EMU_NAME: test
58-
ANDROID_SDK_ID: system-images;android-30;google_apis_playstore;x86_64
59+
ANDROID_SDK_ID: system-images;android-29;google_apis_playstore;x86_64
5960

6061
steps:
6162
- task: CmdLine@2
6263
displayName: 'Configure Appium and Android SDK'
64+
timeoutInMinutes: 15
6365
inputs:
6466
script: |
6567
echo "Configuring Environment"

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@
184184
<dependency>
185185
<groupId>com.github.aquality-automation</groupId>
186186
<artifactId>aquality-selenium-core</artifactId>
187-
<version>4.8.0</version>
187+
<version>4.9.0</version>
188188
</dependency>
189189

190190
<dependency>

src/main/java/aquality/appium/mobile/application/IMobileApplication.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
public interface IMobileApplication extends IApplication {
1515
/**
1616
* Provides default timeout for terminate methods.
17+
*
1718
* @return default timeout for waiting until the application is terminated.
1819
*/
1920
static Duration getDefaultTerminateTimeout() {
@@ -67,15 +68,19 @@ default InteractsWithApps appManagement() {
6768

6869
/**
6970
* Execute application script
71+
*
7072
* @param script script
7173
* @param params parameters
74+
* @param <T> type of the result
7275
* @return result of the script execution.
7376
*/
7477
<T> T executeScript(String script, Map<String, Object> params);
7578

7679
/**
7780
* Execute application script
81+
*
7882
* @param script script
83+
* @param <T> type of the result
7984
* @return result of the script execution.
8085
*/
8186
default <T> T executeScript(String script) {

src/main/java/aquality/appium/mobile/screens/IScreen.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,22 @@
1313
public interface IScreen extends IForm {
1414
/**
1515
* Locator for specified screen
16+
*
17+
* @return locator
1618
*/
1719
By getLocator();
1820

1921
/**
2022
* Name of specified screen
23+
*
24+
* @return name
2125
*/
2226
String getName();
2327

2428
/**
2529
* Size of the element described by screen locator.
30+
*
31+
* @return size
2632
*/
2733
Dimension getSize();
2834

src/main/java/aquality/appium/mobile/screens/Screen.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ public abstract class Screen extends Form<IElement> implements IScreen {
3030

3131
/**
3232
* Constructor with parameters
33+
*
34+
* @param locator Locator of the screen
35+
* @param name Name of the screen
3336
*/
3437
protected Screen(By locator, String name) {
3538
super(IElement.class);
@@ -50,7 +53,7 @@ public String getName() {
5053

5154
@Override
5255
public Dimension getSize() {
53-
return screenElement.visual().getSize();
56+
return screenElement.visual().getSize();
5457
}
5558

5659
@Override
@@ -68,7 +71,7 @@ protected IElement getScreenElement() {
6871
return screenElement;
6972
}
7073

71-
protected IElementFactory getElementFactory(){
74+
protected IElementFactory getElementFactory() {
7275
return AqualityServices.getElementFactory();
7376
}
7477

src/main/java/aquality/appium/mobile/screens/screenfactory/IScreenFactory.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@ public interface IScreenFactory {
99

1010
/**
1111
* Returns an implementation of a particular app screen.
12-
* @param <T> Type of desired application screen.
12+
*
13+
* @param <T> Type of desired application screen.
14+
* @param clazz Class of desired application screen.
15+
* @return Instance of desired application screen.
1316
*/
1417
<T extends IScreen> T getScreen(Class<T> clazz);
1518
}

src/test/java/samples/android/nativeapp/apidemos/ApplicationActivity.java

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
package samples.android.nativeapp.apidemos;
22

33
import aquality.appium.mobile.application.AqualityServices;
4+
import aquality.appium.mobile.elements.interfaces.IButton;
45
import aquality.appium.mobile.screens.Screen;
6+
import aquality.selenium.core.configurations.ITimeoutConfiguration;
57
import io.appium.java_client.android.Activity;
68
import org.openqa.selenium.By;
7-
import samples.android.nativeapp.apidemos.screens.AlertsMenuScreen;
8-
import samples.android.nativeapp.apidemos.screens.AndroidScreen;
9-
import samples.android.nativeapp.apidemos.screens.InvokeSearchScreen;
10-
import samples.android.nativeapp.apidemos.screens.ViewControlsScreen;
11-
import samples.android.nativeapp.apidemos.screens.ViewTabsScrollableScreen;
9+
import org.openqa.selenium.WebDriverException;
10+
import samples.android.nativeapp.apidemos.screens.*;
1211

1312
import java.lang.reflect.InvocationTargetException;
13+
import java.util.Collections;
1414

1515
public enum ApplicationActivity {
1616

@@ -38,14 +38,17 @@ public <T extends AndroidScreen> T open() {
3838
public <T extends AndroidScreen> T getScreen() {
3939
try {
4040
return (T) screen.getDeclaredConstructor().newInstance();
41-
} catch (NoSuchMethodException | InstantiationException | IllegalAccessException | InvocationTargetException e) {
41+
} catch (NoSuchMethodException | InstantiationException | IllegalAccessException |
42+
InvocationTargetException e) {
4243
AqualityServices.getLogger().debug(e.getMessage());
4344
throw new IllegalArgumentException("Something went wrong during screen getting");
4445
}
4546
}
4647

4748
private static class ActivityScreen extends AndroidScreen {
4849
private final Activity activity;
50+
private final IButton btnWait = getElementFactory().getButton(By.id("android:id/aerr_wait"), "Wait");
51+
private final IButton btnCloseApp = getElementFactory().getButton(By.id("android:id/aerr_close"), "Close app");
4952

5053
ActivityScreen(Activity activity) {
5154
super(By.name(activity.getAppActivity()), activity.getAppActivity());
@@ -54,6 +57,21 @@ private static class ActivityScreen extends AndroidScreen {
5457

5558
void open() {
5659
startActivity(activity);
60+
// workaround to handle System UI isn't responding dialog
61+
ITimeoutConfiguration timeoutConfiguration = AqualityServices.getConfiguration().getTimeoutConfiguration();
62+
boolean result = AqualityServices.getConditionalWait().waitFor(() ->
63+
{
64+
if (!btnWait.state().waitForDisplayed()) {
65+
return true;
66+
}
67+
btnWait.click();
68+
return btnWait.state().waitForNotDisplayed();
69+
}, timeoutConfiguration.getCommand(),
70+
timeoutConfiguration.getCondition(),
71+
Collections.singletonList(WebDriverException.class));
72+
if (!result) {
73+
btnCloseApp.click();
74+
}
5775
}
5876
}
5977
}

src/test/java/samples/android/web/WebTextBoxTest.java

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
package samples.android.web;
22

33
import aquality.appium.mobile.application.AqualityServices;
4+
import aquality.appium.mobile.elements.interfaces.IButton;
45
import aquality.appium.mobile.elements.interfaces.ITextBox;
6+
import aquality.selenium.core.configurations.ITimeoutConfiguration;
57
import io.appium.java_client.android.AndroidDriver;
68
import org.openqa.selenium.By;
79
import org.openqa.selenium.Keys;
@@ -11,18 +13,24 @@
1113
public class WebTextBoxTest extends AndroidWebTest {
1214

1315
private static final String VALUE_TO_SUBMIT = "quality assurance";
16+
private static final ITextBox txbSearch = AqualityServices.getElementFactory().getTextBox(By.id("searchInput"), "Search");
17+
private static final IButton btnOverlayToggle = AqualityServices.getElementFactory().getButton(By.className("button-collapse"), "Toggle Overlay");
18+
private static final IButton btnCloseBanner = AqualityServices.getElementFactory().getButton(By.className("overlay-banner-close"), "Close banner");
1419

1520
@Test
1621
public void testTextBoxInteraction() {
1722
AqualityServices.getApplication().getDriver().get("https://wikipedia.org");
18-
ITextBox txbSearch = AqualityServices.getElementFactory().getTextBox(By.id("searchInput"), "Search");
1923
txbSearch.state().waitForClickable();
24+
if (btnOverlayToggle.state().isDisplayed()) {
25+
btnOverlayToggle.click();
26+
btnCloseBanner.click();
27+
}
2028
txbSearch.type(VALUE_TO_SUBMIT);
2129
Assert.assertEquals(VALUE_TO_SUBMIT, txbSearch.getValue(), "Submitted value should match to expected");
2230
txbSearch.clear();
2331
Assert.assertEquals("", txbSearch.getValue(), "Value should be cleared");
2432
txbSearch.click();
25-
checkUnfocus(txbSearch);
33+
checkUnfocus();
2634
txbSearch.focus();
2735
Assert.assertTrue(isKeyboardShown(true), "Keyboard should be shown when focus successful");
2836
txbSearch.typeSecret(VALUE_TO_SUBMIT);
@@ -35,17 +43,17 @@ public void testTextBoxInteraction() {
3543
Assert.assertTrue(txbSearch.state().waitForNotDisplayed(), "text field should disappear after the submit");
3644
}
3745

38-
private void checkUnfocus(ITextBox txbSearch) {
46+
private void checkUnfocus() {
3947
txbSearch.unfocus();
4048
Assert.assertFalse(isKeyboardShown(false), "Keyboard should not be shown when unfocus successful");
4149
}
4250

43-
@SuppressWarnings("unchecked")
4451
private boolean isKeyboardShown(boolean expectedStateToWait) {
52+
ITimeoutConfiguration timeoutConfiguration = AqualityServices.getConfiguration().getTimeoutConfiguration();
4553
boolean waitResult = AqualityServices.getConditionalWait()
46-
.waitFor(driver -> ((AndroidDriver)driver).isKeyboardShown() == expectedStateToWait,
47-
AqualityServices.getConfiguration().getTimeoutConfiguration().getCommand(),
48-
AqualityServices.getConfiguration().getTimeoutConfiguration().getPollingInterval().multipliedBy(10),
54+
.waitFor(driver -> ((AndroidDriver) driver).isKeyboardShown() == expectedStateToWait,
55+
timeoutConfiguration.getCommand(),
56+
timeoutConfiguration.getPollingInterval().multipliedBy(10),
4957
String.format("is keyboard shown condition should be %s", expectedStateToWait));
5058
return expectedStateToWait == waitResult;
5159
}

src/test/resources/settings.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
"platformName": "Android",
1212
"automationName": "UIAutomator2",
1313
"eventTimings": true,
14-
"uiautomator2ServerInstallTimeout": 30000
14+
"uiautomator2ServerInstallTimeout": 30000,
15+
"uiautomator2ServerLaunchTimeout": 60000
1516
}
1617
},
1718
"ios": {

0 commit comments

Comments
 (0)