Skip to content

Commit

Permalink
Make all tests pass on Android 6.0 (Marshmallow)
Browse files Browse the repository at this point in the history
  • Loading branch information
iSoron committed Nov 18, 2019
1 parent 1997d94 commit 898a33a
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 57 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public class WidgetTest extends BaseUserInterfaceTest
@Test
public void shouldCreateAndToggleCheckmarkWidget() throws Exception
{
dragCheckmarkWidgetToHomescreen();
dragCheckmarkWidgetToHomeScreen();
clickText("Wake up early");
clickText("Save");
verifyCheckmarkWidgetIsShown();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ public static void verifyDoesNotDisplayText(String text)

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));
} else {
assertTrue(device.wait(Until.hasObject(By.pkg("com.android.chrome")), 5000));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,78 +21,55 @@

import android.support.test.uiautomator.*;

import static android.os.Build.VERSION.SDK_INT;
import static junit.framework.Assert.*;
import static org.isoron.uhabits.BaseUserInterfaceTest.*;

public class WidgetSteps
{
public static void clickCheckmarkWidget() throws Exception
{
device
.findObject(
new UiSelector().resourceId("org.isoron.uhabits:id/imageView"))
.click();
public class WidgetSteps {
public static void clickCheckmarkWidget() throws Exception {
String view_id = "org.isoron.uhabits:id/imageView";
device.findObject(new UiSelector().resourceId(view_id)).click();
}

public static void clickText(String s) throws Exception
{
public static void clickText(String s) throws Exception {
device.findObject(new UiSelector().text(s)).click();
}

public static void clickWidgets() throws Exception
{
device.findObject(new UiSelector().text("WIDGETS")).click();
public static void dragCheckmarkWidgetToHomeScreen() throws Exception {
openWidgetScreen();
dragWidgetToHomeScreen();
}

public static void dragWidgetToHomescreen() throws Exception
{
private static void dragWidgetToHomeScreen() throws Exception {
int height = device.getDisplayHeight();
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"))
.dragTo(width / 2, height / 2, 8);
}

public static void scrollToHabits() throws Exception
{
new UiScrollable(new UiSelector().resourceId(
"com.google.android.apps.nexuslauncher:id/widgets_list_view")).scrollIntoView(
new UiSelector().text("Habits"));

private static void openWidgetScreen() throws Exception {
int h = device.getDisplayHeight();
int w = device.getDisplayWidth();
if (SDK_INT <= 21) {
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
{
assertTrue(device
.findObject(
new UiSelector().resourceId("org.isoron.uhabits:id/imageView"))
.exists());

assertFalse(device
.findObject(new UiSelector().textStartsWith("Habit deleted"))
.exists());
public static void verifyCheckmarkWidgetIsShown() throws Exception {
String view_id = "org.isoron.uhabits:id/imageView";
assertTrue(device.findObject(new UiSelector().resourceId(view_id)).exists());
assertFalse(device.findObject(new UiSelector().textStartsWith("Habit deleted")).exists());
}
}

0 comments on commit 898a33a

Please sign in to comment.