From 8e9a46fff9f230f00c6dfb29bcfda2ceeec2c38a Mon Sep 17 00:00:00 2001 From: Suraj Shetty Date: Tue, 7 Sep 2021 19:57:57 +0530 Subject: [PATCH] test: Miscellaneous fixes to avoid flaky tests --- cypress/integration/api.js | 11 ++++++++--- .../datetime_field_form_validation.js | 17 +++++++---------- frappe/tests/ui_test_helpers.py | 11 +++++------ 3 files changed, 20 insertions(+), 19 deletions(-) diff --git a/cypress/integration/api.js b/cypress/integration/api.js index 7a5b1611b0..e8c39e6e25 100644 --- a/cypress/integration/api.js +++ b/cypress/integration/api.js @@ -31,8 +31,13 @@ context('API Resources', () => { }); it('Removes the Comments', () => { - cy.get_list('Comment').then(body => body.data.forEach(comment => { - cy.remove_doc('Comment', comment.name); - })); + cy.get_list('Comment').then(body => { + let comment_names = []; + body.data.map(comment => comment_names.push(comment.name)); + comment_names = [...new Set(comment_names)]; // remove duplicates + comment_names.forEach((comment_name) => { + cy.remove_doc('Comment', comment_name); + }); + }); }); }); diff --git a/cypress/integration/datetime_field_form_validation.js b/cypress/integration/datetime_field_form_validation.js index 66fdde6863..cb862152b4 100644 --- a/cypress/integration/datetime_field_form_validation.js +++ b/cypress/integration/datetime_field_form_validation.js @@ -2,18 +2,15 @@ context('Datetime Field Validation', () => { before(() => { cy.login(); cy.visit('/app/communication'); - cy.window().its('frappe').then(frappe => { - frappe.call("frappe.tests.ui_test_helpers.create_communication_records"); - }); }); - // validating datetime field value when value is set from backend and get validated on form load. it('datetime field form validation', () => { - cy.visit('/app/communication'); - cy.get('a[title="Test Form Communication 1"]').invoke('attr', 'data-name') - .then((name) => { - cy.visit(`/app/communication/${name}`); - cy.get('.indicator-pill').should('contain', 'Open').should('have.class', 'red'); - }); + // validating datetime field value when value is set from backend and get validated on form load. + cy.window().its('frappe').then(frappe => { + return frappe.xcall("frappe.tests.ui_test_helpers.create_communication_record"); + }).then(doc => { + cy.visit(`/app/communication/${doc.name}`); + cy.get('.indicator-pill').should('contain', 'Open').should('have.class', 'red'); + }); }); }); \ No newline at end of file diff --git a/frappe/tests/ui_test_helpers.py b/frappe/tests/ui_test_helpers.py index d8ad728136..9f6ad70a35 100644 --- a/frappe/tests/ui_test_helpers.py +++ b/frappe/tests/ui_test_helpers.py @@ -62,16 +62,15 @@ def create_todo_records(): }).insert() @frappe.whitelist() -def create_communication_records(): - if frappe.db.get_all('Communication', {'subject': 'Test Form Communication 1'}): - return - - frappe.get_doc({ +def create_communication_record(): + doc = frappe.get_doc({ "doctype": "Communication", "recipients": "test@gmail.com", "subject": "Test Form Communication 1", "communication_date": frappe.utils.now_datetime(), - }).insert() + }) + doc.insert() + return doc @frappe.whitelist() def setup_workflow():