From 54c93fc9458cae09243a4aa6e0b95a5ad5be0298 Mon Sep 17 00:00:00 2001 From: Clement Michaud Date: Sun, 8 Oct 2017 16:28:10 +0200 Subject: [PATCH] Fix randomness with integration tests The notification message pops up and hide after few seconds. Sometimes, chrome drivers tries to click on a button that moves due to the notification message animation and thus miss it. --- test/features/redirection.feature | 1 + test/features/step_definitions/authentication.ts | 9 +++++++++ test/features/step_definitions/notifications.ts | 2 +- 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/test/features/redirection.feature b/test/features/redirection.feature index 2b5a6602..12fba93b 100644 --- a/test/features/redirection.feature +++ b/test/features/redirection.feature @@ -8,6 +8,7 @@ Feature: User is correctly redirected Scenario: User is redirected to home page after several authentication tries When I visit "https://public.test.local:8080/secret.html" And I login with user "john" and password "badpassword" + And I wait for notification to disappear And I clear field "username" And I login with user "john" and password "password" And I use "REGISTERED" as TOTP token handle diff --git a/test/features/step_definitions/authentication.ts b/test/features/step_definitions/authentication.ts index 140434e8..6899d596 100644 --- a/test/features/step_definitions/authentication.ts +++ b/test/features/step_definitions/authentication.ts @@ -11,6 +11,15 @@ Cucumber.defineSupportCode(function ({ Given, When, Then }) { return this.visit(link); }); + When("I wait for notification to disappear", function() { + const that = this; + const notificationEl = this.driver.findElement(seleniumWebdriver.By.className("notification")); + return this.driver.wait(seleniumWebdriver.until.elementIsVisible(notificationEl), 15000) + .then(function() { + return that.driver.wait(seleniumWebdriver.until.elementIsNotVisible(notificationEl), 15000); + }) + }) + When("I set field {stringInDoubleQuotes} to {stringInDoubleQuotes}", function (fieldName: string, content: string) { return this.setFieldTo(fieldName, content); }); diff --git a/test/features/step_definitions/notifications.ts b/test/features/step_definitions/notifications.ts index 3a068129..8916ba7e 100644 --- a/test/features/step_definitions/notifications.ts +++ b/test/features/step_definitions/notifications.ts @@ -10,7 +10,7 @@ Cucumber.defineSupportCode(function ({ Given, When, Then }) { function (notificationType: string, notificationMessage: string) { const that = this; const notificationEl = this.driver.findElement(seleniumWebdriver.By.className("notification")); - return this.driver.wait(seleniumWebdriver.until.elementIsVisible(notificationEl), 2000) + return this.driver.wait(seleniumWebdriver.until.elementIsVisible(notificationEl), 5000) .then(function () { return notificationEl.getText(); })