Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@

2. Import the project as a *Maven* project in Eclipse or IntelliJ.
3. Set your API key in the _APPLITOOLS_API_KEY_ env variable. Get an API key by logging into Applitools > Person Icon > My API Key
4. Click the 'Run' button in Eclipse/IntelliJ
4. Run 'mvn -Dtest=AppTest test' or click the 'Run' button in Eclipse/IntelliJ

Read more here: https://www.applitools.com/tutorials/selenium-java.html
11 changes: 11 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,23 @@
<name>Java-tutorial</name>
<url>http://maven.apache.org</url>

<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>

<dependencies>
<!-- This is the Applitools Selenium Java SDK -->
<dependency>
<groupId>com.applitools</groupId>
<artifactId>eyes-selenium-java3</artifactId>
<version>RELEASE</version>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>7.1.0</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
106 changes: 51 additions & 55 deletions src/test/java/com/applitools/quickstarts/AppTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,38 +13,74 @@
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.annotations.Test;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.AfterMethod;

/**
* Unit test for simple App.
*/
public class AppTest {

public static void main(String[] args) {
private WebDriver webDriver;
private VisualGridRunner runner;
private Eyes eyes;

@Test
public void ultraFastTest() {
// ⭐️ Note to see visual bugs, run the test using the above URL for the 1st run.
// but then change the above URL to https://demo.applitools.com/index_v2.html
// (for the 2nd run)
// Navigate to the url we want to test
webDriver.get("https://demo.applitools.com");

// Call Open on eyes to initialize a test session
eyes.open(webDriver, "Demo App", "Ultrafast grid demo");

// check the login page with fluent api, see more info here
// https://applitools.com/docs/topics/sdk/the-eyes-sdk-check-fluent-api.html
eyes.check(Target.window().fully().withName("Login page"));

webDriver.findElement(By.id("log-in")).click();

// Check the app page
eyes.check(Target.window().fully().withName("App page"));

// Call Close on eyes to let the server know it should display the results
eyes.closeAsync();
}

@BeforeMethod
public void beforeEach () {
// Create a new chrome web driver
WebDriver webDriver = new ChromeDriver();
webDriver = new ChromeDriver();

// Create a runner with concurrency of 1
VisualGridRunner runner = new VisualGridRunner(1);
runner = new VisualGridRunner(1);

// Create Eyes object with the runner, meaning it'll be a Visual Grid eyes.
Eyes eyes = new Eyes(runner);
eyes = new Eyes(runner);

setUp(eyes);
setUp();
}

@AfterMethod
public void after() {

try {
// ⭐️ Note to see visual bugs, run the test using the above URL for the 1st run.
// but then change the above URL to https://demo.applitools.com/index_v2.html
// (for the 2nd run)
ultraFastTest(webDriver, eyes);
// Close the browser
webDriver.quit();

} finally {
tearDown(webDriver, runner);
}
// we pass false to this method to suppress the exception that is thrown if we
// find visual differences
TestResultsSummary allTestResults = runner.getAllTestResults(false);
// Print results
System.out.println(allTestResults);

// If the test was aborted before eyes.close was called, ends the test as aborted.
eyes.abortIfNotClosed();
}

public static void setUp(Eyes eyes) {

private void setUp() {
// Initialize eyes Configuration
Configuration config = new Configuration();

Expand All @@ -67,45 +103,5 @@ public static void setUp(Eyes eyes) {

// Set the configuration object to eyes
eyes.setConfiguration(config);

}

public static void ultraFastTest(WebDriver webDriver, Eyes eyes) {

try {

// Navigate to the url we want to test
webDriver.get("https://demo.applitools.com");

// Call Open on eyes to initialize a test session
eyes.open(webDriver, "Demo App", "Ultrafast grid demo", new RectangleSize(800, 600));

// check the login page with fluent api, see more info here
// https://applitools.com/docs/topics/sdk/the-eyes-sdk-check-fluent-api.html
eyes.check(Target.window().fully().withName("Login page"));

webDriver.findElement(By.id("log-in")).click();

// Check the app page
eyes.check(Target.window().fully().withName("App page"));

// Call Close on eyes to let the server know it should display the results
eyes.closeAsync();

} catch (Exception e) {
eyes.abortAsync();
}

}

private static void tearDown(WebDriver webDriver, VisualGridRunner runner) {
// Close the browser
webDriver.quit();

// we pass false to this method to suppress the exception that is thrown if we
// find visual differences
TestResultsSummary allTestResults = runner.getAllTestResults(false);
System.out.println(allTestResults);
}

}