Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,14 @@
import androidx.test.rule.GrantPermissionRule;

import org.junit.Before;
import org.junit.Ignore;
import org.junit.Rule;
import org.junit.Test;
import org.wordpress.android.e2e.pages.BlockEditorPage;
import org.wordpress.android.e2e.pages.MySitesPage;
import org.wordpress.android.e2e.pages.PostPreviewPage;
import org.wordpress.android.e2e.pages.SiteSettingsPage;
import org.wordpress.android.support.BaseTest;
import org.wordpress.android.ui.WPLaunchActivity;

import static androidx.test.espresso.Espresso.pressBack;
import static org.wordpress.android.support.WPSupportUtils.sleep;
import java.time.Instant;

public class BlockEditorTests extends BaseTest {
@Rule
Expand All @@ -32,34 +28,63 @@ public void setUp() {
wpLogin();
}

@Ignore("until startup times are improved or idling resources are made more reliable")
@Test
public void testSwitchToClassicAndPreview() {
String title = "Hello Espresso!";

MySitesPage mySitesPage = new MySitesPage().go();
sleep();

mySitesPage.clickSettingsItem();

// Set to Gutenberg. Apparently the site is defaulting to Aztec still.
new SiteSettingsPage().setEditorToGutenberg();

// exit the Settings page
pressBack();

mySitesPage.clickBlogPostsItem();

mySitesPage.startNewPost();
String mTitle = "Hello Espresso!";
Comment thread
jostnes marked this conversation as resolved.
String mPostText = "Lorem ipsum dolor sit amet, consectetur adipiscing elit.";
String mCategory = "Wedding";
String mTag = "Tag " + Instant.now().toEpochMilli();
String mHtmlPost = "<!-- wp:paragraph -->\n"
+ "<p>" + mPostText + "</p>\n"
+ "<!-- /wp:paragraph -->"
+ "\n"
+ "<div class=\"wp-block-column\"><!-- wp:image {\"id\":65,\"sizeSlug\":\"large\"} -->\n"
+ "<figure class=\"wp-block-image size-large\"><img src=\"https://fourpawsdoggrooming.files"
+ ".wordpress.com/2020/08/image-1.jpg?w=731\" alt=\"\" class=\"wp-image-65\"/></figure>\n"
+ "<!-- /wp:image --></div>\n";

BlockEditorPage blockEditorPage = new BlockEditorPage();
blockEditorPage.waitForTitleDisplayed();

blockEditorPage.enterTitle(title);
@Test
public void publishSimplePost() {
new MySitesPage()
.go()
.startNewPost();

new BlockEditorPage()
.waitForTitleDisplayed()
.enterTitle(mTitle)
.enterParagraphText(mPostText)
.publish()
.verifyPostPublished();
}

blockEditorPage.previewPost();
sleep();
@Test
public void publishFullPost() {
new MySitesPage()
.go()
.startNewPost();

new BlockEditorPage()
.waitForTitleDisplayed()
.enterTitle(mTitle)
.enterParagraphText(mPostText)
.addImage()
.addPostSettings(mCategory, mTag)
.clickPublish()
.verifyPostSettings(mCategory, mTag)
.confirmPublish()
.verifyPostPublished();
}

new PostPreviewPage();
@Test
public void blockEditorCanDisplayElementAddedInHtmlMode() {
new MySitesPage()
.go()
.startNewPost();

new BlockEditorPage()
.waitForTitleDisplayed()
.enterTitle(mTitle)
.switchToHtmlMode()
.enterParagraphText(mHtmlPost)
.switchToVisualMode()
.verifyPostElementText(mPostText);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,23 @@

import static androidx.test.espresso.Espresso.onView;
import static androidx.test.espresso.Espresso.openActionBarOverflowOrOptionsMenu;
import static androidx.test.espresso.Espresso.pressBack;
import static androidx.test.espresso.action.ViewActions.click;
import static androidx.test.espresso.action.ViewActions.swipeDown;
import static androidx.test.espresso.action.ViewActions.typeText;
import static androidx.test.espresso.assertion.ViewAssertions.matches;
import static androidx.test.espresso.matcher.ViewMatchers.isDisplayed;
import static androidx.test.espresso.matcher.ViewMatchers.withHint;
import static androidx.test.espresso.matcher.ViewMatchers.withId;
import static androidx.test.espresso.matcher.ViewMatchers.withResourceName;
import static androidx.test.espresso.matcher.ViewMatchers.withText;
import static org.wordpress.android.support.WPSupportUtils.clickOn;
import static org.wordpress.android.support.WPSupportUtils.clickOnViewWithTag;
import static org.wordpress.android.support.WPSupportUtils.populateTextField;
import static org.wordpress.android.support.WPSupportUtils.waitForElementToBeDisplayed;
import static org.wordpress.android.support.WPSupportUtils.waitForElementToBeDisplayedWithoutFailure;
import static junit.framework.TestCase.assertTrue;
import static org.wordpress.android.support.WPSupportUtils.withIndex;

public class BlockEditorPage {
private static ViewInteraction titleField = onView(withHint("Add title"));
Expand All @@ -27,12 +36,113 @@ public BlockEditorPage() {
mEditor.check(matches(isDisplayed()));
}

public void waitForTitleDisplayed() {
public BlockEditorPage waitForTitleDisplayed() {
waitForElementToBeDisplayed(titleField);
return this;
}

public void enterTitle(String postTitle) {
public BlockEditorPage enterTitle(String postTitle) {
titleField.perform(typeText(postTitle), ViewActions.closeSoftKeyboard());
return this;
}

public BlockEditorPage enterParagraphText(String paragraphText) {
onView(withHint(R.string.gutenberg_native_start_writing))
.perform(typeText(paragraphText), ViewActions.closeSoftKeyboard());
return this;
}

public BlockEditorPage switchToHtmlMode() {
openActionBarOverflowOrOptionsMenu(ApplicationProvider.getApplicationContext());
clickOn(onView(withText(R.string.menu_html_mode)));
return this;
}

public BlockEditorPage switchToVisualMode() {
openActionBarOverflowOrOptionsMenu(ApplicationProvider.getApplicationContext());
clickOn(onView(withText(R.string.menu_visual_mode)));
return this;
}

public BlockEditorPage addPostSettings(String categoryName, String tagName) {
openPostSetting();
addCategory(categoryName);
addTag(tagName);
pressBack();
return this;
}

public void openPostSetting() {
openActionBarOverflowOrOptionsMenu(ApplicationProvider.getApplicationContext());
clickOn(onView(withText(R.string.post_settings)));
}

public void addCategory(String category) {
clickOn(onView(withId(R.id.post_categories_container)));
clickOn(onView(withText(category)));
pressBack();
}

public void addTag(String tag) {
clickOn(onView(withId(R.id.post_tags_container)));
ViewInteraction tagsField = onView(withId(R.id.tags_edit_text));
populateTextField(tagsField, tag);
pressBack();
}

public BlockEditorPage publish() {
clickPublish();
confirmPublish();
return this;
}

public BlockEditorPage clickPublish() {
clickOn(onView(withResourceName("menu_primary_action")));
return this;
}

public BlockEditorPage confirmPublish() {
clickOn(onView(withText(R.string.publish_now)));
dismissBloggingRemindersAlertIfNeeded();
return this;
}

public void dismissBloggingRemindersAlertIfNeeded() {
ViewInteraction bloggingRemindersAlertTitle = onView(withText(R.string.set_your_blogging_reminders_title));

if (waitForElementToBeDisplayedWithoutFailure(bloggingRemindersAlertTitle)) {
bloggingRemindersAlertTitle.perform(swipeDown());
}
}

public void verifyPostPublished() {
assertTrue("'Post published' toast was not displayed",
waitForElementToBeDisplayedWithoutFailure(onView(withText(R.string.post_published))));
Comment on lines +119 to +120

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤔 Having the assertion failure message as the first argument makes the code a bit confusing. assertTrue(boolean condition, String message) would make it better to read. ¯\_(ツ)_/¯

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Completely agree with that, I needed a second look to see that that was supposed to be the error message.

}

public BlockEditorPage verifyPostSettings(String categoryName, String tagName) {
assertTrue("Category is not present in Post confirmation panel",
waitForElementToBeDisplayedWithoutFailure(onView(withText(categoryName))));
assertTrue("Tag is not present in Post confirmation panel",
waitForElementToBeDisplayedWithoutFailure(onView(withText(tagName))));
return this;
}

public BlockEditorPage verifyPostElementText(String postText) {
assertTrue("Expected text is not displayed",
Comment thread
jostnes marked this conversation as resolved.
waitForElementToBeDisplayedWithoutFailure(onView(withText(postText))));
return this;
}

public BlockEditorPage addImage() {
clickOnViewWithTag("add-block-button");
clickOn("Image");
clickOn("WordPress Media Library");
waitForElementToBeDisplayed(onView(withText("WordPress media")));
waitForElementToBeDisplayed(onView(withIndex(withId(R.id.image_thumbnail), 0)));
onView(withIndex(withId(R.id.image_thumbnail), 0)).perform(click());
clickOn(R.id.mnu_confirm_selection);
return this;
}

public void previewPost() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -462,17 +462,21 @@ public Boolean get() {
}

public static boolean waitForElementToBeDisplayedWithoutFailure(final Integer elementID) {
return waitForElementToBeDisplayedWithoutFailure(onView(withId(elementID)));
}

public static boolean waitForElementToBeDisplayedWithoutFailure(final ViewInteraction element) {
try {
waitForConditionToBeTrueWithoutFailure(new Supplier<Boolean>() {
@Override
public Boolean get() {
return isElementDisplayed(elementID);
return isElementDisplayed(element);
}
});
} catch (Exception e) {
// ignore the failure
}
return isElementDisplayed(elementID);
return isElementDisplayed(element);
}

public static void waitForConditionToBeTrue(Supplier<Boolean> supplier) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"request": {
"method": "GET",
"urlPath": "/wp/v2/sites/106707880/blocks",
"queryParameters": {
"locale": {
"matches": "(.*)"
},
"_locale": {
"equalTo": "user"
},
"per_page": {
"equalTo": "100"
}
}
},
"response": {
"status": 200,
"jsonBody": []
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
{
"request": {
"method": "GET",
"urlPath": "/wp/v2/sites/106707880/media/133",
"queryParameters": {
"locale": {
"matches": "(.*)"
}
}
},
"response": {
"status": 200,
"jsonBody": {
"ID": 133,
"URL": "https://e2eflowtestingmobile.files.wordpress.com/2019/05/img_0111-14.jpg",
"guid": "http://e2eflowtestingmobile.files.wordpress.com/2019/05/img_0111-14.jpg",
"date": "2019-05-08T09:49:00+00:00",
"post_ID": 295,
"author_ID": 152748359,
"file": "img_0111-14.jpg",
"mime_type": "image/jpeg",
"extension": "jpg",
"title": "img_0111",
"caption": "",
"description": "",
"alt": "",
"icon": "https://s1.wp.com/wp-includes/images/media/default.png",
"thumbnails": {
"thumbnail": "https://e2eflowtestingmobile.files.wordpress.com/2019/05/img_0111-14.jpg?w=150",
"medium": "https://e2eflowtestingmobile.files.wordpress.com/2019/05/img_0111-14.jpg?w=300",
"large": "https://e2eflowtestingmobile.files.wordpress.com/2019/05/img_0111-14.jpg?w=1024",
"post-thumbnail": "https://e2eflowtestingmobile.files.wordpress.com/2019/05/img_0111-14.jpg?w=740&h=430&crop=1",
"independent-publisher-2-banner": "https://e2eflowtestingmobile.files.wordpress.com/2019/05/img_0111-14.jpg?w=1440&h=600&crop=1",
"independent-publisher-2-full-width": "https://e2eflowtestingmobile.files.wordpress.com/2019/05/img_0111-14.jpg?w=1100"
},
"height": 3024,
"width": 4032,
"exif": {
"aperture": "2.4",
"credit": "",
"camera": "iPhone X",
"caption": "",
"created_timestamp": "1522412059",
"copyright": "",
"focal_length": "6",
"iso": "16",
"shutter_speed": "0.0047846889952153",
"title": "",
"orientation": "1",
"keywords": []
},
"meta": {
"links": {
"self": "{{request.requestLine.baseUrl}}/rest/v1.1/sites/106707880/media/133",
"help": "{{request.requestLine.baseUrl}}/rest/v1.1/sites/106707880/media/133/help",
"site": "{{request.requestLine.baseUrl}}/rest/v1.1/sites/106707880",
"parent": "{{request.requestLine.baseUrl}}/rest/v1.1/sites/106707880/posts/295"
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"request": {
"method": "GET",
"urlPath": "/wpcom/v2/sites/106707880/xposts/"
},
"response": {
"status": 200,
"jsonBody": {
"code": "xposts_require_o2_enabled",
"message": "Xposts are only available on sites with the o2-plugin enabled.",
"data": {
"status": 400
}
}
}
}