-
Notifications
You must be signed in to change notification settings - Fork 8.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix flaky test by verifying that a search has been saved by checking for a success toast #21302
Changes from 3 commits
15466c2
af8089b
3302926
eedebd0
614cebd
5d19276
6eedadf
6caf740
f3334ef
e752ec0
838e91e
d6298a1
645a3c7
4c26f4c
8912ffe
14e3e75
1260440
4b87d45
b05fd92
9f74eef
8e43781
2b64fb8
3847816
10d7bfa
c953d42
7a5a82f
39bf935
eb09cbe
37e7864
9998372
cb8212e
37ba74b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -53,6 +53,10 @@ export function DiscoverPageProvider({ getService, getPageObjects }) { | |
await getRemote().findDisplayedById('SaveSearch').pressKeys(searchName); | ||
await testSubjects.click('discoverSaveSearchButton'); | ||
await PageObjects.header.waitUntilLoadingHasFinished(); | ||
|
||
// Make sure toast exists and then close it. | ||
await testSubjects.existOrFail('saveSearchSuccess'); | ||
await find.clickByCssSelector('[data-test-subj="saveSearchSuccess"] [data-test-subj="toastCloseButton"]'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. All of the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If I were reading the code and I saw this on its own: await testSubject.click('saveSearchSuccess toastCloseButton'); It would not be clear to me why we're closing a toast that we haven't even looked at yet. The code implies the toast exists, but it doesn't verify this. I might even remove this code thinking that cleanup doesn't matter in this case, completely overlooking the role it plays as an assertion. For me, the intent behind the code is clearer with two explicit actions: 1) the verification of success and 2) the removal of the toast to clean up the UI.
They'll disappear after a few seconds, but as soon as There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
yes
Well, there is still a delay, just a very minor one, like, whatever time it takes the code to execute the next line.
We don't add manual assertions that any given button exists, for instance, before we click it. Actually, we kind of do, but it's part of the click function, so we don't have to add a manual check before every click call. What this is doing is adding that manual call that already exists inside the click function.
sgtm. We seem to be doing well with flakiness so maybe this doesn't do anything extra. I guess the way I see it is the only thing this code does is add a very slight potential for extra flakiness by having a check for "existsOrFail" and then the subsequent click. What if, for instance, the "existsOrFail" function ends up searching through a bunch of DOM elements before it gets to the toast, so that function call takes a few seconds to return true, then before the next line can execute, the toast disappears. Unlikely (especially because the existsOfFail check takes max 1 s), but maybe possible? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I think I understand how you're approaching this. I think you're looking at this from the angle of "How do we remove points of failure", which I totally get. I'm looking at it from the point of view of "How do we make this code clear to the reader", which is an orthogonal concern to yours.
I think what you're saying makes sense. I think this is possible and it's a valid concern. Though I'm not sure what's the best way to satisfy both of our concerns. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Sorry, I read this wrong earlier. I thought you were saying you were actually going to remove the code you added because it doesn't matter. I'm confused by your intentions with this PR. Initially I thought your goal was to avoid flakiness. If you want to extend the tests to make them more robust (fail more often than they otherwise might now), I can see why you would add both lines (primarily want to make sure the toast is there, secondarily I want to dismiss it). Or are you trying to reduce flakiness by first making sure the toast exists before dismissing it? In which case, the first line is pointless. I'm just confused by what actually fixes the flakiness of the other test. You wrote
But that doesn't make sense to me, why would adding a more thorough check cause it to pass? If it does pass, it seems like it's accidental (like the extra check is similar to adding a little sleep and hence, you don't hit whatever you were hitting before). I suppose it doesn't too much matter. You can check this code in and maybe it'll accidentally help with stability, but it seems like there is an underlying issue that might show up later. |
||
} | ||
|
||
async getColumnHeaders() { | ||
|
@@ -221,8 +225,9 @@ export function DiscoverPageProvider({ getService, getPageObjects }) { | |
async clickCopyToClipboard() { | ||
await testSubjects.click('sharedSnapshotCopyButton'); | ||
|
||
// Confirm that the content was copied to the clipboard. | ||
return await testSubjects.exists('shareCopyToClipboardSuccess'); | ||
// Confirm that the content was copied to the clipboard and close the toast. | ||
await testSubjects.existOrFail('shareCopyToClipboardSuccess'); | ||
await find.clickByCssSelector('[data-test-subj="shareCopyToClipboardSuccess"] [data-test-subj="toastCloseButton"]'); | ||
} | ||
|
||
async getShareCaption() { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,7 +21,6 @@ | |
export function DashboardVisualizationProvider({ getService, getPageObjects }) { | ||
const log = getService('log'); | ||
const queryBar = getService('queryBar'); | ||
const testSubjects = getService('testSubjects'); | ||
const dashboardAddPanel = getService('dashboardAddPanel'); | ||
const PageObjects = getPageObjects(['dashboard', 'visualize', 'header', 'discover']); | ||
|
||
|
@@ -56,8 +55,6 @@ export function DashboardVisualizationProvider({ getService, getPageObjects }) { | |
} | ||
|
||
await PageObjects.discover.saveSearch(name); | ||
await PageObjects.header.waitUntilLoadingHasFinished(); | ||
await testSubjects.exists('saveSearchSuccess'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. how come no replacement with the dismissing of toast here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. oh nm you probably moved it into There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Right, |
||
} | ||
|
||
async createAndAddSavedSearch({ name, query, fields }) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does using
await testSubjects.click('saveDashboardSuccess toastCloseButton');
work? I see that style used somewhere else.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good call, according to the tests for the test subj package, that should work.