From 209b36c73b586a19560512846c56d040733dc151 Mon Sep 17 00:00:00 2001 From: Nolan Lawson Date: Sat, 21 Apr 2018 13:06:46 -0700 Subject: [PATCH] fix flaky login tests (#209) --- tests/roles.js | 10 +++++++--- tests/spec/002-login-spec.js | 8 +++++--- tests/utils.js | 2 ++ 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/tests/roles.js b/tests/roles.js index 24815f82..7673af78 100644 --- a/tests/roles.js +++ b/tests/roles.js @@ -1,13 +1,17 @@ import { Role } from 'testcafe' -import { authorizeInput, emailInput, getUrl, instanceInput, passwordInput } from './utils' +import { + addInstanceButton, + authorizeInput, emailInput, getUrl, instanceInput, mastodonLogInButton, + passwordInput +} from './utils' function login (t, username, password) { return t.typeText(instanceInput, 'localhost:3000', {paste: true}) - .pressKey('enter') + .click(addInstanceButton) .expect(getUrl()).eql('http://localhost:3000/auth/sign_in') .typeText(emailInput, username, {paste: true}) .typeText(passwordInput, password, {paste: true}) - .pressKey('enter') + .click(mastodonLogInButton) .expect(getUrl()).contains('/oauth/authorize') .click(authorizeInput) .expect(getUrl()).eql('http://localhost:4002/', {timeout: 20000}) diff --git a/tests/spec/002-login-spec.js b/tests/spec/002-login-spec.js index ec2d5e2f..a660611a 100644 --- a/tests/spec/002-login-spec.js +++ b/tests/spec/002-login-spec.js @@ -1,6 +1,8 @@ import { Selector as $ } from 'testcafe' import { + addInstanceButton, authorizeInput, emailInput, formError, getFirstVisibleStatus, getUrl, instanceInput, logInToInstanceLink, + mastodonLogInButton, passwordInput, settingsButton } from '../utils' @@ -12,11 +14,11 @@ function manualLogin (t, username, password) { return t.click(logInToInstanceLink) .expect(getUrl()).contains('/settings/instances/add') .typeText(instanceInput, 'localhost:3000') - .pressKey('enter') + .click(addInstanceButton) .expect(getUrl()).eql('http://localhost:3000/auth/sign_in') .typeText(emailInput, username, {paste: true}) .typeText(passwordInput, password, {paste: true}) - .pressKey('enter') + .click(mastodonLogInButton) .expect(getUrl()).contains('/oauth/authorize') .click(authorizeInput) .expect(getUrl()).eql('http://localhost:4002/') @@ -26,7 +28,7 @@ test('Cannot log in to a fake instance', async t => { await t.click(logInToInstanceLink) .expect(getUrl()).contains('/settings/instances/add') .typeText(instanceInput, 'fake.nolanlawson.com', {paste: true}) - .pressKey('enter') + .click(addInstanceButton) .expect(formError.exists).ok() .expect(formError.innerText).contains('Is this a valid Mastodon instance?') .typeText(instanceInput, '.biz', {paste: true}) diff --git a/tests/utils.js b/tests/utils.js index 13a75c56..9ff0cf5f 100644 --- a/tests/utils.js +++ b/tests/utils.js @@ -37,6 +37,8 @@ export const accountProfileFollowedBy = $('.account-profile .account-profile-fol export const accountProfileFollowButton = $('.account-profile .account-profile-follow button') export const goBackButton = $('.dynamic-page-go-back') export const accountProfileMoreOptionsButton = $('.account-profile-more-options button') +export const addInstanceButton = $('#submitButton') +export const mastodonLogInButton = $('button[type="submit"]') export const favoritesCountElement = $('.status-favs-reblogs:nth-child(3)').addCustomDOMProperties({ innerCount: el => parseInt(el.innerText, 10)