Skip to content

Commit

Permalink
Merge pull request #1404 from SeasideSt/corstest-fix
Browse files Browse the repository at this point in the history
Use wait statements to make the CORS test more reliable
  • Loading branch information
jbrichau authored Feb 28, 2024
2 parents f8c9257 + 25e856b commit 7543e51
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 16 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
helpers
getCORSResultText

(Delay forMilliseconds: 300) wait.
^ self waitUntilNoBPNoSuchElementExceptionIn: [ ((driver findElementByID: 'result') findElementByTagName: 'p') getText ]
Original file line number Diff line number Diff line change
Expand Up @@ -7,49 +7,41 @@ 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.

"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: 'Success'.
self assert: self getCORSResultText equals: 'Success'.

] ensure: [ WACORSResourceExample unregister; unregisterCorsAdaptor ]

0 comments on commit 7543e51

Please sign in to comment.