From 25e856b43bf02424d503a7eac618adcd238ccafe Mon Sep 17 00:00:00 2001 From: Johan Brichau Date: Wed, 28 Feb 2024 20:00:12 +0100 Subject: [PATCH] Use wait statements to make the CORS test more reliable --- .../instance/getCORSResultText.st | 5 ++++ .../instance/testCORSFilterFunctionalTest.st | 24 +++++++------------ 2 files changed, 13 insertions(+), 16 deletions(-) create mode 100644 repository/Seaside-Tests-Parasol.package/WAWebDriverFunctionalTestCase.class/instance/getCORSResultText.st diff --git a/repository/Seaside-Tests-Parasol.package/WAWebDriverFunctionalTestCase.class/instance/getCORSResultText.st b/repository/Seaside-Tests-Parasol.package/WAWebDriverFunctionalTestCase.class/instance/getCORSResultText.st new file mode 100644 index 000000000..b12530fbd --- /dev/null +++ b/repository/Seaside-Tests-Parasol.package/WAWebDriverFunctionalTestCase.class/instance/getCORSResultText.st @@ -0,0 +1,5 @@ +helpers +getCORSResultText + + (Delay forMilliseconds: 300) wait. + ^ self waitUntilNoBPNoSuchElementExceptionIn: [ ((driver findElementByID: 'result') findElementByTagName: 'p') getText ] \ No newline at end of file diff --git a/repository/Seaside-Tests-Parasol.package/WAWebDriverFunctionalTestCase.class/instance/testCORSFilterFunctionalTest.st b/repository/Seaside-Tests-Parasol.package/WAWebDriverFunctionalTestCase.class/instance/testCORSFilterFunctionalTest.st index ded312173..3450f3ce3 100644 --- a/repository/Seaside-Tests-Parasol.package/WAWebDriverFunctionalTestCase.class/instance/testCORSFilterFunctionalTest.st +++ b/repository/Seaside-Tests-Parasol.package/WAWebDriverFunctionalTestCase.class/instance/testCORSFilterFunctionalTest.st @@ -7,35 +7,29 @@ testCORSFilterFunctionalTest self assert: (driver findElementByID: 'allowed-origins') getText equals: 'None'. (((driver findElementByID: 'get-requests') findElementsByTagName: 'button') detect: [ :button | button getText = 'Same Origin' ]) click. - (Delay forMilliseconds: 300) wait. - self assert: ((driver findElementByID: 'result') findElementByTagName: 'p') getText equals: 'Success'. + self assert: self getCORSResultText equals: 'Success'. (((driver findElementByID: 'get-requests') findElementsByTagName: 'button') detect: [ :button | button getText = 'Cross Origin' ]) click. - (Delay forMilliseconds: 300) wait. - self assert: ((driver findElementByID: 'result') findElementByTagName: 'p') getText equals: 'Error'. + self assert: self getCORSResultText equals: 'Error'. "Now test with cross-origin allowed" ((driver findElementsByTagName: 'button') detect: [ :button | button getText = 'Allow other origin' ]) click. (((driver findElementByID: 'get-requests') findElementsByTagName: 'button') detect: [ :button | button getText = 'Same Origin' ]) click. - (Delay forMilliseconds: 300) wait. - self assert: ((driver findElementByID: 'result') findElementByTagName: 'p') getText equals: 'Success'. + self assert: self getCORSResultText equals: 'Success'. (((driver findElementByID: 'get-requests') findElementsByTagName: 'button') detect: [ :button | button getText = 'Cross Origin' ]) click. - (Delay forMilliseconds: 300) wait. - self assert: ((driver findElementByID: 'result') findElementByTagName: 'p') getText equals: 'Success'. + self assert: self getCORSResultText equals: 'Success'. "the following statement is to circumvent testing issue with the dev toolbar being over the delete buttons" (driver findElementByID: 'result') moveToElement. (((driver findElementByID: 'delete-requests') findElementsByTagName: 'button') detect: [ :button | button getText = 'Same Origin' ]) click. - (Delay forMilliseconds: 300) wait. - self assert: ((driver findElementByID: 'result') findElementByTagName: 'p') getText equals: 'Success'. + self assert: self getCORSResultText equals: 'Success'. "the following statement is to circumvent testing issue with the dev toolbar being over the delete buttons" (driver findElementByID: 'result') moveToElement. (((driver findElementByID: 'delete-requests') findElementsByTagName: 'button') detect: [ :button | button getText = 'Cross Origin' ]) click. - (Delay forMilliseconds: 300) wait. - self assert: ((driver findElementByID: 'result') findElementByTagName: 'p') getText equals: 'Error'. + self assert: self getCORSResultText equals: 'Error'. ((driver findElementsByTagName: 'button') detect: [ :button | button getText = 'Allow DELETE' ]) click. @@ -43,13 +37,11 @@ testCORSFilterFunctionalTest (driver findElementByID: 'result') moveToElement. (((driver findElementByID: 'delete-requests') findElementsByTagName: 'button') detect: [ :button | button getText = 'Same Origin' ]) click. - (Delay forMilliseconds: 300) wait. - self assert: ((driver findElementByID: 'result') findElementByTagName: 'p') getText equals: 'Success'. + self assert: self getCORSResultText equals: 'Success'. "the following statement is to circumvent testing issue with the dev toolbar being over the delete buttons" (driver findElementByID: 'result') moveToElement. (((driver findElementByID: 'delete-requests') findElementsByTagName: 'button') detect: [ :button | button getText = 'Cross Origin' ]) click. - (Delay forMilliseconds: 300) wait. - self assert: ((driver findElementByID: 'result') findElementByTagName: 'p') getText equals: 'Success'. + self assert: self getCORSResultText equals: 'Success'. ] ensure: [ WACORSResourceExample unregister; unregisterCorsAdaptor ] \ No newline at end of file