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

Add more E2E tests for Jetpack Social #37046

Merged
merged 4 commits into from
May 3, 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
4 changes: 4 additions & 0 deletions projects/plugins/social/changelog/add-e2e-tests-for-social
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: added

Added more E2E tests
23 changes: 23 additions & 0 deletions projects/plugins/social/tests/e2e/specs/admin-page.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { prerequisitesBuilder } from 'jetpack-e2e-commons/env/prerequisites.js';
import { expect, test } from 'jetpack-e2e-commons/fixtures/base-test.js';
import { JetpackSocialPage } from '../pages/index.js';
import logger from 'jetpack-e2e-commons/logger.js';

test.beforeEach( async ( { page } ) => {
await prerequisitesBuilder( page )
.withCleanEnv()
.withActivePlugins( [ 'social' ] )
.withLoggedIn( true )
.build();
} );

test( 'Jetpack Social admin page', async ( { page } ) => {
logger.action( 'Visit the Jetpack Social admin page' );
await JetpackSocialPage.visit( page );

logger.action( 'Checking for heading "Jetpack Social"' );
await expect( page.getByRole( 'heading', { name: 'Jetpack Social' } ) ).toBeVisible();

logger.action( 'Checking for button "Get Started"' );
await expect( page.getByRole( 'button', { name: 'Get Started' } ) ).toBeVisible();
} );
51 changes: 51 additions & 0 deletions projects/plugins/social/tests/e2e/specs/social-sidebar.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import { prerequisitesBuilder } from 'jetpack-e2e-commons/env/prerequisites.js';
import { expect, test } from 'jetpack-e2e-commons/fixtures/base-test.js';
import logger from 'jetpack-e2e-commons/logger.js';
import BlockEditorPage from 'jetpack-e2e-commons/pages/wp-admin/block-editor.js';
import { connect } from '../flows/index.js';

test.beforeEach( async ( { page } ) => {
await prerequisitesBuilder( page )
.withCleanEnv()
.withActivePlugins( [ 'social' ] )
.withInactivePlugins( [ 'jetpack' ] )
.withLoggedIn( true )
.withWpComLoggedIn( true )
Copy link
Contributor

Choose a reason for hiding this comment

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

For some reason this step is faliing for me. It gets stuck on the confirmation screen after login. It must be something about my environment or other tests would be failing.

Is it still working for you in your dev environment?

Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry meant to attach the screenshot

test-failed-1

Copy link
Member Author

Choose a reason for hiding this comment

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

Is it still working for you in your dev environment?

Yes.

What error do you see in the console/terminal?

Copy link
Contributor

Choose a reason for hiding this comment

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

It's a timeout on this page as it's waiting for the form to be hidden, but that never happens as we need to click on the continue button. Very strange! The GH Action is succeeding too. I've tried cleaning my environment but I get the same problem.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, many of those workflow utilities are unpredictable and needs more work, which is beyond the scope of this PR.

Copy link
Contributor

Choose a reason for hiding this comment

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

I've pushed a change in f670105, that looks for the Login button being hidden rather than waiting for the login container to be hidden (which isn't happening sometimes). It works locally for me, but we'll have to see if it works in CI and for everyone else.

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't see anything changed in that commit you pushed 🤔

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah! I've committed the wrong file. 49f6911 should have the right changes.

.build();
} );

test( 'Jetpack Social sidebar', async ( { page } ) => {
await test.step( 'Connect wordpress.com account', async () => {
await connect( page );
} );

await test.step( 'Goto post edit page', async () => {
logger.action( 'Hover over "Posts" in admin menu' );
await page.getByRole( 'link', { name: 'Posts', exact: true } ).hover();

logger.action( 'Click on "Add New Post" in admin menu' );
await page.getByRole( 'link', { name: 'Add New Post' } ).click();

/**
* @type {BlockEditorPage}
*/
const blockEditor = await BlockEditorPage.init( page );

await page.waitForURL( '**/post-new.php' );
await blockEditor.waitForEditor();

logger.action( 'Close "Welcome to the block editor" dialog' );
await blockEditor.resolveWelcomeGuide();

await blockEditor.setTitle( 'Jetpack Social test post' );
} );

await test.step( 'Check Social sidebar', async () => {
logger.action( 'Open Jetpack Social sidebar' );
await page.getByRole( 'button', { name: 'Jetpack Social', exact: true } ).click();

logger.action( 'Checking for "Preview" button' );
const previewButton = page.getByRole( 'button', { name: 'Open Social Previews', exact: true } );
await expect( previewButton ).toBeVisible();
} );
} );
7 changes: 1 addition & 6 deletions tools/e2e-commons/pages/wpcom/login.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,9 @@ export default class LoginPage extends WpPage {
await this.fill( usernameSelector, credentials.username );
await this.click( continueButtonSelector );
await this.waitForElementToBeVisible( passwordSelector );
// Even if we wait for the field to become visible Playwright might still type the password too fast
// and the first characters will miss the password field. A short wait fixes this
await this.waitForTimeout( 2000 );
await this.fill( passwordSelector, credentials.password );
await this.click( submitButtonSelector );

await this.waitForDomContentLoaded();
await this.waitForElementToBeHidden( this.selectors[ 0 ] );
await this.waitForElementToBeHidden( submitButtonSelector );
} catch ( e ) {
if ( retry === true ) {
logger.warn( `The login didn't work as expected - retrying now: '${ e }'` );
Expand Down
Loading