private void Run()
        {
            // Create a new webdriver
            IWebDriver webDriver = new ChromeDriver();

            // Navigate to the url we want to test
            webDriver.Url = "https://demo.applitools.com";

            // ⭐️ 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);

            // Create configuration object
            Configuration conf = new Configuration();



            //conf.SetApiKey("APPLITOOLS_API_KEY");    // Set the Applitools API KEY here or as an environment variable "APPLITOOLS_API_KEY"
            conf.SetTestName("C# 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);

            // Add iPhone 4 device emulation in Portrait mode
            conf.AddDeviceEmulation(DeviceName.iPhone_4, ScreenOrientation.Portrait);


            // Set the configuration object to eyes
            eyes.SetConfiguration(conf);

            // 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"));

            // Close the browser
            webDriver.Quit();

            eyes.CloseAsync();

            //Wait and collect all test results
            TestResultSummary allTestResults = runner.GetAllTestResults();

            System.Console.WriteLine(allTestResults);
        }
コード例 #2
0
        public void TestMethod2()
        {
            String shouldBreakSiteStr = Environment.GetEnvironmentVariable("INJECT_BUG");

            bool shouldBreakSite = false;

            if (shouldBreakSiteStr != null && shouldBreakSiteStr.Length > 0)
            {
                shouldBreakSite = bool.Parse(shouldBreakSiteStr);
            }

            String testName = "Functional VS Visual";

            VisualGridRunner runner = new VisualGridRunner(10);
            Eyes             eyes   = new Eyes(runner);
            ChromeDriver     driver = new ChromeDriver();

            Configuration sconf = eyes.GetConfiguration();

            sconf.SetAppName(testName);

            sconf.SetTestName(testName);

            eyes.ApiKey = Environment.GetEnvironmentVariable("APPLITOOLS_API_KEY");

            var batchName = Environment.GetEnvironmentVariable("APPLITOOLS_BATCH_NAME");
            var batchId   = Environment.GetEnvironmentVariable("APPLITOOLS_BATCH_ID");

            BatchInfo batchInfo = new Applitools.BatchInfo(batchName);

            batchInfo.Id = batchId;

            sconf.SetBatch(batchInfo);

            sconf.AddBrowser(1200, 800, BrowserType.CHROME);
            sconf.AddBrowser(1200, 800, BrowserType.FIREFOX);
            sconf.AddBrowser(1200, 800, BrowserType.SAFARI);
            sconf.AddBrowser(1200, 800, BrowserType.IE_11);
            sconf.AddBrowser(1200, 800, BrowserType.EDGE);


            //sconf.AddDeviceEmulation(DeviceName.iPad, ScreenOrientation.Portrait);
            //sconf.AddDeviceEmulation(DeviceName.iPad_Pro, ScreenOrientation.Portrait);
            //sconf.AddDeviceEmulation(DeviceName.iPhone_6_7_8_Plus, ScreenOrientation.Portrait);
            //sconf.AddDeviceEmulation(DeviceName.iPhone_X, ScreenOrientation.Portrait);
            //sconf.AddDeviceEmulation(DeviceName.Galaxy_Note_3, ScreenOrientation.Portrait);
            //sconf.AddDeviceEmulation(DeviceName.Nexus_10, ScreenOrientation.Portrait);

            eyes.SetLogHandler(new FileLogHandler(@"C:\Users\user\Desktop\appli.log", false, true));

            sconf.SetViewportSize(1000, 600);

            eyes.SetConfiguration(sconf);

            Console.WriteLine("Open conection to Eyes");
            eyes.Open(driver);

            driver.Url = "https://github.com/login";

            Console.WriteLine("Visual Assertion #1");
            eyes.Check(Target.Window().Fully().WithName("Login page"));

            Console.WriteLine("Click Login");
            driver.FindElement(By.CssSelector("#login > form > div.auth-form-body.mt-3 > input.btn.btn-primary.btn-block"))
            .Click();

            if (shouldBreakSite)
            {
                Console.WriteLine("Breaking Site");
                BreakSite(driver);
            }

            Console.WriteLine("Begin Functional Assertions");

            // validate sign in button
            String buttonText = driver
                                .FindElement(
                By.CssSelector("#login > form > div.auth-form-body.mt-3 > input.btn.btn-primary.btn-block"))
                                .GetAttribute("value");

            Assert.IsTrue(buttonText.CompareTo("Sign in") == 0, "wrong button");

            // validate error message
            String errorMessage = driver.FindElement(By.CssSelector("#js-flash-container > div > div")).Text;

            Assert.IsTrue(errorMessage.Contains("Incorrect username or password."), "wrong label");

            String usernameTextbox = driver
                                     .FindElement(By.CssSelector("#login > form > div.auth-form-body.mt-3 > label:nth-child(1)")).Text;

            Assert.IsTrue(usernameTextbox.Contains("Username or email address"), "wrong label");

            String passwordTextbox = driver
                                     .FindElement(By.CssSelector("#login > form > div.auth-form-body.mt-3 > label:nth-child(3)")).Text;

            Assert.IsTrue(passwordTextbox.Contains("Password"), "wrong label");

            Console.WriteLine("Completed Functional Assertions");

            Console.WriteLine("Visual Assertion #2");
            eyes.Check(Target.Window().Fully().WithName("Error Message"));

            Console.WriteLine("Close connection to Eyes");
            eyes.CloseAsync();

            System.Diagnostics.Debug.WriteLine("Waiting for visual test to complete");
            TestResultsSummary results = runner.GetAllTestResults();

            System.Diagnostics.Debug.WriteLine(results);

            driver.Quit();
        }