-
Notifications
You must be signed in to change notification settings - Fork 46
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
#2238 Write function to compare transform string in Cypress tests #2225
#2238 Write function to compare transform string in Cypress tests #2225
Conversation
Signed-off-by: Jerin George <[email protected]>
Signed-off-by: Jerin George <[email protected]>
…ng comments Signed-off-by: Jerin George <[email protected]>
// Test get Zoom to reveal & ZoomTo | ||
cy.selectEntryFromDropdown("Histogram"); | ||
cy.setXPercentOffset(70); | ||
cy.setYPercentOffset(60); | ||
cy.submitAPI(); | ||
cy.wait(500); |
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.
Are these wait
s necessary? It seems strange that you are adding them even in places where the code was running OK before. We should remove all unnecessary wait
s. Also, if we do have to add them 500 (half a second) seems like a long time to wait. While it won't affect the overall run time of the test too much by adding them it is our usual practice to keep them as small as reasonably possible.
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.
After api calls there needs a minimum wait time required, Test will fail if the wait time less than 500ms as it required after api call.
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.
I'm not sure how you can say that since the verify code isn't / wasn't working correctly. Do you mean these are needed when the test run on your own Mac ?
// TODO -- write function to test these +/- 2 px. | ||
// cy.verifyCanvasTransform("translate(498.32727272727266,290.85454545454536) scale(0.9090909090909091)"); | ||
cy.wait(500); | ||
cy.verifyCanvasTransform("translate(498.32727272727266,290.85454545454536) scale(0.9090909090909091)"); |
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.
Did you test to see if your code will return an error if an incorrect value is provided? I tried changing this line to:
cy.verifyCanvasTransform("translate(200,290.85454545454536) scale(0.9090909090909091)");
That is, with 200 as the x parameter and the test passed!
When writing any tests, it is just as important to make sure the test will fail, in an invalid situation, as it is to make sure the test passes. If the test doesn't fail in the invalid situation then there would be no reason to run the test in the first place -- right?
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.
.should("eq", movString); | ||
// Verify the argument passed is a string | ||
if (movString === String) { | ||
cy.get("#canvas-div-0 .d3-canvas-group", { timeout: 10000 }) |
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.
Is the timeout
needed here. I see from the docs that the default is 4000 (4 seconds) which should be ample time for anything to happen in Common Canvas. We don't set this timeout anywhere else in the Cypress tests so if it isn't needed please remove it.
compareCloseTo(actualValues.translateY, expectedValues.translateY); | ||
compareCloseTo(actualValues.scale, expectedValues.scale); | ||
}); | ||
} |
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.
I know it ought to be unlikely but, what happens here if movString
is not a string? Will the function return as if the comparison succeeded? If so that not what we want as we want the test to fail in all error situations.
If you are testing for a string higher up in the function because sometimes zoom.cy.js passes in an undefined value then your code should specifically test for "undefined" and return success and in any other case (other than "string" ) return failure. In fact, since undefined is a value that is specifically passed in by zoom.cy.js, what the function ought to do is make sure the actualTransformString
is undefined in that situation.
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.
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.
Although I'm sure it works, that's a strange way to write the if / else if / else
code. It would read better if you have the two "positive" cases first and then a catch all case which returns the error in the bottom (as the else).
.invoke("attr", "transform") | ||
.should("eq", movString); | ||
// Verify the argument passed is a string | ||
if (movString === String) { |
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.
This isn't how you test for a string. This line of code is the reason invalid test situations are returning success (as mentioned in my comment above). You should use typeof
to test for the type of a variable.
compareCloseTo(actualValues.translateY, expectedValues.translateY); | ||
compareCloseTo(actualValues.scale, expectedValues.scale); | ||
}); | ||
} |
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.
Although I'm sure it works, that's a strange way to write the if / else if / else
code. It would read better if you have the two "positive" cases first and then a catch all case which returns the error in the bottom (as the else).
// Test get Zoom to reveal & ZoomTo | ||
cy.selectEntryFromDropdown("Histogram"); | ||
cy.setXPercentOffset(70); | ||
cy.setYPercentOffset(60); | ||
cy.submitAPI(); | ||
cy.wait(500); |
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.
I'm not sure how you can say that since the verify code isn't / wasn't working correctly. Do you mean these are needed when the test run on your own Mac ?
…ests (elyra-ai#2225) Signed-off-by: Jerin George <[email protected]>
@tomlyn ,I have pushed new commit as the issue with the cy.wait is because of using .then instead of .should, we can ignore the unnecessary wait time now. |
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.
LGTM
Fixes: #2238
Developer's Certificate of Origin 1.1