diff --git a/.gitignore b/.gitignore index 53cee29..c075fe1 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,4 @@ .DS_Store -/target/ \ No newline at end of file +/target/ +/.idea +/SeleniumJavaDemoApp.iml diff --git a/pom.xml b/pom.xml index 219b5a0..ebb601d 100644 --- a/pom.xml +++ b/pom.xml @@ -9,18 +9,12 @@ Java-tutorial http://maven.apache.org - - - 10 - 10 - - com.applitools eyes-selenium-java3 - 3.151.2 + 3.160.0 @@ -30,12 +24,5 @@ test - - - javax.activation - activation - 1.1.1 - - diff --git a/src/main/java/com/applitools/quickstarts/VisualGridDemo.java b/src/main/java/com/applitools/quickstarts/VisualGridDemo.java deleted file mode 100644 index 8c824b0..0000000 --- a/src/main/java/com/applitools/quickstarts/VisualGridDemo.java +++ /dev/null @@ -1,110 +0,0 @@ -package com.applitools.quickstarts; - - -import com.applitools.eyes.selenium.BrowserType; -import com.applitools.eyes.selenium.Configuration; -import com.applitools.eyes.selenium.Eyes; -import com.applitools.eyes.selenium.fluent.Target; -import com.applitools.eyes.visualgrid.model.DeviceName; -import com.applitools.eyes.visualgrid.model.TestResultSummary; -import com.applitools.eyes.visualgrid.services.VisualGridRunner; -import org.openqa.selenium.By; -import org.openqa.selenium.WebDriver; -import org.openqa.selenium.chrome.ChromeDriver; - - - -import com.applitools.eyes.BatchInfo; - -public class VisualGridDemo { - - public static void main(String[] args) { - VisualGridDemo program = new VisualGridDemo(); - program.runTest(); - } - - public static Eyes initializeEyes(VisualGridRunner runner) { - // Create Eyes object with the runner, meaning it'll be a Visual Grid eyes. - Eyes eyes = new Eyes(runner); - - // Set API key - eyes.setApiKey("APPLITOOLS_API_KEY"); - - //If dedicated or on-prem cloud, uncomment and enter the cloud url - //Default: https://eyes.applitools.com - //eyes.setServerUrl("https://testeyes.applitools.com"); - - - // Create SeleniumConfiguration. - Configuration sconf = new Configuration(); - - // Set the AUT name - sconf.setAppName("Bank App"); - - // Set a test name - sconf.setTestName("Smoke Test via Visual Grid"); - - // Set a batch name so all the different browser and mobile combinations are - // part of the same batch - sconf.setBatch(new BatchInfo("VIP Browser combo batch")); - - // Add Chrome browsers with different Viewports - sconf.addBrowser(800, 600, BrowserType.CHROME); - sconf.addBrowser(700, 500, BrowserType.CHROME); - - // Add Firefox browser with different Viewports - sconf.addBrowser(1200, 800, BrowserType.FIREFOX); - sconf.addBrowser(1600, 1200, BrowserType.FIREFOX); - - // Add iPhone 4 device emulation - sconf.addDeviceEmulation(DeviceName.iPhone_4); - - // Set the configuration object to eyes - eyes.setConfiguration(sconf); - - return eyes; - } - - private void runTest() { - - // Create a runner with concurrency of 10 - VisualGridRunner runner = new VisualGridRunner(10); - - //Initialize Eyes with Visual Grid Runner - Eyes eyes = initializeEyes(runner); - - // Create a new Webdriver - WebDriver webDriver = new ChromeDriver(); - - // Navigate to the URL we want to test - webDriver.get("https://demo.applitools.com"); - - // To see visual bugs, change the above URL to: - // https://demo.applitools.com/index_v2.html and run the test again - - - // Call Open on eyes to initialize a test session - eyes.open(webDriver); - - // Check the Login page - eyes.check(Target.window().fully().withName("Step 1 - Login page")); - - // Click on the Login button to go to the App's main page - webDriver.findElement(By.id("log-in")).click(); - - // Check the App page - eyes.check(Target.window().fully().withName("Step 2 - App Page")); - - // Close the browser - webDriver.quit(); - - System.out.println( - "Please wait... we are now: \n1. Uploading resources, \n2. Rendering in Visual Grid, and \n3. Using Applitools A.I. to validate the checkpoints. \nIt'll take about 30 secs to a minute..."); - - // Close eyes asynchronously - eyes.closeAsync(); - TestResultSummary allTestResults = runner.getAllTestResults(); - System.out.println(allTestResults); - - } -} diff --git a/src/test/java/com/applitools/quickstarts/AppTest.java b/src/test/java/com/applitools/quickstarts/AppTest.java index 36c55f2..5ddfc80 100644 --- a/src/test/java/com/applitools/quickstarts/AppTest.java +++ b/src/test/java/com/applitools/quickstarts/AppTest.java @@ -1,38 +1,88 @@ package com.applitools.quickstarts; -import junit.framework.Test; -import junit.framework.TestCase; -import junit.framework.TestSuite; +import com.applitools.eyes.TestResultsSummary; +import com.applitools.eyes.selenium.BrowserType; +import com.applitools.eyes.selenium.Configuration; +import com.applitools.eyes.selenium.Eyes; +import com.applitools.eyes.selenium.fluent.Target; +import com.applitools.eyes.visualgrid.model.DeviceName; +import com.applitools.eyes.visualgrid.model.ScreenOrientation; +import com.applitools.eyes.visualgrid.services.VisualGridRunner; +import org.junit.Test; +import org.openqa.selenium.By; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.chrome.ChromeDriver; /** * Unit test for simple App. */ -public class AppTest - extends TestCase +public class AppTest { - /** - * Create the test case - * - * @param testName name of the test case - */ - public AppTest( String testName ) + @Test + public void VGTest() { - super( testName ); - } + // Create a new webdriver + WebDriver webDriver = new ChromeDriver(); - /** - * @return the suite of tests being tested - */ - public static Test suite() - { - return new TestSuite( AppTest.class ); - } + // Navigate to the url we want to test + webDriver.get("https://demo.applitools.com"); - /** - * Rigourous Test :-) - */ - public void testApp() - { - assertTrue( true ); + // ⭐️ 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) + + // Create a runner with concurrency of 10 + VisualGridRunner runner = new VisualGridRunner(10); + + // Create Eyes object with the runner, meaning it'll be a Visual Grid eyes. + Eyes eyes = new Eyes(runner); + + // Get current Eyes configuration object + Configuration conf = eyes.getConfiguration(); + + + //conf.setApiKey("APPLITOOLS_API_KEY"); // Set the Applitools API KEY here or as an environment variable "APPLITOOLS_API_KEY" + conf.setTestName("Java VisualGrid demo") // Set test name + .setAppName("Demo app"); // Set app name + + // Add browsers with different viewports + conf.addBrowser(800, 600, BrowserType.CHROME); + conf.addBrowser(700, 500, BrowserType.FIREFOX); + conf.addBrowser(1200, 800, BrowserType.IE_10); + conf.addBrowser(1600, 1200, BrowserType.IE_11); + conf.addBrowser(1024, 768, BrowserType.EDGE); + conf.addBrowser(800, 600, BrowserType.SAFARI); + + // Add iPhone 4 device emulation in Portrait mode + conf.addDeviceEmulation(DeviceName.iPhone_4, ScreenOrientation.PORTRAIT); + + + // Set the configuration object to eyes + eyes.setConfiguration(conf); + + try + { + // Call Open on eyes to initialize a test session + eyes.open(webDriver); + + // check the login page + 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(); + } + finally + { + // Close the browser + webDriver.quit(); + } + + // Wait and collect all test results + TestResultsSummary allTestResults = runner.getAllTestResults(); + System.out.println(allTestResults); } + }