Skip to content

[java] implement performance support in session #270

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

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

titusfortner
Copy link
Collaborator

Three options here.

The one I did for Accessibility was like:

PerformanceResults results = session.getPerformanceResults();

The one that is probably "most Java" is:

PerformanceResults results = new Performance(session).getResults();

The one I implemented here is:

PerformanceResults results = session.performance().getResults();

Thoughts/Preferences?

Copy link
Contributor

@nadvolod nadvolod left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this approach
PerformanceResults results = session.performance().getResults();
I think that the API usage makes sense and I also like having the performance stored in a separate object Performance.

@@ -0,0 +1,6 @@
"https://www.saucedemo.com":
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@titusfortner can you please explain what this is and it's intended usage?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, for JS they use JSON; I wanted to implement something that uses a Map, so you can convert either yaml or json into the map it will work. I didn't want to use JSON because I don't want to deal with Jackson library, yet. :) More info: https://docs.saucelabs.com/performance/transitions#defining-a-performance-budget

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@titusfortner I worry that this feature is unnecessarily making the code complicated and overengineered. From my experience, customers aren't advanced enough to handle such a use case (or even me 😂). Instead they are only interested in 3 use cases. Specifically they like multiPagePerformanceExample() and the simplePerformanceTest()

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, We have docs for it with code examples, so I thought we should provide support for it. I'm not sure how much it would be used. I had some thoughts on expanding it later, but definitely not the thing that should be holding us up.

This is the kind of feature I wouldn't make an issue out of in the Sauce Bindings Documentation, but would have example code in the Sauce Docs with it for people who are interested in playing with it. As such, the confusion factor of the average user shouldn't really matter. It's the same kind of thing with the mergeCapabilities() in SauceOptions.

public void performanceDetails() {
driver.get("https://www.saucedemo.com");

PerformanceMetrics performanceMetrics = session.performance().getMetrics();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This confuses me. I don't understand the difference between a PerformanceMetrics and PerformanceResults

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we rename PerformanceMetrics to PerformanceLog.

PerformanceResults uses Sauce Labs magic AI values. You can pass in specific metrics you care about and Sauce will pass/fail it based on whether we think it is in range.

If you want to assert on anything based on a hard coded value instead of our magic, you need to first get the log.

I mean, maybe this should be:

PerformanceLogs performanceLogs = session.logs().getPerformance();

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense. The API call would be what you said or session.performance().getLogs()

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The other part of this is that it isn't all the logs, just the logs for the last page transition. session.logs() should be getting all the logs for something, so maybe session.performance().getLastLog()?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@titusfortner so if it's just for the last page transition then maybe?
session.performance().getLastPageTransitionLog()

@nadvolod nadvolod linked an issue Jul 22, 2021 that may be closed by this pull request
public void performanceMetricResults() {
driver.get("https://www.saucedemo.com");

PerformanceResults performanceResults = session.performance().getResults("firstInteractive");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@titusfortner should we move the parameter values into an enum? They've remained the same forever and it should improve usability

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, so long as we have getRawResults() I don't think there's a problem doing enums for this.

@@ -75,6 +77,13 @@ public Results getAccessibilityResults(AxeBuilder builder) {
return builder.analyze(driver);
}

public Performance performance() {
if (!sauceOptions.sauce().getCapturePerformance()) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what does this do for non-Chrome which doesn't have this method?

*
* @param metrics A List of values for which performance metrics to evaluate
* @return PerformanceResults is a wrapper of the HashMap results to make it easier to work with them
* @see <a href="https://docs.saucelabs.com/performance/transitions#implementing-the-performance-command-assertion">Implementing the Performance Command Assertion</a>
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these links are wrong for anchors, they need to be /# without index.html

/**
* This measures the performance output against a baseline of previously accepted performance values
*
* @return PerformanceResults is a wrapper of the HashMap results to make it easier to work with them
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

specify this is passed, reason, and details

* @return PerformanceResults is a wrapper of the HashMap results to make it easier to work with them
* @see <a href="https://docs.saucelabs.com/performance/transitions#implementing-the-performance-command-assertion">Implementing the Performance Command Assertion</a>
*/
public PerformanceResults getResults() {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

probably needs to be getAllResults() to better differentiate from other method

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add Sauce performance enablement and disablement
2 participants