Skip to content

Visual testing API #182

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

Closed
wants to merge 3 commits into from
Closed

Visual testing API #182

wants to merge 3 commits into from

Conversation

nadvolod
Copy link
Contributor

@nadvolod nadvolod commented Sep 25, 2020

This is PR designed to iron out the visual API. Once we agree on it we can work on making it happen.
Here is a real world example of a current usage of Screener for visual testing https://github.com/saucelabs-training/demo-java/blob/master/java8/visual-e2e/visuale2e.junit4.examples/src/test/java/com/saucedemo/VisualCrossPlatformTests.java

Copy link
Contributor Author

nadvolod commented Oct 5, 2020

Codacy Here is an overview of what got changed by this pull request:

Issues
======
- Added 8
           

Complexity increasing per file
==============================
- java/src/main/java/com/saucelabs/saucebindings/visual/SauceVisualOptions.java  4
- java/src/test/java/com/saucelabs/saucebindings/integration/VisualE2ETest.java  1
- java/src/test/java/com/saucelabs/saucebindings/SauceVisualSession.java  3
         

See the complete overview on Codacy

public class SauceVisualOptions {
private final MutableCapabilities visualCapabilities;
private String visualProjectName;
private String viewportSize;
Copy link
Contributor Author

Choose a reason for hiding this comment

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


public class SauceVisualOptions {
private final MutableCapabilities visualCapabilities;
private String visualProjectName;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

public class SauceVisualOptions {
private final MutableCapabilities visualCapabilities;
private String visualProjectName;
private String viewportSize;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

import org.openqa.selenium.MutableCapabilities;

public class SauceVisualOptions {
private final MutableCapabilities visualCapabilities;
Copy link
Contributor Author

Choose a reason for hiding this comment

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


@Getter
@Setter
private String hubUrl = "https://hub.screener.io/wd/hub";
Copy link
Contributor Author

Choose a reason for hiding this comment

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

import com.saucelabs.saucebindings.visual.SauceVisualOptions;
import lombok.Getter;
import lombok.Setter;
import lombok.var;
Copy link
Contributor Author

Choose a reason for hiding this comment

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


public class SauceVisualOptions {
private final MutableCapabilities visualCapabilities;
private String visualProjectName;
Copy link
Contributor Author

Choose a reason for hiding this comment

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


import com.saucelabs.saucebindings.SauceVisualSession;
import com.saucelabs.saucebindings.visual.SauceVisualOptions;
import lombok.var;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@titusfortner
Copy link
Collaborator

Should we have a separate session class for Visual?

We could do something as simple as:

SauceOptions options = new SauceOptions();
options.setVisual();

SauceSession session = new SauceSession(options);

We don't necessarily need a VisualOptions class either:

SauceOptions options = new SauceOptions();
options.setName("visualProjectName");
options.setScreenResolution("1280x1024") // same as viewportSize

We could even use a takeScreenshot() method that would work for normal Sauce sessions

session.takeScreenshot("Snapshot name");

@nadvolod
Copy link
Contributor Author

nadvolod commented Oct 9, 2020

@titusfortner I really like your approach. It's certainly cleaner. I went to separate classes because it seemed like that's the same direction we were going in mobile. So I tried to keep it similar. Regardless, I do want to iron out the use case below. To me, there is ambiguity when using/re-using methods because it means that they will have different behavior depending on whether you are using functional or visual, potentially breaking SRP.

    public void withVisualOptions() {
        SauceOptions options = new SauceOptions();
        //This becomes a mandatory call in order to start calling the methods below,
        //otherwise they become useless/confusing methods?
        options.setVisual();

        // is it clear that setProjectName only applies to Sauce Visual and not to Functional?
        options.setProjectName("Sauce Bindings");

        // how do we know that this is for visual?
        options.setViewportSize("1280x1024");

        var visualSession = new SauceSession(visualOptions);

        //Not sure if you always need to set test name,
        //but if we do then maybe we can just do start(testName);
        visualSession.start();

        visualSession.setTestName("Visual Test");

        //Same thing here, do we want ambiguity between visual and functional so that when we call this method,
        // users might be confused about why the snapshot isn't happening in their functional test
        visualSession.takeSnapshot("Snapshot name 1");

        Boolean isPassed = visualSession.stop();
        assertTrue(isPassed);
    }

This seems like a blend of both and solves the ambiguity:

    public void withVisualOptions() {
        SauceOptions options = new SauceOptions();
        options.setVisual();
        options.visual.setProjectName("Sauce Bindings");
        options.visual.setViewportSize("1280x1024");

Base automatically changed from master to main March 15, 2021 20:20
@titusfortner
Copy link
Collaborator

Superceded by #256

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.

2 participants