Skip to content
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

Fix issues with running the integration tests in different environments #2503

Merged
merged 3 commits into from
Feb 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/androidTest/java/de/blau/android/IntentsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ public void rcWithZoom() {
RemoteControlUrlActivity rc = (RemoteControlUrlActivity) instrumentation.waitForMonitorWithTimeout(rcMonitor, 60000);
assertNotNull(rc);
takeRequests();
TestUtils.clickAwayTip(device, main);
assertNotNull(App.getDelegator().getOsmElement(Node.NAME, 101792984L));
assertTrue(18 <= main.getMap().getZoomLevel());
assertEquals(101792984L, App.getLogic().getSelectedNode().getOsmId());
Expand All @@ -229,7 +230,7 @@ private void takeRequests() {
mockServerNotes.server().takeRequest(10L, TimeUnit.SECONDS);
mockServerOsmose.server().takeRequest(10L, TimeUnit.SECONDS);
// processing the downloads takes time
TestUtils.sleep(30000);
TestUtils.sleep(10000);
} catch (InterruptedException e) {
fail(e.getMessage());
}
Expand Down
79 changes: 44 additions & 35 deletions src/androidTest/java/de/blau/android/KeyboardTest.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
package de.blau.android;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;

import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
Expand Down Expand Up @@ -68,6 +72,11 @@ public void setup() {
TestUtils.zoomToNullIsland(logic, map);
TestUtils.loadTestData(main, "test2.osm");
TestUtils.stopEasyEdit(main);
map.getDataLayer().setVisible(true);
TestUtils.zoomToLevel(device, main, 20);
map.invalidate();
TestUtils.unlock(device);
device.waitForWindowUpdate(null, 2000);
}

/**
Expand Down Expand Up @@ -97,7 +106,7 @@ public void zoomAndPan() {

device.pressKeyCode(KeyEvent.KEYCODE_PLUS);
TestUtils.sleep();
Assert.assertNotEquals(viewBox, App.getLogic().getViewBox());
assertNotEquals(viewBox, App.getLogic().getViewBox());

device.pressKeyCode(KeyEvent.KEYCODE_MINUS);
TestUtils.sleep();
Expand All @@ -112,41 +121,41 @@ public void zoomAndPan() {
device.pressKeyCode(KeyEvent.KEYCODE_VOLUME_UP);
TestUtils.sleep();
boxIsEqual(viewBox, App.getLogic().getViewBox());

// volume keys should zoom
prefs.setZoomWithKeys(true);
device.pressKeyCode(KeyEvent.KEYCODE_VOLUME_DOWN);
TestUtils.sleep();
Assert.assertNotEquals(viewBox, App.getLogic().getViewBox());
assertNotEquals(viewBox, App.getLogic().getViewBox());

device.pressKeyCode(KeyEvent.KEYCODE_VOLUME_UP);
TestUtils.sleep();
boxIsEqual(viewBox, App.getLogic().getViewBox());

device.pressDPadRight();
TestUtils.sleep();
Assert.assertNotEquals(viewBox, App.getLogic().getViewBox());
assertNotEquals(viewBox, App.getLogic().getViewBox());
device.pressDPadLeft();
TestUtils.sleep();
boxIsEqual(viewBox, App.getLogic().getViewBox());

device.pressDPadLeft();
TestUtils.sleep();
Assert.assertNotEquals(viewBox, App.getLogic().getViewBox());
assertNotEquals(viewBox, App.getLogic().getViewBox());
device.pressDPadRight();
TestUtils.sleep();
boxIsEqual(viewBox, App.getLogic().getViewBox());

device.pressDPadUp();
TestUtils.sleep();
Assert.assertNotEquals(viewBox, App.getLogic().getViewBox());
assertNotEquals(viewBox, App.getLogic().getViewBox());
device.pressDPadDown();
TestUtils.sleep();
boxIsEqual(viewBox, App.getLogic().getViewBox());

device.pressDPadDown();
TestUtils.sleep();
Assert.assertNotEquals(viewBox, App.getLogic().getViewBox());
assertNotEquals(viewBox, App.getLogic().getViewBox());
device.pressDPadUp();
TestUtils.sleep();
boxIsEqual(viewBox, App.getLogic().getViewBox());
Expand All @@ -166,57 +175,57 @@ public void way() {
TestUtils.unlock(device);

TestUtils.clickAtCoordinates(device, map, 8.3893820, 47.3895626, true);
TestUtils.clickText(device, true, context.getString(R.string.okay), true, false); // Tip
Assert.assertTrue(TestUtils.clickText(device, false, "↓ Path", false, false));
TestUtils.clickAwayTip(device, context);
assertTrue(TestUtils.clickTextContains(device, "Path", true, 5000));
Way way = App.getLogic().getSelectedWay();
Assert.assertNotNull(way);
Assert.assertEquals(104148456L, way.getOsmId());
Assert.assertTrue(TestUtils.findText(device, false, WAY_SELECTED));
assertNotNull(way);
assertEquals(104148456L, way.getOsmId());
assertTrue(TestUtils.findText(device, false, WAY_SELECTED));

ActivityMonitor monitor = instrumentation.addMonitor(PropertyEditorActivity.class.getName(), null, false);

device.pressKeyCode(KeyEvent.KEYCODE_E, KeyEvent.META_CTRL_ON);

Activity propertyEditor = instrumentation.waitForMonitorWithTimeout(monitor, 30000);
Assert.assertTrue(propertyEditor instanceof PropertyEditorActivity);
assertTrue(propertyEditor instanceof PropertyEditorActivity);
instrumentation.removeMonitor(monitor);

Assert.assertTrue(TestUtils.clickHome(device, true));
Assert.assertTrue(TestUtils.findText(device, false, WAY_SELECTED));
assertTrue(TestUtils.clickHome(device, true));
assertTrue(TestUtils.findText(device, false, WAY_SELECTED));

device.pressKeyCode(KeyEvent.KEYCODE_R, KeyEvent.META_CTRL_ON);
Assert.assertTrue(TestUtils.textGone(device, WAY_SELECTED, 1000));
assertTrue(TestUtils.textGone(device, WAY_SELECTED, 1000));

Assert.assertTrue(TestUtils.clickText(device, false, "Delete Way", true));
assertTrue(TestUtils.clickText(device, false, "Delete Way", true));

Assert.assertEquals(OsmElement.STATE_DELETED, way.getState());
assertEquals(OsmElement.STATE_DELETED, way.getState());
device.pressKeyCode(KeyEvent.KEYCODE_U, KeyEvent.META_CTRL_ON);
TestUtils.sleep();
Assert.assertEquals(OsmElement.STATE_UNCHANGED, way.getState());
assertEquals(OsmElement.STATE_UNCHANGED, way.getState());
TestUtils.clickText(device, false, "Ok", false); // in case we get a tip

TestUtils.clickAtCoordinates(device, map, 8.3893820, 47.3895626, true);
Assert.assertTrue(TestUtils.clickText(device, false, "↓ Path", false, false));
assertTrue(TestUtils.clickText(device, false, "↓ Path", false, false));
way = App.getLogic().getSelectedWay();
Assert.assertNotNull(way);
Assert.assertEquals(104148456L, way.getOsmId());
Assert.assertTrue(TestUtils.findText(device, false, WAY_SELECTED));
assertNotNull(way);
assertEquals(104148456L, way.getOsmId());
assertTrue(TestUtils.findText(device, false, WAY_SELECTED));

device.pressKeyCode(KeyEvent.KEYCODE_C, KeyEvent.META_CTRL_ON);
TestUtils.sleep();
device.pressKeyCode(KeyEvent.KEYCODE_V, KeyEvent.META_CTRL_ON);
way = App.getLogic().getSelectedWay();
Assert.assertNotNull(way);
Assert.assertTrue(way.getOsmId() < 0);
assertNotNull(way);
assertTrue(way.getOsmId() < 0);

monitor = instrumentation.addMonitor(HelpViewer.class.getName(), null, false);
device.pressKeyCode(KeyEvent.KEYCODE_H, KeyEvent.META_CTRL_ON);
Activity helpViewer = instrumentation.waitForMonitorWithTimeout(monitor, 30000);
Assert.assertTrue(helpViewer instanceof HelpViewer);
assertTrue(helpViewer instanceof HelpViewer);
instrumentation.removeMonitor(monitor);
Assert.assertTrue(TestUtils.findText(device, false, WAY_SELECTED));
assertTrue(TestUtils.findText(device, false, WAY_SELECTED));
device.pressBack();
Assert.assertTrue(TestUtils.findText(device, false, WAY_SELECTED));
assertTrue(TestUtils.findText(device, false, WAY_SELECTED));
TestUtils.clickUp(device);
}

Expand All @@ -230,9 +239,9 @@ public void help() {
ActivityMonitor monitor = instrumentation.addMonitor(HelpViewer.class.getName(), null, false);
device.pressKeyCode(KeyEvent.KEYCODE_H, KeyEvent.META_CTRL_ON);
Activity helpViewer = instrumentation.waitForMonitorWithTimeout(monitor, 30000);
Assert.assertTrue(helpViewer instanceof HelpViewer);
assertTrue(helpViewer instanceof HelpViewer);
instrumentation.removeMonitor(monitor);
Assert.assertTrue(TestUtils.findText(device, false, "Main Vespucci Screen", 2000));
assertTrue(TestUtils.findText(device, false, "Main Vespucci Screen", 2000));
device.pressBack();
device.pressKeyCode(KeyEvent.KEYCODE_X, KeyEvent.META_CTRL_ON);
}
Expand All @@ -244,9 +253,9 @@ public void help() {
* @param box2 second box
*/
private void boxIsEqual(@NonNull ViewBox box, @NonNull ViewBox box2) {
Assert.assertEquals(box.getLeft(), box2.getLeft(), 10);
Assert.assertEquals(box.getRight(), box2.getRight(), 10);
Assert.assertEquals(box.getBottom(), box2.getBottom(), 10);
Assert.assertEquals(box.getTop(), box2.getTop(), 10);
assertEquals(box.getLeft(), box2.getLeft(), 10);
assertEquals(box.getRight(), box2.getRight(), 10);
assertEquals(box.getBottom(), box2.getBottom(), 10);
assertEquals(box.getTop(), box2.getTop(), 10);
}
}
2 changes: 1 addition & 1 deletion src/androidTest/java/de/blau/android/SplashTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public void splash() {
Intent intent = new Intent(Intent.ACTION_MAIN);
Splash splash = mActivityRule.launchActivity(intent);
assertNotNull(splash);
Main main = (Main) instrumentation.waitForMonitorWithTimeout(monitor, 5000); // wait for main
Main main = (Main) instrumentation.waitForMonitorWithTimeout(monitor, 60000); // wait for main
assertNotNull(main);
}
}
30 changes: 29 additions & 1 deletion src/androidTest/java/de/blau/android/TestUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -732,6 +732,19 @@ public static boolean longClickText(@NonNull UiDevice device, @NonNull String te
}
}

/**
* Click a text on screen
*
* @param device UiDevice object
* @param text text to search (case insensitive, uses textStartsWith)
* @param waitForNewWindow set the wait for new window flag if true
* @param wait how long to wait for the object to appear in ms
* @return true if successful
*/
public static boolean clickTextContains(@NonNull UiDevice device, @NonNull String text, boolean waitForNewWindow, long wait) {
return clickTextContains(device, false, text, waitForNewWindow, wait);
}

/**
* Click a text on screen (case sensitive, any position in a string)
*
Expand All @@ -742,6 +755,20 @@ public static boolean longClickText(@NonNull UiDevice device, @NonNull String te
* @return true if successful
*/
public static boolean clickTextContains(@NonNull UiDevice device, boolean clickable, @NonNull String text, boolean waitForNewWindow) {
return clickTextContains(device, clickable, text, waitForNewWindow, 500);
}

/**
* Click a text on screen (case sensitive, any position in a string)
*
* @param device UiDevice object
* @param clickable clickable if true the search will be restricted to clickable objects
* @param text text to search (case sensitive, uses textContains)
* @param waitForNewWindow set the wait for new window flag if true
* @param wait how long to wait for the object to appear in ms
* @return true if successful
*/
public static boolean clickTextContains(@NonNull UiDevice device, boolean clickable, @NonNull String text, boolean waitForNewWindow, long wait) {
Log.w(DEBUG_TAG, "Searching for object with " + text);
//
BySelector bySelector = null;
Expand All @@ -754,7 +781,7 @@ public static boolean clickTextContains(@NonNull UiDevice device, boolean clicka
bySelector = By.textContains(text);
uiSelector = new UiSelector().textContains(text);
}
device.wait(Until.findObject(bySelector), 500);
device.wait(Until.findObject(bySelector), wait);
UiObject button = device.findObject(uiSelector);
if (button.exists()) {
try {
Expand Down Expand Up @@ -1557,6 +1584,7 @@ public static boolean findNotification(@NonNull UiDevice device, @NonNull String
found = device.wait(Until.hasObject(By.textContains(message)), 5000);
}
}
scrollToStartsWith("CLEAR ALL", false);
UiObject2 clearAll = device.findObject(By.text(Pattern.compile("CLEAR ALL", Pattern.CASE_INSENSITIVE)));
if (clearAll != null) {
clearAll.click();
Expand Down
13 changes: 9 additions & 4 deletions src/androidTest/java/de/blau/android/UndoRedoTest.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package de.blau.android;

import static org.junit.Assert.assertNotNull;

import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
Expand Down Expand Up @@ -58,6 +60,7 @@ public void setup() {
map.getViewBox().fitToBoundingBox(map, map.getDataLayer().getExtent());
logic.updateStyle();
map.getDataLayer().setVisible(true);
TestUtils.zoomToLevel(device, main, 20);
map.invalidate();
TestUtils.unlock(device);
device.waitForWindowUpdate(null, 2000);
Expand All @@ -78,11 +81,13 @@ public void teardown() {
// @SdkSuppress(minSdkVersion = 26)
@Test
public void dialog() {
TestUtils.clickAtCoordinates(device, map, 8.38782, 47.390339, true);
TestUtils.clickText(device, true, context.getString(R.string.okay), true, false); // Tip
TestUtils.clickText(device, false, "↓ Toilets", false, false);
Node node = (Node) App.getDelegator().getOsmElement(Node.NAME, 3465444349L);
assertNotNull(node);
TestUtils.clickAtCoordinates(device, map, node.getLon(), node.getLat(), true);
TestUtils.clickAwayTip(device, context);
TestUtils.clickTextContains(device, "Toilets", false, 5000);
TestUtils.sleep();
Node node = App.getLogic().getSelectedNode();
node = App.getLogic().getSelectedNode();
Assert.assertNotNull(node);
Assert.assertEquals(3465444349L, node.getOsmId());
Assert.assertTrue(TestUtils.findText(device, false, context.getString(R.string.actionmode_nodeselect)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public void teardown() {
@Test
public void newAddressLongClick() {
TestUtils.unlock(device);
TestUtils.switchSimpleMode(device, main, true);
TestUtils.switchSimpleMode(device, main, false);
map.getDataLayer().setVisible(true);
TestUtils.zoomToLevel(device, main, 21);
TestUtils.longClickAtCoordinates(device, map, 8.3893454, 47.3901898, true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ public void selectNodes() {
TestUtils.sleep(2000);
TestUtils.clickAtCoordinates(device, map, 8.38782, 47.390339, true);
TestUtils.clickText(device, true, context.getString(R.string.okay), true, false); // Tip
TestUtils.findText(device, false, " Toilets", 10000);
assertTrue(TestUtils.clickText(device, false, " Toilets", true, false));
TestUtils.findText(device, false, " Toilets", 10000, true);
assertTrue(TestUtils.clickTextContains(device, false, " Toilets", true));
Node node = App.getLogic().getSelectedNode();
assertNotNull(node);
assertEquals(3465444349L, node.getOsmId());
Expand All @@ -103,7 +103,7 @@ public void selectNodes() {
// double clicking doesn't currently work reliably in tests TestUtils.doubleClickAtCoordinates(device, map,
// 8.3877977, 47.3897371, true); // NOSONAR
TestUtils.clickAtCoordinates(device, map, 8.3877977, 47.3897371, true);
assertTrue(TestUtils.clickText(device, false, " Excrement", false, false));
assertTrue(TestUtils.clickTextContains(device, false, " Excrement", false));
assertEquals(2, logic.getSelectedNodes().size());
TestUtils.zoomToLevel(device, main, 22);
TestUtils.drag(device, map, 8.3877977, 47.3897371, 8.3879, 47.38967, true, 100);
Expand All @@ -128,7 +128,7 @@ public void selectAndMergeWays() {
TestUtils.zoomToLevel(device, main, 21);
TestUtils.clickAtCoordinates(device, map, 8.3893820, 47.3895626, true);
TestUtils.clickText(device, true, context.getString(R.string.okay), true, false); // Tip
assertTrue(TestUtils.clickText(device, false, " Path", false, false));
assertTrue(TestUtils.clickTextContains(device, false, " Path", false));
assertTrue(TestUtils.findText(device, false, context.getString(R.string.actionmode_wayselect)));
Way way = App.getLogic().getSelectedWay();
assertNotNull(way);
Expand All @@ -139,7 +139,7 @@ public void selectAndMergeWays() {
TestUtils.clickAtCoordinates(device, map, 8.3899934, 47.3898778, true);
TestUtils.textGone(device, context.getString(R.string.menu_split), 1);
TestUtils.clickAtCoordinates(device, map, 8.3899204, 47.3898603, true);
assertTrue(TestUtils.clickText(device, false, " Path", false, false));
assertTrue(TestUtils.clickTextContains(device, false, " Path", false));
assertTrue(TestUtils.findText(device, false, context.getString(R.string.actionmode_wayselect)));
assertTrue(TestUtils.clickOverflowButton(device));
TestUtils.scrollTo(context.getString(R.string.menu_extend_selection), false);
Expand Down
Loading
Loading