From 46726c6e6d8b7a448379bf6db6e073f7fa2d6396 Mon Sep 17 00:00:00 2001 From: rachelmcr Date: Mon, 15 May 2017 22:26:36 +0100 Subject: [PATCH 01/10] Add bold text formatting test --- .../aztec/demo/SimpleTextFormattingTests.java | 49 +++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 app/src/androidTest/java/org/wordpress/aztec/demo/SimpleTextFormattingTests.java diff --git a/app/src/androidTest/java/org/wordpress/aztec/demo/SimpleTextFormattingTests.java b/app/src/androidTest/java/org/wordpress/aztec/demo/SimpleTextFormattingTests.java new file mode 100644 index 000000000..c9416cd77 --- /dev/null +++ b/app/src/androidTest/java/org/wordpress/aztec/demo/SimpleTextFormattingTests.java @@ -0,0 +1,49 @@ +package org.wordpress.aztec.demo; + +import android.support.test.espresso.ViewInteraction; +import android.support.test.rule.ActivityTestRule; +import android.support.test.runner.AndroidJUnit4; +import android.test.suitebuilder.annotation.LargeTest; +import org.junit.Rule; +import org.junit.Test; +import org.junit.runner.RunWith; + +import static android.support.test.espresso.Espresso.onView; +import static android.support.test.espresso.action.ViewActions.click; +import static android.support.test.espresso.action.ViewActions.closeSoftKeyboard; +import static android.support.test.espresso.action.ViewActions.typeText; +import static android.support.test.espresso.assertion.ViewAssertions.matches; +import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed; +import static android.support.test.espresso.matcher.ViewMatchers.withId; +import static android.support.test.espresso.matcher.ViewMatchers.withText; +import static org.hamcrest.Matchers.allOf; + +@LargeTest +@RunWith(AndroidJUnit4.class) +public class SimpleTextFormattingTests { + + @Rule + public ActivityTestRule mActivityTestRule = new ActivityTestRule<>(MainActivity.class); + + @Test + public void testSimpleBoldFormatting() { + // Focus on visual editor + ViewInteraction aztecText = onView(withId(R.id.aztec)); + aztecText.perform(click()); + + // Enable bold formatting + ViewInteraction boldButton = onView(withId(R.id.format_bar_button_bold)); + boldButton.perform(click()); + + // Type bold text + aztecText.perform(typeText("hello world"), closeSoftKeyboard()); + + // Switch to HTML view + ViewInteraction htmlButton = onView(withId(R.id.format_bar_button_html)); + htmlButton.perform(click()); + + // Assert that text has bold tags + ViewInteraction sourceText = onView(allOf(withId(R.id.source), isDisplayed())); + sourceText.check(matches(withText("hello world"))); + } +} From f885132d240971c9fe59ee63c1bf940b54e1d65c Mon Sep 17 00:00:00 2001 From: rachelmcr Date: Tue, 16 May 2017 19:54:07 +0100 Subject: [PATCH 02/10] Reverse test to enter HTML and check for enabled format button --- .../aztec/demo/SimpleTextFormattingTests.java | 29 +++++++------------ 1 file changed, 11 insertions(+), 18 deletions(-) diff --git a/app/src/androidTest/java/org/wordpress/aztec/demo/SimpleTextFormattingTests.java b/app/src/androidTest/java/org/wordpress/aztec/demo/SimpleTextFormattingTests.java index c9416cd77..d16312d0f 100644 --- a/app/src/androidTest/java/org/wordpress/aztec/demo/SimpleTextFormattingTests.java +++ b/app/src/androidTest/java/org/wordpress/aztec/demo/SimpleTextFormattingTests.java @@ -10,13 +10,10 @@ import static android.support.test.espresso.Espresso.onView; import static android.support.test.espresso.action.ViewActions.click; -import static android.support.test.espresso.action.ViewActions.closeSoftKeyboard; import static android.support.test.espresso.action.ViewActions.typeText; import static android.support.test.espresso.assertion.ViewAssertions.matches; -import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed; +import static android.support.test.espresso.matcher.ViewMatchers.isEnabled; import static android.support.test.espresso.matcher.ViewMatchers.withId; -import static android.support.test.espresso.matcher.ViewMatchers.withText; -import static org.hamcrest.Matchers.allOf; @LargeTest @RunWith(AndroidJUnit4.class) @@ -27,23 +24,19 @@ public class SimpleTextFormattingTests { @Test public void testSimpleBoldFormatting() { - // Focus on visual editor - ViewInteraction aztecText = onView(withId(R.id.aztec)); - aztecText.perform(click()); - - // Enable bold formatting - ViewInteraction boldButton = onView(withId(R.id.format_bar_button_bold)); - boldButton.perform(click()); - - // Type bold text - aztecText.perform(typeText("hello world"), closeSoftKeyboard()); - // Switch to HTML view ViewInteraction htmlButton = onView(withId(R.id.format_bar_button_html)); htmlButton.perform(click()); - // Assert that text has bold tags - ViewInteraction sourceText = onView(allOf(withId(R.id.source), isDisplayed())); - sourceText.check(matches(withText("hello world"))); + // Type text with bold tags + ViewInteraction htmlViewEditText = onView(withId(R.id.source)); + htmlViewEditText.perform(typeText("hello world")); + + // Switch back to visual view + htmlButton.perform(click()); + + // Assert that bold button is enabled + ViewInteraction boldButton = onView(withId(R.id.format_bar_button_bold)); + boldButton.check(matches(isEnabled())); } } From f8af68d31e63d4340ffd4cd290a3839f3d92bacf Mon Sep 17 00:00:00 2001 From: rachelmcr Date: Tue, 16 May 2017 20:57:35 +0100 Subject: [PATCH 03/10] Add helper methods --- .../aztec/demo/SimpleTextFormattingTests.java | 20 ++++---------- .../org/wordpress/aztec/demo/TestUtils.java | 27 +++++++++++++++++++ 2 files changed, 32 insertions(+), 15 deletions(-) create mode 100644 app/src/androidTest/java/org/wordpress/aztec/demo/TestUtils.java diff --git a/app/src/androidTest/java/org/wordpress/aztec/demo/SimpleTextFormattingTests.java b/app/src/androidTest/java/org/wordpress/aztec/demo/SimpleTextFormattingTests.java index d16312d0f..886f94503 100644 --- a/app/src/androidTest/java/org/wordpress/aztec/demo/SimpleTextFormattingTests.java +++ b/app/src/androidTest/java/org/wordpress/aztec/demo/SimpleTextFormattingTests.java @@ -9,11 +9,11 @@ import org.junit.runner.RunWith; import static android.support.test.espresso.Espresso.onView; -import static android.support.test.espresso.action.ViewActions.click; -import static android.support.test.espresso.action.ViewActions.typeText; import static android.support.test.espresso.assertion.ViewAssertions.matches; -import static android.support.test.espresso.matcher.ViewMatchers.isEnabled; +import static android.support.test.espresso.matcher.ViewMatchers.isChecked; +import static android.support.test.espresso.matcher.ViewMatchers.isNotChecked; import static android.support.test.espresso.matcher.ViewMatchers.withId; +import static org.wordpress.aztec.demo.TestUtils.enterHTML; @LargeTest @RunWith(AndroidJUnit4.class) @@ -24,19 +24,9 @@ public class SimpleTextFormattingTests { @Test public void testSimpleBoldFormatting() { - // Switch to HTML view - ViewInteraction htmlButton = onView(withId(R.id.format_bar_button_html)); - htmlButton.perform(click()); + enterHTML("hello world"); - // Type text with bold tags - ViewInteraction htmlViewEditText = onView(withId(R.id.source)); - htmlViewEditText.perform(typeText("hello world")); - - // Switch back to visual view - htmlButton.perform(click()); - - // Assert that bold button is enabled ViewInteraction boldButton = onView(withId(R.id.format_bar_button_bold)); - boldButton.check(matches(isEnabled())); + boldButton.check(matches(isChecked())); } } diff --git a/app/src/androidTest/java/org/wordpress/aztec/demo/TestUtils.java b/app/src/androidTest/java/org/wordpress/aztec/demo/TestUtils.java new file mode 100644 index 000000000..d9c3d5842 --- /dev/null +++ b/app/src/androidTest/java/org/wordpress/aztec/demo/TestUtils.java @@ -0,0 +1,27 @@ +package org.wordpress.aztec.demo; + +import android.support.test.espresso.ViewInteraction; + +import static android.support.test.espresso.Espresso.onView; +import static android.support.test.espresso.action.ViewActions.click; +import static android.support.test.espresso.action.ViewActions.typeText; +import static android.support.test.espresso.matcher.ViewMatchers.withId; + +/** + * Test utilities to be used with instrumentation tests. + */ +public class TestUtils { + public static void toggleHTMLView() { + ViewInteraction htmlButton = onView(withId(R.id.format_bar_button_html)); + htmlButton.perform(click()); + } + + public static void enterHTML(String text) { + toggleHTMLView(); + + ViewInteraction htmlViewEditText = onView(withId(R.id.source)); + htmlViewEditText.perform(typeText(text)); + + toggleHTMLView(); + } +} From 92e7a84d0d6047c60353c98026d83677c9dde096 Mon Sep 17 00:00:00 2001 From: rachelmcr Date: Tue, 16 May 2017 21:00:05 +0100 Subject: [PATCH 04/10] Add check for disabled format button at start of test --- .../org/wordpress/aztec/demo/SimpleTextFormattingTests.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/src/androidTest/java/org/wordpress/aztec/demo/SimpleTextFormattingTests.java b/app/src/androidTest/java/org/wordpress/aztec/demo/SimpleTextFormattingTests.java index 886f94503..64e575a89 100644 --- a/app/src/androidTest/java/org/wordpress/aztec/demo/SimpleTextFormattingTests.java +++ b/app/src/androidTest/java/org/wordpress/aztec/demo/SimpleTextFormattingTests.java @@ -24,9 +24,11 @@ public class SimpleTextFormattingTests { @Test public void testSimpleBoldFormatting() { + ViewInteraction boldButton = onView(withId(R.id.format_bar_button_bold)); + boldButton.check(matches(isNotChecked())); + enterHTML("hello world"); - ViewInteraction boldButton = onView(withId(R.id.format_bar_button_bold)); boldButton.check(matches(isChecked())); } } From 3ca2d85ee87d981bd508fd23d8e30996587e6d80 Mon Sep 17 00:00:00 2001 From: rachelmcr Date: Thu, 18 May 2017 10:56:12 +0100 Subject: [PATCH 05/10] Add simple formatting tests --- .../aztec/demo/SimpleTextFormattingTests.java | 252 +++++++++++++++++- .../org/wordpress/aztec/demo/TestUtils.java | 50 +++- 2 files changed, 281 insertions(+), 21 deletions(-) diff --git a/app/src/androidTest/java/org/wordpress/aztec/demo/SimpleTextFormattingTests.java b/app/src/androidTest/java/org/wordpress/aztec/demo/SimpleTextFormattingTests.java index 64e575a89..b61ff7cdf 100644 --- a/app/src/androidTest/java/org/wordpress/aztec/demo/SimpleTextFormattingTests.java +++ b/app/src/androidTest/java/org/wordpress/aztec/demo/SimpleTextFormattingTests.java @@ -1,19 +1,46 @@ package org.wordpress.aztec.demo; -import android.support.test.espresso.ViewInteraction; import android.support.test.rule.ActivityTestRule; import android.support.test.runner.AndroidJUnit4; import android.test.suitebuilder.annotation.LargeTest; + import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; -import static android.support.test.espresso.Espresso.onView; +import static android.support.test.espresso.action.ViewActions.click; +import static android.support.test.espresso.action.ViewActions.scrollTo; +import static android.support.test.espresso.action.ViewActions.typeText; +import static android.support.test.espresso.action.ViewActions.typeTextIntoFocusedView; import static android.support.test.espresso.assertion.ViewAssertions.matches; -import static android.support.test.espresso.matcher.ViewMatchers.isChecked; -import static android.support.test.espresso.matcher.ViewMatchers.isNotChecked; -import static android.support.test.espresso.matcher.ViewMatchers.withId; -import static org.wordpress.aztec.demo.TestUtils.enterHTML; +import static android.support.test.espresso.matcher.ViewMatchers.withText; +import static org.wordpress.aztec.demo.TestUtils.aztecText; +import static org.wordpress.aztec.demo.TestUtils.boldButton; +import static org.wordpress.aztec.demo.TestUtils.formattedText; +import static org.wordpress.aztec.demo.TestUtils.headingButton; +import static org.wordpress.aztec.demo.TestUtils.headingFiveSelector; +import static org.wordpress.aztec.demo.TestUtils.headingFourSelector; +import static org.wordpress.aztec.demo.TestUtils.headingOneSelector; +import static org.wordpress.aztec.demo.TestUtils.headingSixSelector; +import static org.wordpress.aztec.demo.TestUtils.headingThreeSelector; +import static org.wordpress.aztec.demo.TestUtils.headingTwoSelector; +import static org.wordpress.aztec.demo.TestUtils.italicButton; +import static org.wordpress.aztec.demo.TestUtils.linkButton; +import static org.wordpress.aztec.demo.TestUtils.linkOKButton; +import static org.wordpress.aztec.demo.TestUtils.linkTextField; +import static org.wordpress.aztec.demo.TestUtils.linkURLField; +import static org.wordpress.aztec.demo.TestUtils.linkURLText; +import static org.wordpress.aztec.demo.TestUtils.moreButton; +import static org.wordpress.aztec.demo.TestUtils.orderedListButton; +import static org.wordpress.aztec.demo.TestUtils.pageButton; +import static org.wordpress.aztec.demo.TestUtils.preSelector; +import static org.wordpress.aztec.demo.TestUtils.quoteButton; +import static org.wordpress.aztec.demo.TestUtils.sourceText; +import static org.wordpress.aztec.demo.TestUtils.strikethroughButton; +import static org.wordpress.aztec.demo.TestUtils.toggleHTMLView; +import static org.wordpress.aztec.demo.TestUtils.underlineButton; +import static org.wordpress.aztec.demo.TestUtils.unformattedText; +import static org.wordpress.aztec.demo.TestUtils.unorderedListButton; @LargeTest @RunWith(AndroidJUnit4.class) @@ -24,11 +51,214 @@ public class SimpleTextFormattingTests { @Test public void testSimpleBoldFormatting() { - ViewInteraction boldButton = onView(withId(R.id.format_bar_button_bold)); - boldButton.check(matches(isNotChecked())); + // Enter text in visual editor with formatting + aztecText.perform(typeText(unformattedText)); + boldButton.perform(click()); + aztecText.perform(typeText(formattedText)); + + // Check that HTML formatting tags were correctly added + toggleHTMLView(); + sourceText.check(matches(withText(unformattedText + "" + formattedText + ""))); + } + + @Test + public void testSimpleItalicFormatting() { + // Enter text in visual editor with formatting + aztecText.perform(typeText(unformattedText)); + italicButton.perform(click()); + aztecText.perform(typeText(formattedText)); + + // Check that HTML formatting tags were correctly added + toggleHTMLView(); + sourceText.check(matches(withText(unformattedText + "" + formattedText + ""))); + } + + @Test + public void testSimpleStrikethroughFormatting() { + // Enter text in visual editor with formatting + aztecText.perform(typeText(unformattedText)); + strikethroughButton.perform(click()); + aztecText.perform(typeText(formattedText)); + + // Check that HTML formatting tags were correctly added + toggleHTMLView(); + sourceText.check(matches(withText(unformattedText + "" + formattedText + ""))); + } + + @Test + public void testSimpleUnderlineFormatting() { + // Enter text in visual editor with formatting + aztecText.perform(typeText(unformattedText)); + underlineButton.perform(click()); + aztecText.perform(typeText(formattedText)); + + // Check that HTML formatting tags were correctly added + toggleHTMLView(); + sourceText.check(matches(withText(unformattedText + "" + formattedText + ""))); + } + + @Test + public void testSimpleQuoteFormatting() { + // Enter text in visual editor with formatting + aztecText.perform(typeText(unformattedText + "\n")); + quoteButton.perform(click()); + aztecText.perform(typeText(formattedText)); + + // Check that HTML formatting tags were correctly added + toggleHTMLView(); + sourceText.check(matches(withText(unformattedText + "\n
" + formattedText + "
"))); + } + + @Test + public void testSimpleUnorderedListFormatting() { + // Enter text in visual editor with formatting + aztecText.perform(typeText(unformattedText + "\n")); + unorderedListButton.perform(scrollTo(), click()); + aztecText.perform(typeText(formattedText)); + + // Check that HTML formatting tags were correctly added + toggleHTMLView(); + sourceText.check(matches(withText(unformattedText + "\n
    \n\t
  • " + formattedText + "
  • \n
"))); + } + + @Test + public void testSimpleOrderedListFormatting() { + // Enter text in visual editor with formatting + aztecText.perform(typeText(unformattedText + "\n")); + orderedListButton.perform(scrollTo(), click()); + aztecText.perform(typeText(formattedText)); + + // Check that HTML formatting tags were correctly added + toggleHTMLView(); + sourceText.check(matches(withText(unformattedText + "\n
    \n\t
  1. " + formattedText + "
  2. \n
"))); + } + + @Test + public void testSimpleLinkFormatting() { + // Enter text in visual editor with formatting + aztecText.perform(typeText(unformattedText)); + linkButton.perform(scrollTo(), click()); + linkURLField.perform(typeTextIntoFocusedView(linkURLText)); + linkTextField.perform(typeText(formattedText)); + linkOKButton.perform(click()); + + // Check that HTML formatting tags were correctly added + toggleHTMLView(); + sourceText.check(matches(withText(unformattedText + "" + formattedText + ""))); + } + + @Test + public void testSimpleMoreTagFormatting() { + // Enter text in visual editor more tag in between + aztecText.perform(typeText(unformattedText)); + moreButton.perform(scrollTo(), click()); + aztecText.perform(typeTextIntoFocusedView(unformattedText)); + + // Check that more tag was correctly added + toggleHTMLView(); + sourceText.check(matches(withText(unformattedText + "\n\n\n\n" + unformattedText))); + } + + @Test + public void testSimplePageBreakFormatting() { + // Enter text in visual editor with page break in between + aztecText.perform(typeText(unformattedText)); + pageButton.perform(scrollTo(), click()); + aztecText.perform(typeTextIntoFocusedView(unformattedText)); + + // Check that page break was correctly added + toggleHTMLView(); + sourceText.check(matches(withText(unformattedText + "\n\n\n\n" + unformattedText))); + } + + @Test + public void testSimpleHeadingOneFormatting() { + // Enter text in visual editor with formatting + aztecText.perform(typeText(unformattedText + "\n")); + headingButton.perform(click()); + headingOneSelector.perform(click()); + aztecText.perform(typeTextIntoFocusedView(formattedText)); + + // Check that HTML formatting tags were correctly added + toggleHTMLView(); + sourceText.check(matches(withText(unformattedText + "\n

" + formattedText + "

"))); + } + + @Test + public void testSimpleHeadingTwoFormatting() { + // Enter text in visual editor with formatting + aztecText.perform(typeText(unformattedText + "\n")); + headingButton.perform(click()); + headingTwoSelector.perform(click()); + aztecText.perform(typeTextIntoFocusedView(formattedText)); + + // Check that HTML formatting tags were correctly added + toggleHTMLView(); + sourceText.check(matches(withText(unformattedText + "\n

" + formattedText + "

"))); + } + + @Test + public void testSimpleHeadingThreeFormatting() { + // Enter text in visual editor with formatting + aztecText.perform(typeText(unformattedText + "\n")); + headingButton.perform(click()); + headingThreeSelector.perform(click()); + aztecText.perform(typeTextIntoFocusedView(formattedText)); + + // Check that HTML formatting tags were correctly added + toggleHTMLView(); + sourceText.check(matches(withText(unformattedText + "\n

" + formattedText + "

"))); + } + + @Test + public void testSimpleHeadingFourFormatting() { + // Enter text in visual editor with formatting + aztecText.perform(typeText(unformattedText + "\n")); + headingButton.perform(click()); + headingFourSelector.perform(click()); + aztecText.perform(typeTextIntoFocusedView(formattedText)); + + // Check that HTML formatting tags were correctly added + toggleHTMLView(); + sourceText.check(matches(withText(unformattedText + "\n

" + formattedText + "

"))); + } + + @Test + public void testSimpleHeadingFiveFormatting() { + // Enter text in visual editor with formatting + aztecText.perform(typeText(unformattedText + "\n")); + headingButton.perform(click()); + headingFiveSelector.perform(click()); + aztecText.perform(typeTextIntoFocusedView(formattedText)); + + // Check that HTML formatting tags were correctly added + toggleHTMLView(); + sourceText.check(matches(withText(unformattedText + "\n
" + formattedText + "
"))); + } + + @Test + public void testSimpleHeadingSixFormatting() { + // Enter text in visual editor with formatting + aztecText.perform(typeText(unformattedText + "\n")); + headingButton.perform(click()); + headingSixSelector.perform(click()); + aztecText.perform(typeTextIntoFocusedView(formattedText)); + + // Check that HTML formatting tags were correctly added + toggleHTMLView(); + sourceText.check(matches(withText(unformattedText + "\n
" + formattedText + "
"))); + } - enterHTML("hello world"); + @Test + public void testSimplePreformattedTextFormatting() { + // Enter text in visual editor with formatting + aztecText.perform(typeText(unformattedText + "\n")); + headingButton.perform(click()); + preSelector.perform(click()); + aztecText.perform(typeTextIntoFocusedView(formattedText)); - boldButton.check(matches(isChecked())); + // Check that HTML formatting tags were correctly added + toggleHTMLView(); + sourceText.check(matches(withText(unformattedText + "\n
" + formattedText + "
"))); } -} +} \ No newline at end of file diff --git a/app/src/androidTest/java/org/wordpress/aztec/demo/TestUtils.java b/app/src/androidTest/java/org/wordpress/aztec/demo/TestUtils.java index d9c3d5842..60942d184 100644 --- a/app/src/androidTest/java/org/wordpress/aztec/demo/TestUtils.java +++ b/app/src/androidTest/java/org/wordpress/aztec/demo/TestUtils.java @@ -4,24 +4,54 @@ import static android.support.test.espresso.Espresso.onView; import static android.support.test.espresso.action.ViewActions.click; -import static android.support.test.espresso.action.ViewActions.typeText; +import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed; import static android.support.test.espresso.matcher.ViewMatchers.withId; +import static android.support.test.espresso.matcher.ViewMatchers.withText; +import static org.hamcrest.Matchers.allOf; /** * Test utilities to be used with instrumentation tests. */ public class TestUtils { - public static void toggleHTMLView() { - ViewInteraction htmlButton = onView(withId(R.id.format_bar_button_html)); - htmlButton.perform(click()); - } - public static void enterHTML(String text) { - toggleHTMLView(); + // Strings + public static String unformattedText = "hello"; + public static String formattedText = "world"; + public static String linkURLText = "https://github.com/wordpress-mobile/AztecEditor-Android"; + + // Editor Views + public static ViewInteraction aztecText = onView(withId(R.id.aztec)); + public static ViewInteraction sourceText = onView(allOf(withId(R.id.source), isDisplayed())); - ViewInteraction htmlViewEditText = onView(withId(R.id.source)); - htmlViewEditText.perform(typeText(text)); + // Format Toolbar Buttons + public static ViewInteraction boldButton = onView(withId(R.id.format_bar_button_bold)); + public static ViewInteraction headingButton = onView(withId(R.id.format_bar_button_heading)); + public static ViewInteraction italicButton = onView(withId(R.id.format_bar_button_italic)); + public static ViewInteraction linkButton = onView(withId(R.id.format_bar_button_link)); + public static ViewInteraction moreButton = onView(withId(R.id.format_bar_button_more)); + public static ViewInteraction orderedListButton = onView(withId(R.id.format_bar_button_ol)); + public static ViewInteraction pageButton = onView(withId(R.id.format_bar_button_page)); + public static ViewInteraction quoteButton = onView(withId(R.id.format_bar_button_quote)); + public static ViewInteraction strikethroughButton = onView(withId(R.id.format_bar_button_strikethrough)); + public static ViewInteraction underlineButton = onView(withId(R.id.format_bar_button_underline)); + public static ViewInteraction unorderedListButton = onView(withId(R.id.format_bar_button_ul)); - toggleHTMLView(); + // Heading/Paragraph Format Selectors + public static ViewInteraction headingOneSelector = onView(allOf(withId(android.R.id.title), withText("Heading 1"))); + public static ViewInteraction headingTwoSelector = onView(withText("Heading 2")); + public static ViewInteraction headingThreeSelector = onView(withText("Heading 3")); + public static ViewInteraction headingFourSelector = onView(withText("Heading 4")); + public static ViewInteraction headingFiveSelector = onView(withText("Heading 5")); + public static ViewInteraction headingSixSelector = onView(withText("Heading 6")); + public static ViewInteraction preSelector = onView(withText("Heading 6")); + + // Link Modal + public static ViewInteraction linkOKButton = onView(withId(android.R.id.button1)); + public static ViewInteraction linkTextField = onView(withId(R.id.linkText)); + public static ViewInteraction linkURLField = onView(withId(R.id.linkURL)); + + public static void toggleHTMLView() { + ViewInteraction htmlButton = onView(withId(R.id.format_bar_button_html)); + htmlButton.perform(click()); } } From 728446c5e43c721e0d0c143cd3770e8fbac948b5 Mon Sep 17 00:00:00 2001 From: rachelmcr Date: Wed, 7 Jun 2017 23:11:46 +0100 Subject: [PATCH 06/10] Update paragraph style selectors --- .../org/wordpress/aztec/demo/TestUtils.java | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/app/src/androidTest/java/org/wordpress/aztec/demo/TestUtils.java b/app/src/androidTest/java/org/wordpress/aztec/demo/TestUtils.java index 60942d184..ae7ec83db 100644 --- a/app/src/androidTest/java/org/wordpress/aztec/demo/TestUtils.java +++ b/app/src/androidTest/java/org/wordpress/aztec/demo/TestUtils.java @@ -1,13 +1,15 @@ package org.wordpress.aztec.demo; +import android.support.test.espresso.DataInteraction; import android.support.test.espresso.ViewInteraction; +import static android.support.test.espresso.Espresso.onData; import static android.support.test.espresso.Espresso.onView; import static android.support.test.espresso.action.ViewActions.click; import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed; import static android.support.test.espresso.matcher.ViewMatchers.withId; -import static android.support.test.espresso.matcher.ViewMatchers.withText; import static org.hamcrest.Matchers.allOf; +import static org.hamcrest.Matchers.hasToString; /** * Test utilities to be used with instrumentation tests. @@ -37,13 +39,13 @@ public class TestUtils { public static ViewInteraction unorderedListButton = onView(withId(R.id.format_bar_button_ul)); // Heading/Paragraph Format Selectors - public static ViewInteraction headingOneSelector = onView(allOf(withId(android.R.id.title), withText("Heading 1"))); - public static ViewInteraction headingTwoSelector = onView(withText("Heading 2")); - public static ViewInteraction headingThreeSelector = onView(withText("Heading 3")); - public static ViewInteraction headingFourSelector = onView(withText("Heading 4")); - public static ViewInteraction headingFiveSelector = onView(withText("Heading 5")); - public static ViewInteraction headingSixSelector = onView(withText("Heading 6")); - public static ViewInteraction preSelector = onView(withText("Heading 6")); + public static DataInteraction headingOneSelector = onData(hasToString("Heading 1")); + public static DataInteraction headingTwoSelector = onData(hasToString("Heading 2")); + public static DataInteraction headingThreeSelector = onData(hasToString("Heading 3")); + public static DataInteraction headingFourSelector = onData(hasToString("Heading 4")); + public static DataInteraction headingFiveSelector = onData(hasToString("Heading 5")); + public static DataInteraction headingSixSelector = onData(hasToString("Heading 6")); + public static DataInteraction preSelector = onData(hasToString("Preformat")); // Link Modal public static ViewInteraction linkOKButton = onView(withId(android.R.id.button1)); From 3d117ee0c46f4428cffcc7d78bd769ab14689591 Mon Sep 17 00:00:00 2001 From: rachelmcr Date: Fri, 9 Jun 2017 01:07:59 +0100 Subject: [PATCH 07/10] Add custom actions to fix page break test --- .../aztec/demo/BetterClickAction.java | 120 ++++++++++++++++++ .../aztec/demo/BetterScrollToAction.java | 63 +++++++++ .../aztec/demo/SimpleTextFormattingTests.java | 6 +- .../org/wordpress/aztec/demo/TestUtils.java | 16 +++ 4 files changed, 203 insertions(+), 2 deletions(-) create mode 100644 app/src/androidTest/java/org/wordpress/aztec/demo/BetterClickAction.java create mode 100644 app/src/androidTest/java/org/wordpress/aztec/demo/BetterScrollToAction.java diff --git a/app/src/androidTest/java/org/wordpress/aztec/demo/BetterClickAction.java b/app/src/androidTest/java/org/wordpress/aztec/demo/BetterClickAction.java new file mode 100644 index 000000000..2e5b301fe --- /dev/null +++ b/app/src/androidTest/java/org/wordpress/aztec/demo/BetterClickAction.java @@ -0,0 +1,120 @@ +package org.wordpress.aztec.demo; + +import static android.support.test.espresso.matcher.ViewMatchers.isDisplayingAtLeast; +import static org.hamcrest.Matchers.allOf; + +import android.support.test.espresso.core.deps.guava.base.Optional; +import android.support.test.espresso.PerformException; +import android.support.test.espresso.UiController; +import android.support.test.espresso.ViewAction; +import android.support.test.espresso.action.CoordinatesProvider; +import android.support.test.espresso.action.PrecisionDescriber; +import android.support.test.espresso.action.Tap; +import android.support.test.espresso.action.Tapper; +import android.support.test.espresso.util.HumanReadables; +import android.view.View; +import android.view.ViewConfiguration; +import android.webkit.WebView; +import org.hamcrest.Matcher; + +/** + * Enables clicking on views with 65% or greater displaying. + */ +public final class BetterClickAction implements ViewAction { + private final CoordinatesProvider coordinatesProvider; + private final Tapper tapper; + private final PrecisionDescriber precisionDescriber; + private final Optional rollbackAction; + public BetterClickAction(Tapper tapper, CoordinatesProvider coordinatesProvider, + PrecisionDescriber precisionDescriber) { + this(tapper, coordinatesProvider, precisionDescriber, null); + } + public BetterClickAction(Tapper tapper, CoordinatesProvider coordinatesProvider, + PrecisionDescriber precisionDescriber, ViewAction rollbackAction) { + this.coordinatesProvider = coordinatesProvider; + this.tapper = tapper; + this.precisionDescriber = precisionDescriber; + this.rollbackAction = Optional.fromNullable(rollbackAction); + } + @Override + @SuppressWarnings("unchecked") + public Matcher getConstraints() { + Matcher standardConstraint = isDisplayingAtLeast(65); + if (rollbackAction.isPresent()) { + return allOf(standardConstraint, rollbackAction.get().getConstraints()); + } else { + return standardConstraint; + } + } + @Override + public void perform(UiController uiController, View view) { + float[] coordinates = coordinatesProvider.calculateCoordinates(view); + float[] precision = precisionDescriber.describePrecision(); + Tapper.Status status = Tapper.Status.FAILURE; + int loopCount = 0; + // Native event injection is quite a tricky process. A tap is actually 2 + // seperate motion events which need to get injected into the system. Injection + // makes an RPC call from our app under test to the Android system server, the + // system server decides which window layer to deliver the event to, the system + // server makes an RPC to that window layer, that window layer delivers the event + // to the correct UI element, activity, or window object. Now we need to repeat + // that 2x. for a simple down and up. Oh and the down event triggers timers to + // detect whether or not the event is a long vs. short press. The timers are + // removed the moment the up event is received (NOTE: the possibility of eventTime + // being in the future is totally ignored by most motion event processors). + // + // Phew. + // + // The net result of this is sometimes we'll want to do a regular tap, and for + // whatever reason the up event (last half) of the tap is delivered after long + // press timeout (depending on system load) and the long press behaviour is + // displayed (EG: show a context menu). There is no way to avoid or handle this more + // gracefully. Also the longpress behavour is app/widget specific. So if you have + // a seperate long press behaviour from your short press, you can pass in a + // 'RollBack' ViewAction which when executed will undo the effects of long press. + while (status != Tapper.Status.SUCCESS && loopCount < 3) { + try { + status = tapper.sendTap(uiController, coordinates, precision); + } catch (RuntimeException re) { + throw new PerformException.Builder() + .withActionDescription(this.getDescription()) + .withViewDescription(HumanReadables.describe(view)) + .withCause(re) + .build(); + } + int duration = ViewConfiguration.getPressedStateDuration(); + // ensures that all work enqueued to process the tap has been run. + if (duration > 0) { + uiController.loopMainThreadForAtLeast(duration); + } + if (status == Tapper.Status.WARNING) { + if (rollbackAction.isPresent()) { + rollbackAction.get().perform(uiController, view); + } else { + break; + } + } + loopCount++; + } + if (status == Tapper.Status.FAILURE) { + throw new PerformException.Builder() + .withActionDescription(this.getDescription()) + .withViewDescription(HumanReadables.describe(view)) + .withCause(new RuntimeException(String.format("Couldn't " + + "click at: %s,%s precision: %s, %s . Tapper: %s coordinate provider: %s precision " + + "describer: %s. Tried %s times. With Rollback? %s", coordinates[0], coordinates[1], + precision[0], precision[1], tapper, coordinatesProvider, precisionDescriber, loopCount, + rollbackAction.isPresent()))) + .build(); + } + if (tapper == Tap.SINGLE && view instanceof WebView) { + // WebViews will not process click events until double tap + // timeout. Not the best place for this - but good for now. + uiController.loopMainThreadForAtLeast(ViewConfiguration.getDoubleTapTimeout()); + } + } + @Override + public String getDescription() { + return tapper.toString().toLowerCase() + " click"; + } +} diff --git a/app/src/androidTest/java/org/wordpress/aztec/demo/BetterScrollToAction.java b/app/src/androidTest/java/org/wordpress/aztec/demo/BetterScrollToAction.java new file mode 100644 index 000000000..84636934a --- /dev/null +++ b/app/src/androidTest/java/org/wordpress/aztec/demo/BetterScrollToAction.java @@ -0,0 +1,63 @@ +package org.wordpress.aztec.demo; + +import static android.support.test.espresso.matcher.ViewMatchers.isAssignableFrom; +import static android.support.test.espresso.matcher.ViewMatchers.isDescendantOfA; +import static android.support.test.espresso.matcher.ViewMatchers.isDisplayingAtLeast; +import static android.support.test.espresso.matcher.ViewMatchers.withEffectiveVisibility; +import static org.hamcrest.Matchers.allOf; +import static org.hamcrest.Matchers.anyOf; + +import android.support.test.espresso.PerformException; +import android.support.test.espresso.UiController; +import android.support.test.espresso.ViewAction; +import android.support.test.espresso.matcher.ViewMatchers.Visibility; +import android.support.test.espresso.util.HumanReadables; + +import android.graphics.Rect; +import android.util.Log; +import android.view.View; +import android.widget.HorizontalScrollView; +import android.widget.ScrollView; + +import org.hamcrest.Matcher; + +/** + * Enables scrolling to the given view with 65% or greater displaying. View must be a descendant of a ScrollView. + */ +public final class BetterScrollToAction implements ViewAction { + private static final String TAG = BetterScrollToAction.class.getSimpleName(); + + @SuppressWarnings("unchecked") + @Override + public Matcher getConstraints() { + return allOf(withEffectiveVisibility(Visibility.VISIBLE), isDescendantOfA(anyOf( + isAssignableFrom(ScrollView.class), isAssignableFrom(HorizontalScrollView.class)))); + } + + @Override + public void perform(UiController uiController, View view) { + if (isDisplayingAtLeast(65).matches(view)) { + Log.i(TAG, "View is already displayed. Returning."); + return; + } + Rect rect = new Rect(); + view.getDrawingRect(rect); + if (!view.requestRectangleOnScreen(rect, true /* immediate */)) { + Log.w(TAG, "Scrolling to view was requested, but none of the parents scrolled."); + } + uiController.loopMainThreadUntilIdle(); + if (!isDisplayingAtLeast(65).matches(view)) { + throw new PerformException.Builder() + .withActionDescription(this.getDescription()) + .withViewDescription(HumanReadables.describe(view)) + .withCause(new RuntimeException( + "Scrolling to view was attempted, but the view is not displayed")) + .build(); + } + } + + @Override + public String getDescription() { + return "scroll to"; + } +} diff --git a/app/src/androidTest/java/org/wordpress/aztec/demo/SimpleTextFormattingTests.java b/app/src/androidTest/java/org/wordpress/aztec/demo/SimpleTextFormattingTests.java index b61ff7cdf..a2cd506a7 100644 --- a/app/src/androidTest/java/org/wordpress/aztec/demo/SimpleTextFormattingTests.java +++ b/app/src/androidTest/java/org/wordpress/aztec/demo/SimpleTextFormattingTests.java @@ -15,6 +15,8 @@ import static android.support.test.espresso.assertion.ViewAssertions.matches; import static android.support.test.espresso.matcher.ViewMatchers.withText; import static org.wordpress.aztec.demo.TestUtils.aztecText; +import static org.wordpress.aztec.demo.TestUtils.betterClick; +import static org.wordpress.aztec.demo.TestUtils.betterScrollTo; import static org.wordpress.aztec.demo.TestUtils.boldButton; import static org.wordpress.aztec.demo.TestUtils.formattedText; import static org.wordpress.aztec.demo.TestUtils.headingButton; @@ -163,12 +165,12 @@ public void testSimpleMoreTagFormatting() { public void testSimplePageBreakFormatting() { // Enter text in visual editor with page break in between aztecText.perform(typeText(unformattedText)); - pageButton.perform(scrollTo(), click()); + pageButton.perform(betterScrollTo(), betterClick()); aztecText.perform(typeTextIntoFocusedView(unformattedText)); // Check that page break was correctly added toggleHTMLView(); - sourceText.check(matches(withText(unformattedText + "\n\n\n\n" + unformattedText))); + sourceText.check(matches(withText(unformattedText + "\n\n\n\n" + unformattedText))); } @Test diff --git a/app/src/androidTest/java/org/wordpress/aztec/demo/TestUtils.java b/app/src/androidTest/java/org/wordpress/aztec/demo/TestUtils.java index ae7ec83db..195e62397 100644 --- a/app/src/androidTest/java/org/wordpress/aztec/demo/TestUtils.java +++ b/app/src/androidTest/java/org/wordpress/aztec/demo/TestUtils.java @@ -1,7 +1,12 @@ package org.wordpress.aztec.demo; import android.support.test.espresso.DataInteraction; +import android.support.test.espresso.ViewAction; import android.support.test.espresso.ViewInteraction; +import android.support.test.espresso.action.GeneralLocation; +import android.support.test.espresso.action.Press; +import android.support.test.espresso.action.Tap; +import android.support.test.espresso.action.ViewActions; import static android.support.test.espresso.Espresso.onData; import static android.support.test.espresso.Espresso.onView; @@ -52,8 +57,19 @@ public class TestUtils { public static ViewInteraction linkTextField = onView(withId(R.id.linkText)); public static ViewInteraction linkURLField = onView(withId(R.id.linkURL)); + // Switch to HTML view public static void toggleHTMLView() { ViewInteraction htmlButton = onView(withId(R.id.format_bar_button_html)); htmlButton.perform(click()); } + + // Better scrolling action for last toolbar item (<90% of item displayed) + public static ViewAction betterScrollTo() { + return ViewActions.actionWithAssertions(new BetterScrollToAction()); + } + + // Better click action for last toolbar item (<90% of item displayed) + public static ViewAction betterClick() { + return new BetterClickAction(Tap.SINGLE, GeneralLocation.CENTER, Press.FINGER); + } } From 41c85d22469ec23705ca78da883fe7c2b5210ab7 Mon Sep 17 00:00:00 2001 From: rachelmcr Date: Tue, 13 Jun 2017 23:59:17 +0100 Subject: [PATCH 08/10] Replace failing link formatting test --- .../aztec/demo/SimpleTextFormattingTests.java | 36 ++++++++++++++----- 1 file changed, 28 insertions(+), 8 deletions(-) diff --git a/app/src/androidTest/java/org/wordpress/aztec/demo/SimpleTextFormattingTests.java b/app/src/androidTest/java/org/wordpress/aztec/demo/SimpleTextFormattingTests.java index a2cd506a7..2ffe0bf66 100644 --- a/app/src/androidTest/java/org/wordpress/aztec/demo/SimpleTextFormattingTests.java +++ b/app/src/androidTest/java/org/wordpress/aztec/demo/SimpleTextFormattingTests.java @@ -135,18 +135,38 @@ public void testSimpleOrderedListFormatting() { sourceText.check(matches(withText(unformattedText + "\n
    \n\t
  1. " + formattedText + "
  2. \n
"))); } - @Test - public void testSimpleLinkFormatting() { + /* + * This test is disabled because Espresso does not click in the correct position for the link dialog's OK button. + * See replacement test below. + */ + //@Test + //public void testSimpleLinkFormatting() { // Enter text in visual editor with formatting - aztecText.perform(typeText(unformattedText)); - linkButton.perform(scrollTo(), click()); - linkURLField.perform(typeTextIntoFocusedView(linkURLText)); - linkTextField.perform(typeText(formattedText)); - linkOKButton.perform(click()); + //aztecText.perform(typeText(unformattedText)); + //linkButton.perform(scrollTo(), click()); + //linkURLField.perform(replaceText(linkURLText)); + //linkTextField.perform(replaceText(formattedText)); + //linkOKButton.perform(click()); // Check that HTML formatting tags were correctly added + //toggleHTMLView(); + //sourceText.check(matches(withText(unformattedText + "" + formattedText + ""))); + //} + + /* + * This test enters link HTML and then checks the link dialog values. + */ + @Test + public void testSimpleLinkFormatting() { + // Enter link HTML toggleHTMLView(); - sourceText.check(matches(withText(unformattedText + "" + formattedText + ""))); + sourceText.perform(typeText("" + formattedText + "")); + + // Check that link dialog contains the correct values + toggleHTMLView(); + linkButton.perform(scrollTo(), click()); + linkURLField.check(matches(withText(linkURLText))); + linkTextField.check(matches(withText(formattedText))); } @Test From c044ad1a649fa5229fb9ae4a63acae092d707efc Mon Sep 17 00:00:00 2001 From: rachelmcr Date: Thu, 15 Jun 2017 13:28:00 +0100 Subject: [PATCH 09/10] Remove commented out link formatting test --- .../aztec/demo/SimpleTextFormattingTests.java | 22 +++---------------- 1 file changed, 3 insertions(+), 19 deletions(-) diff --git a/app/src/androidTest/java/org/wordpress/aztec/demo/SimpleTextFormattingTests.java b/app/src/androidTest/java/org/wordpress/aztec/demo/SimpleTextFormattingTests.java index 2ffe0bf66..51b97c9e1 100644 --- a/app/src/androidTest/java/org/wordpress/aztec/demo/SimpleTextFormattingTests.java +++ b/app/src/androidTest/java/org/wordpress/aztec/demo/SimpleTextFormattingTests.java @@ -135,26 +135,10 @@ public void testSimpleOrderedListFormatting() { sourceText.check(matches(withText(unformattedText + "\n
    \n\t
  1. " + formattedText + "
  2. \n
"))); } - /* - * This test is disabled because Espresso does not click in the correct position for the link dialog's OK button. - * See replacement test below. - */ - //@Test - //public void testSimpleLinkFormatting() { - // Enter text in visual editor with formatting - //aztecText.perform(typeText(unformattedText)); - //linkButton.perform(scrollTo(), click()); - //linkURLField.perform(replaceText(linkURLText)); - //linkTextField.perform(replaceText(formattedText)); - //linkOKButton.perform(click()); - - // Check that HTML formatting tags were correctly added - //toggleHTMLView(); - //sourceText.check(matches(withText(unformattedText + "" + formattedText + ""))); - //} - /* * This test enters link HTML and then checks the link dialog values. + * This is opposite of the steps in the other tests (which enter rich text and check the HTML), + * because Espresso does not click in the correct position for the link dialog's OK button. */ @Test public void testSimpleLinkFormatting() { @@ -283,4 +267,4 @@ public void testSimplePreformattedTextFormatting() { toggleHTMLView(); sourceText.check(matches(withText(unformattedText + "\n
" + formattedText + "
"))); } -} \ No newline at end of file +} From 3f26f95ddd4365145f8f1a350db5e26e9023d937 Mon Sep 17 00:00:00 2001 From: rachelmcr Date: Thu, 15 Jun 2017 13:29:38 +0100 Subject: [PATCH 10/10] Add explanatory comments to click and scroll actions --- .../java/org/wordpress/aztec/demo/BetterClickAction.java | 1 + .../java/org/wordpress/aztec/demo/BetterScrollToAction.java | 2 ++ 2 files changed, 3 insertions(+) diff --git a/app/src/androidTest/java/org/wordpress/aztec/demo/BetterClickAction.java b/app/src/androidTest/java/org/wordpress/aztec/demo/BetterClickAction.java index 2e5b301fe..1c9c82f4b 100644 --- a/app/src/androidTest/java/org/wordpress/aztec/demo/BetterClickAction.java +++ b/app/src/androidTest/java/org/wordpress/aztec/demo/BetterClickAction.java @@ -39,6 +39,7 @@ public BetterClickAction(Tapper tapper, CoordinatesProvider coordinatesProvider, @Override @SuppressWarnings("unchecked") public Matcher getConstraints() { + // Check that at least 65% of the element is displayed (instead of default 90%) Matcher standardConstraint = isDisplayingAtLeast(65); if (rollbackAction.isPresent()) { return allOf(standardConstraint, rollbackAction.get().getConstraints()); diff --git a/app/src/androidTest/java/org/wordpress/aztec/demo/BetterScrollToAction.java b/app/src/androidTest/java/org/wordpress/aztec/demo/BetterScrollToAction.java index 84636934a..6e5ea4aa8 100644 --- a/app/src/androidTest/java/org/wordpress/aztec/demo/BetterScrollToAction.java +++ b/app/src/androidTest/java/org/wordpress/aztec/demo/BetterScrollToAction.java @@ -36,6 +36,7 @@ public Matcher getConstraints() { @Override public void perform(UiController uiController, View view) { + // Check that at least 65% of the element is displayed (instead of default 90%) if (isDisplayingAtLeast(65).matches(view)) { Log.i(TAG, "View is already displayed. Returning."); return; @@ -46,6 +47,7 @@ public void perform(UiController uiController, View view) { Log.w(TAG, "Scrolling to view was requested, but none of the parents scrolled."); } uiController.loopMainThreadUntilIdle(); + // Check that at least 65% of the element is displayed (instead of default 90%) if (!isDisplayingAtLeast(65).matches(view)) { throw new PerformException.Builder() .withActionDescription(this.getDescription())