Skip to content
This repository has been archived by the owner on Mar 13, 2024. It is now read-only.

Fix E2E flaky tests #2996

Merged
merged 2 commits into from
Jun 21, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
Fix flaky some of the E2E tests
  • Loading branch information
saturninoabril committed Jun 21, 2019
commit d4a61e8cc2bb402372b0394afd5a5d5be4e45b67
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ describe('Account Settings > Display > Channel Display Mode', () => {

// Post a message to a channel
cy.visit('/');
cy.postMessage('Test for channel display mode {enter}');
cy.postMessage('Test for channel display mode');
Copy link
Member Author

Choose a reason for hiding this comment

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

nit: update the correct usage of cy.postMessage where the text param don't need to add {enter} since the command itself is doing it already.

});

beforeEach(() => {
Expand Down
8 changes: 4 additions & 4 deletions cypress/integration/account_settings/general/nickname.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ describe('Account Settings > Sidebar > General', () => {
cy.get('#accountSettingsHeader > .close').click();
cy.get('#sidebarHeaderDropdownButton').click();

cy.get('#manageMembers').should('be.visible');
cy.get('#manageMembers').click();
cy.get('#viewMembers').should('be.visible');
cy.get('#viewMembers').click();

// # Search for username and check that no nickname is present
cy.get('.modal-title').should('be.visible');
Expand Down Expand Up @@ -82,8 +82,8 @@ describe('Account Settings > Sidebar > General', () => {
cy.get('#accountSettingsHeader > .close').click();
cy.get('#sidebarHeaderDropdownButton').click();

cy.get('#manageMembers').should('be.visible');
cy.get('#manageMembers').click();
cy.get('#viewMembers').should('be.visible');
cy.get('#viewMembers').click();
Copy link
Member Author

Choose a reason for hiding this comment

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

user-1 by default don't have a permission to manage members on sample team/channel and so just use viewMembers


// # Search for username and check that expected nickname is present
cy.get('.modal-title').should('be.visible');
Expand Down
2 changes: 2 additions & 0 deletions cypress/integration/at_mentions/at_mentions_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,8 @@ describe('at-mention', () => {
cy.get('@postMessageText').
find(`[data-mention=${receiver.username}]`).
should('not.exist');

cy.get('#sidebarItem_saepe-5').scrollIntoView().click({force: true});
Copy link
Member Author

Choose a reason for hiding this comment

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

nit: Added missing step

Copy link
Contributor

Choose a reason for hiding this comment

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

Another nit, no need to scroll into view if we are forcing the click.

});
});
});
8 changes: 4 additions & 4 deletions cypress/integration/channel/edit_message_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ describe('Edit Message', () => {
cy.visit('/');

// # Post message "Hello"
cy.get('#post_textbox').type('Hello World!').type('{enter}');
cy.postMessage('Hello World!');

// # Hit the up arrow to open the "edit modal"
cy.get('#post_textbox').type('{uparrow}');
Expand Down Expand Up @@ -75,7 +75,7 @@ describe('Edit Message', () => {
cy.visit('/');

// # Post a message
cy.postMessage('Checking timestamp {enter}');
cy.postMessage('Checking timestamp');

cy.getLastPostId().then((postId) => {
// # Mouseover post to display the timestamp
Expand Down Expand Up @@ -149,7 +149,7 @@ describe('Edit Message', () => {
cy.visit('/');

// # Enter first message
cy.get('#post_textbox').type('Hello{enter}');
cy.postMessage('Hello');

// * Verify first message is sent and not pending
cy.getLastPostId().then((postId) => {
Expand All @@ -158,7 +158,7 @@ describe('Edit Message', () => {
});

// # Enter second message
cy.get('#post_textbox').type('World!{enter}');
cy.postMessage('World!');

// * Verify second message is sent and not pending
cy.getLastPostId().then((postId) => {
Expand Down
2 changes: 1 addition & 1 deletion cypress/integration/channel/message_deletion_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ describe('Message deletion', () => {

it('M13336 Delete both parent post and reply when deleting parent post from center', () => {
// # Post message in center.
cy.postMessage('test message deletion {enter}');
cy.postMessage('test message deletion');

cy.getLastPostId().then((parentMessageId) => {
// # Mouseover the post and click post comment icon.
Expand Down
14 changes: 7 additions & 7 deletions cypress/integration/channel/message_draft_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,19 @@
// - Use element ID when selecting an element. Create one if none.
// ***************************************************************

/*eslint max-nested-callbacks: ["error", 3]*/
/*eslint max-nested-callbacks: ["error", 4]*/

let testTeam;

describe('Message Draft', () => {
before(() => {
// # Login as new user
cy.loginAsNewUser();

// # Create new team and visit its URL
cy.apiCreateTeam('test-team', 'Test Team').then((response) => {
testTeam = response.body;
cy.visit(`/${testTeam.name}`);
cy.loginAsNewUser().then(() => {
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think having to use .then() should be necessary, but maybe I'm missing something.

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'm not totally sure about this but let's try and observe.

// # Create new team and visit its URL
cy.apiCreateTeam('test-team', 'Test Team').then((response) => {
testTeam = response.body;
cy.visit(`/${testTeam.name}`);
});
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
// - Use element ID when selecting an element. Create one if none.
// ***************************************************************

/*eslint max-nested-callbacks: ["error", 3]*/
/*eslint max-nested-callbacks: ["error", 4]*/

import * as TIMEOUTS from '../../fixtures/timeouts';

Expand All @@ -16,12 +16,12 @@ let testTeam;
describe('Message Draft and Switch Channels', () => {
before(() => {
// # Login as new user
cy.loginAsNewUser();

// # Create new team and visit its URL
cy.apiCreateTeam('test-team', 'Test Team').then((response) => {
testTeam = response.body;
cy.visit(`/${testTeam.name}`);
cy.loginAsNewUser().then(() => {
// # Create new team and visit its URL
cy.apiCreateTeam('test-team', 'Test Team').then((response) => {
testTeam = response.body;
cy.visit(`/${testTeam.name}`);
});
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ describe('MM-13697 Edit Post with attachment', () => {
});

// # Type 'This is sample text' and submit
cy.get('#post_textbox').type('This is sample text{enter}');
cy.postMessage('This is sample text');

// # Get last post ID
cy.getLastPostId().then((postID) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ describe('Email notification', () => {
it('post a message that mentions a user', () => {
cy.apiLogin('user-1');
cy.visit('/ad-1/channels/town-square');
cy.postMessage(`${text}{enter}`);
cy.postMessage(text);

// Wait for a while to ensure that email notification is sent.
cy.wait(TIMEOUTS.SMALL);
Expand Down
22 changes: 15 additions & 7 deletions cypress/integration/login/login_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,17 @@
// - Use element ID when selecting an element. Create one if none.
// ***************************************************************

/* eslint max-nested-callbacks: ["error", 4] */

let config;

describe('Login page', () => {
before(() => {
// 1. Go to login page
cy.apiGetConfig().then((response) => {
config = response.body;
});

// # Go to login page
cy.apiLogout();

cy.visit('/login');
Expand All @@ -20,13 +28,13 @@ describe('Login page', () => {
cy.get('#login_section').should('be.visible');

// * Check the title
cy.title().should('include', 'Mattermost');
cy.title().should('include', config.TeamSettings.SiteName);
});

it('should match elements, body', () => {
// * Check elements in the body
cy.get('#login_section').should('be.visible');
cy.get('#site_name').should('contain', 'Mattermost');
cy.get('#site_name').should('contain', config.TeamSettings.SiteName);
cy.get('#site_description').should('contain', 'All team communication in one place, searchable and accessible anywhere');
cy.get('#loginId').should('be.visible');
cy.get('#loginId').should('have.attr', 'placeholder', 'Email or Username');
Expand All @@ -44,13 +52,13 @@ describe('Login page', () => {
cy.get('#copyright').should('contain', '© 2015-');
cy.get('#copyright').should('contain', 'Mattermost, Inc.');
cy.get('#about_link').should('contain', 'About');
cy.get('#about_link').should('have.attr', 'href', 'https://about.mattermost.com/default-about/');
cy.get('#about_link').should('have.attr', 'href', config.SupportSettings.AboutLink);
cy.get('#privacy_link').should('contain', 'Privacy');
cy.get('#privacy_link').should('have.attr', 'href', 'https://about.mattermost.com/default-privacy-policy/');
cy.get('#privacy_link').should('have.attr', 'href', config.SupportSettings.PrivacyPolicyLink);
cy.get('#terms_link').should('contain', 'Terms');
cy.get('#terms_link').should('have.attr', 'href', 'https://about.mattermost.com/default-terms/');
cy.get('#terms_link').should('have.attr', 'href', config.SupportSettings.TermsOfServiceLink);
cy.get('#help_link').should('contain', 'Help');
cy.get('#help_link').should('have.attr', 'href', 'https://about.mattermost.com/default-help/');
cy.get('#help_link').should('have.attr', 'href', config.SupportSettings.HelpLink);
});

it('should login then logout by user-1', () => {
Expand Down
26 changes: 18 additions & 8 deletions cypress/integration/login/signup_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,18 @@
// - Use element ID when selecting an element. Create one if none.
// ***************************************************************

/* eslint max-nested-callbacks: ["error", 4] */

let config;

describe('Signup Email page', () => {
before(() => {
cy.apiGetConfig().then((response) => {
config = response.body;
});
cy.apiLogout();

// # Go to login page
saturninoabril marked this conversation as resolved.
Show resolved Hide resolved
// # Go to signup email page
cy.visit('/signup_email');
});
Expand All @@ -18,7 +28,7 @@ describe('Signup Email page', () => {
cy.get('#signup_email_section').should('be.visible');

// * Check the title
cy.title().should('include', 'Mattermost');
cy.title().should('include', config.TeamSettings.SiteName);
});

it('should match elements, back button', () => {
Expand All @@ -32,7 +42,7 @@ describe('Signup Email page', () => {
it('should match elements, body', () => {
// * Check elements in the body
cy.get('#signup_email_section').should('be.visible');
cy.get('#site_name').should('contain', 'Mattermost');
cy.get('#site_name').should('contain', config.TeamSettings.SiteName);
cy.get('#site_description').should('contain', 'All team communication in one place, searchable and accessible anywhere');
cy.get('#create_account').should('contain', 'Let\'s create your account');
cy.get('#signin_account').should('contain', 'Already have an account?');
Expand All @@ -56,8 +66,8 @@ describe('Signup Email page', () => {
cy.get('#createAccountButton').should('contain', 'Create Account');

cy.get('#signup_agreement').should('contain', 'By proceeding to create your account and use Mattermost, you agree to our Terms of Service and Privacy Policy. If you do not agree, you cannot use Mattermost.');
cy.get('#signup_agreement > span > [href="https://about.mattermost.com/default-terms/"]').should('be.visible');
cy.get('#signup_agreement > span > [href="https://about.mattermost.com/default-privacy-policy/"]').should('be.visible');
cy.get(`#signup_agreement > span > [href="${config.SupportSettings.TermsOfServiceLink}"]`).should('be.visible');
cy.get(`#signup_agreement > span > [href="${config.SupportSettings.PrivacyPolicyLink}"]`).should('be.visible');
});

it('should match elements, footer', () => {
Expand All @@ -67,12 +77,12 @@ describe('Signup Email page', () => {
cy.get('#copyright').should('contain', '© 2015-');
cy.get('#copyright').should('contain', 'Mattermost, Inc.');
cy.get('#about_link').should('contain', 'About');
cy.get('#about_link').should('have.attr', 'href', 'https://about.mattermost.com/default-about/');
cy.get('#about_link').should('have.attr', 'href', config.SupportSettings.AboutLink);
cy.get('#privacy_link').should('contain', 'Privacy');
cy.get('#privacy_link').should('have.attr', 'href', 'https://about.mattermost.com/default-privacy-policy/');
cy.get('#privacy_link').should('have.attr', 'href', config.SupportSettings.PrivacyPolicyLink);
cy.get('#terms_link').should('contain', 'Terms');
cy.get('#terms_link').should('have.attr', 'href', 'https://about.mattermost.com/default-terms/');
cy.get('#terms_link').should('have.attr', 'href', config.SupportSettings.TermsOfServiceLink);
cy.get('#help_link').should('contain', 'Help');
cy.get('#help_link').should('have.attr', 'href', 'https://about.mattermost.com/default-help/');
cy.get('#help_link').should('have.attr', 'href', config.SupportSettings.HelpLink);
Copy link
Member Author

@saturninoabril saturninoabril Jun 21, 2019

Choose a reason for hiding this comment

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

This is failing since cypress server has different config for SiteName and so, it's safe to use data from config instead of hard-coded values.

});
});
10 changes: 5 additions & 5 deletions cypress/integration/post_header/post_header_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ describe('Post Header', () => {
cy.visit('/ad-1/channels/town-square');

// # Post a message
cy.postMessage('test for permalink{enter}');
cy.postMessage('test for permalink');

// * Check initial state that "the jump to recent messages" is not visible
cy.get('#archive-link-home').should('not.be.visible');
Expand Down Expand Up @@ -62,7 +62,7 @@ describe('Post Header', () => {
cy.visit('/ad-1/channels/town-square');

// # Post a message
cy.postMessage('test for flagged post{enter}');
cy.postMessage('test for flagged post');

cy.getLastPostId().then((postId) => {
// * Check that the center flag icon of a post is not visible
Expand All @@ -87,7 +87,7 @@ describe('Post Header', () => {
cy.visit('/ad-1/channels/town-square');

// # Post a message
cy.postMessage('test for dropdown menu{enter}');
cy.postMessage('test for dropdown menu');

cy.getLastPostId().then((postId) => {
// * Check that the center dot menu' button and dropdown are hidden
Expand Down Expand Up @@ -115,7 +115,7 @@ describe('Post Header', () => {
cy.visit('/ad-1/channels/town-square');

// # Post a message
cy.postMessage('test for reaction and emoji picker{enter}');
cy.postMessage('test for reaction and emoji picker');

cy.getLastPostId().then((postId) => {
// * Check that the center post reaction icon and emoji picker are not visible
Expand Down Expand Up @@ -145,7 +145,7 @@ describe('Post Header', () => {
cy.visit('/ad-1/channels/town-square');

// # Post a message
cy.postMessage('test for opening and closing RHS{enter}');
cy.postMessage('test for opening and closing RHS');

// # Open RHS on hover to a post and click to its comment icon
cy.clickPostCommentIcon();
Expand Down
2 changes: 1 addition & 1 deletion cypress/integration/search/search_user_post.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ describe('Search in DMs', () => {
createNewDMChannel(users['user-2'].email);

// # Post message to user
cy.postMessage(message + '{enter}');
cy.postMessage(message);

// # Type `in:` in searchbox
cy.get('#searchBox').type('in:');
Expand Down
43 changes: 24 additions & 19 deletions cypress/plugins/post_message_as.js
Original file line number Diff line number Diff line change
@@ -1,35 +1,40 @@
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.

require('@babel/polyfill');
require('isomorphic-fetch');

const {Client4} = require('mattermost-redux/client');
const axios = require('axios');

const cypressConfig = require('../../cypress.json');

module.exports = async ({sender, message, channelId, createAt = 0}) => {
const url = `${cypressConfig.baseUrl}/api/v4/users/login`;

const response = await axios({
url,
const loginResponse = await axios({
url: `${cypressConfig.baseUrl}/api/v4/users/login`,
headers: {'X-Requested-With': 'XMLHttpRequest'},
method: 'post',
data: {login_id: sender.username, password: sender.password},
});

const token = response.headers.token;

Client4.setUrl(cypressConfig.baseUrl);
Client4.setToken(token);
const setCookie = loginResponse.headers['set-cookie'];
let cookieString = '';
setCookie.forEach((cookie) => {
const nameAndValue = cookie.split(';')[0];
cookieString += nameAndValue + ';';
});

const options = {
channel_id: channelId,
message,
type: '',
create_at: createAt,
};
const response = await axios({
url: `${cypressConfig.baseUrl}/api/v4/posts`,
headers: {
'Content-Type': 'application/json',
'X-Requested-With': 'XMLHttpRequest',
Cookie: cookieString,
},
method: 'post',
data: {
channel_id: channelId,
message,
type: '',
create_at: createAt,
},
});

return Client4.createPost(options);
return {status: response.status, data: response.data, error: response.error};
Copy link
Member Author

@saturninoabril saturninoabril Jun 21, 2019

Choose a reason for hiding this comment

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

Not totally sure why postMessageAs is not working as expected. I just removed the use of Client4; let's observe if it will pass on daily test.

Copy link
Contributor

Choose a reason for hiding this comment

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

mattermost-redux changes perhaps? I haven't looked at recent commits, but I think it's totally fine for us to use the API directly, ultimately that's what the client is doing. This way we have more control over the requests as well. 👍

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 think so as the current mattermost-redux is working locally but let's eliminate potential issue by going thru API call directly.

};
Loading