Make all tests pass on Android 6.0 (Marshmallow)

pull/535/head
Alinson S. Xavier 6 years ago
parent 1997d9491b
commit 898a33a754

@ -34,7 +34,7 @@ public class WidgetTest extends BaseUserInterfaceTest
@Test @Test
public void shouldCreateAndToggleCheckmarkWidget() throws Exception public void shouldCreateAndToggleCheckmarkWidget() throws Exception
{ {
dragCheckmarkWidgetToHomescreen(); dragCheckmarkWidgetToHomeScreen();
clickText("Wake up early"); clickText("Wake up early");
clickText("Save"); clickText("Save");
verifyCheckmarkWidgetIsShown(); verifyCheckmarkWidgetIsShown();

@ -139,7 +139,7 @@ public class CommonSteps extends BaseUserInterfaceTest
public static void verifyOpensWebsite(String url) throws Exception public static void verifyOpensWebsite(String url) throws Exception
{ {
if(SDK_INT <= LOLLIPOP) { if(SDK_INT <= 23) {
assertTrue(device.wait(Until.hasObject(By.pkg("com.android.browser")), 5000)); assertTrue(device.wait(Until.hasObject(By.pkg("com.android.browser")), 5000));
} else { } else {
assertTrue(device.wait(Until.hasObject(By.pkg("com.android.chrome")), 5000)); assertTrue(device.wait(Until.hasObject(By.pkg("com.android.chrome")), 5000));

@ -21,78 +21,55 @@ package org.isoron.uhabits.acceptance.steps;
import android.support.test.uiautomator.*; import android.support.test.uiautomator.*;
import static android.os.Build.VERSION.SDK_INT;
import static junit.framework.Assert.*; import static junit.framework.Assert.*;
import static org.isoron.uhabits.BaseUserInterfaceTest.*; import static org.isoron.uhabits.BaseUserInterfaceTest.*;
public class WidgetSteps public class WidgetSteps {
{ public static void clickCheckmarkWidget() throws Exception {
public static void clickCheckmarkWidget() throws Exception String view_id = "org.isoron.uhabits:id/imageView";
{ device.findObject(new UiSelector().resourceId(view_id)).click();
device
.findObject(
new UiSelector().resourceId("org.isoron.uhabits:id/imageView"))
.click();
} }
public static void clickText(String s) throws Exception public static void clickText(String s) throws Exception {
{
device.findObject(new UiSelector().text(s)).click(); device.findObject(new UiSelector().text(s)).click();
} }
public static void clickWidgets() throws Exception public static void dragCheckmarkWidgetToHomeScreen() throws Exception {
{ openWidgetScreen();
device.findObject(new UiSelector().text("WIDGETS")).click(); dragWidgetToHomeScreen();
} }
public static void dragWidgetToHomescreen() throws Exception private static void dragWidgetToHomeScreen() throws Exception {
{
int height = device.getDisplayHeight(); int height = device.getDisplayHeight();
int width = device.getDisplayWidth(); int width = device.getDisplayWidth();
device
.findObject(new UiSelector().text("Checkmark"))
.dragTo(width / 2, height / 2, 8);
}
public static void longPressHomeScreen() throws Exception
{
device.pressHome();
device.waitForIdle();
device
.findObject(new UiSelector().resourceId(
"com.google.android.apps.nexuslauncher:id/workspace"))
.longClick();
}
public static void dragCheckmarkWidgetToHomescreen() throws Exception {
int height = device.getDisplayHeight();
int width = device.getDisplayWidth();
device.pressHome();
device.waitForIdle();
device.findObject(new UiSelector().description("Apps")).click();
device.findObject(new UiSelector().description("Apps")).click();
device.findObject(new UiSelector().description("Widgets")).click();
device.drag(width/2, height/2, 0, height/2, 8);
device.findObject(new UiSelector().text("Checkmark")) device.findObject(new UiSelector().text("Checkmark"))
.dragTo(width / 2, height / 2, 8); .dragTo(width / 2, height / 2, 8);
} }
public static void scrollToHabits() throws Exception private static void openWidgetScreen() throws Exception {
{ int h = device.getDisplayHeight();
new UiScrollable(new UiSelector().resourceId( int w = device.getDisplayWidth();
"com.google.android.apps.nexuslauncher:id/widgets_list_view")).scrollIntoView( if (SDK_INT <= 21) {
new UiSelector().text("Habits")); device.pressHome();
device.waitForIdle();
device.findObject(new UiSelector().description("Apps")).click();
device.findObject(new UiSelector().description("Apps")).click();
device.findObject(new UiSelector().description("Widgets")).click();
} else {
String list_id = "com.android.launcher3:id/widgets_list_view";
device.pressHome();
device.waitForIdle();
device.drag(w / 2, h / 2, w / 2, h / 2, 8);
device.findObject(new UiSelector().text("Widgets")).click();
new UiScrollable(new UiSelector().resourceId(list_id))
.scrollIntoView(new UiSelector().text("Checkmark"));
}
} }
public static void verifyCheckmarkWidgetIsShown() throws Exception public static void verifyCheckmarkWidgetIsShown() throws Exception {
{ String view_id = "org.isoron.uhabits:id/imageView";
assertTrue(device assertTrue(device.findObject(new UiSelector().resourceId(view_id)).exists());
.findObject( assertFalse(device.findObject(new UiSelector().textStartsWith("Habit deleted")).exists());
new UiSelector().resourceId("org.isoron.uhabits:id/imageView"))
.exists());
assertFalse(device
.findObject(new UiSelector().textStartsWith("Habit deleted"))
.exists());
} }
} }

Loading…
Cancel
Save