public void WebDriverTestMethod()
        {
            Dictionary <String, Object> pars = new Dictionary <String, Object>();

            try
            {
                reportiumClient.testStart("Wikipedia sample", new TestContextTags("sample1", "apples"));

                // write your code here
                reportiumClient.stepStart("Open Wikipedia");
                driver.Navigate().GoToUrl("www.wikipedia.org");
                pars.Clear();
                pars.Add("content", "The Free Encyclopedia");
                pars.Add("timeout", 20);
                String res = (String)driver.ExecuteScript("mobile:checkpoint:text", pars);

                if (!res.ToLower().Equals("true"))
                {
                    reportiumClient.reportiumAssert("homepage loaded", false);
                }
                reportiumClient.stepEnd();

                reportiumClient.stepStart("Looking for term");
                driver.FindElementByXPath("//*[@id='searchInput']").SendKeys("apple");
                System.Threading.Thread.Sleep(2000);

                driver.FindElementByXPath("//*[@class=\"pure-button pure-button-primary-progressive\"]").Click();
                reportiumClient.stepEnd();

                reportiumClient.stepStart("Visual Analysis to verify on right page");
                pars.Clear();
                pars.Add("content", "fruit");
                pars.Add("timeout", 20);
                res = (String)driver.ExecuteScript("mobile:checkpoint:text", pars);
                if (!res.ToLower().Equals("true"))
                {
                    reportiumClient.reportiumAssert("search term loaded", false);
                }
                reportiumClient.stepEnd();

                reportiumClient.testStop(TestResultFactory.createSuccess());
            }
            catch (Exception e)
            {
                reportiumClient.testStop(TestResultFactory.createFailure(e.Message, e));
                Trace.Write(e.StackTrace);
                Trace.WriteLine(" ");
            }
        }
Esempio n. 2
0
        public void WebDriverTestMethod()
        {
            //Write your test here
            reportClient.testStart("User Agent test", new TestContextTags("assignment2", "training"));

            Dictionary <String, Object> pars = new Dictionary <String, Object>();

            try
            {
                reportClient.stepStart("Open the website");
                driver.Navigate().GoToUrl("https://training.perfecto.io");
                pars.Clear();
                pars.Add("content", "Training Website");
                pars.Add("timeout", 20);
                String res = (String)driver.ExecuteScript("mobile:checkpoint:text", pars);

                if (!res.ToLower().Equals("true"))
                {
                    reportClient.reportiumAssert("homepage loaded", false);
                }
                reportClient.stepEnd();

                reportClient.stepStart("navigate to agent page");
                driver.FindElementByXPath("//*[@class=\"mobile-menu\"]").Click();

                pars.Clear();
                pars.Add("label", "Agent");
                pars.Add("timeout", 20);
                driver.ExecuteScript("mobile:button-text:click", pars);

                String result = (String)driver.FindElementByXPath("//*[text()=\"The User Agent\"]").Text;
                Trace.WriteLine(result);

                reportClient.testStop(TestResultFactory.createSuccess());
            }
            catch (Exception e)
            {
                reportClient.testStop(TestResultFactory.createFailure(e.Message, e));
                Trace.Write(e.StackTrace);
                Trace.WriteLine(" ");
            }
        }
Esempio n. 3
0
        public void AppiumTestMethod()
        {
            Dictionary <String, Object> pars = new Dictionary <String, Object>();
            String res;

            try
            {
                reportiumClient.testStart("Image Injection Assignment", new TestContextTags("assignment4", "image"));

                // write your code here

                reportiumClient.stepStart("Start the app and upload the image");

                try
                {
                    // close the calendar if open to verify that starting from fresh app
                    pars.Add("name", "RealTimeFilter");
                    driver.ExecuteScript("mobile:application:close", pars);
                }
                catch (Exception e)
                {
                    Trace.Write(e.StackTrace);
                    Trace.WriteLine(" ");
                }
                try
                {
                    pars.Clear();
                    pars.Add("name", "RealTimeFilter");
                    driver.ExecuteScript("mobile:application:open", pars);
                }
                catch (Exception e)
                {
                    // unable to start the app, probably because it isn't installed
                    pars.Clear();
                    pars.Add("file", "PUBLIC:ImageInjection\\RealTimeFilter.ipa");
                    pars.Add("sensorInstrument", "sensor");
                    driver.ExecuteScript("mobile:application:install", pars);

                    pars.Clear();
                    pars.Add("name", "RealTimeFilter");
                    driver.ExecuteScript("mobile:application:open", pars);
                }

                driver.Context = "NATIVE_APP";
                reportiumClient.stepEnd();

                reportiumClient.stepStart("inject the image");

                pars.Clear();
                pars.Add("repositoryFile", "PRIVATE:perfectoL.png");
                pars.Add("identifier", "Victor.RealTimeFilter");
                driver.ExecuteScript("mobile:image.injection:start", pars);
                reportiumClient.stepEnd();

                reportiumClient.stepStart("dismiss popup if it appears");
                // rotate the image (device) to show in landscape
                pars.Clear();
                pars.Add("content", "Access the Camera");
                pars.Add("timeout", 20);
                res = (String)driver.ExecuteScript("mobile:checkpoint:text", pars);

                if (res.ToLower().Equals("true"))
                {
                    pars.Clear();
                    pars.Add("label", "OK");
                    pars.Add("timeout", 10);

                    res = (String)driver.ExecuteScript("mobile:button-text:click", pars);
                }
                reportiumClient.stepEnd();

                reportiumClient.stepStart("verify the image is displayed");
                // rotate the image (device) to show in landscape
                pars.Clear();
                pars.Add("state", "landscape");
                driver.ExecuteScript("mobile:device:rotate", pars);

                pars.Clear();
                pars.Add("content", "Perfection");
                pars.Add("timeout", 20);

                res = (String)driver.ExecuteScript("mobile:checkpoint:text", pars);

                if (res.ToLower().Equals("true"))
                {
                    reportiumClient.testStop(TestResultFactory.createSuccess());
                }
                else
                {
                    pars.Clear();
                    pars.Add("tail", 50);
                    String logStr = (String)driver.ExecuteScript("mobile:device:log", pars);
                    reportiumClient.reportiumAssert("Failed to view image", false);
                    reportiumClient.testStop(TestResultFactory.createFailure("Failed to view image", null));
                }
            }
            catch (Exception e)
            {
                reportiumClient.testStop(TestResultFactory.createFailure(e.Message, e));
            }
        }
Esempio n. 4
0
        public void AppiumTestMethod()
        {
            //Write your test here
            // Notify Reporting Server that test is starting
            reportClient.testStart("Wikipedia assignment", new TestContextTags("assignment1", "apple entry"));

            Dictionary <String, Object> pars = new Dictionary <String, Object>();

            try
            {
                reportClient.stepStart("Open YouTube");
                try
                {
                    // close the calendar if open to verify that starting from fresh app
                    pars.Add("name", "YouTube");
                    driver.ExecuteScript("mobile:application:close", pars);
                }
                catch (Exception e)
                {
                    Trace.Write(e.StackTrace);
                    Trace.WriteLine(" ");
                }
                pars.Clear();
                pars.Add("name", "YouTube");
                driver.ExecuteScript("mobile:application:open", pars);
                driver.Context = "NATIVE_APP";

                reportClient.stepEnd();

                reportClient.stepStart("Adjust Volume");
                MaxVolume(driver);
                reportClient.stepEnd();

                reportClient.stepStart("Activate the audio search");
                driver.FindElementByXPath("//*[@content-desc=\"Search\"]").Click();
                driver.FindElementByXPath("//*[@resource-id=\"com.google.android.youtube:id/voice_search\"]").Click();
                reportClient.stepEnd();

                reportClient.stepStart("Play name for audio search");
                // Create audio file from String
                String key = "PRIVATE:mysong.wav";
                pars.Clear();
                pars.Add("text", "Metallica Master of Puppets");
                pars.Add("repositoryFile", key);
                driver.ExecuteScript("mobile:text:audio", pars);
                // inject Audio to device
                pars.Clear();
                pars.Add("key", key);
                pars.Add("wait", "wait");
                driver.ExecuteScript("mobile:audio:inject", pars);
                reportClient.stepEnd();

                reportClient.stepStart("Play the music clip and validate");
                driver.FindElementByXPath("//*[@content-desc=\"Play album\"]").Click();

                pars.Clear();
                pars.Add("timeout", 30);
                pars.Add("duration", 1);
                String audioR = (String)driver.ExecuteScript("mobile:checkpoint:audio", pars);
                reportClient.stepEnd();

                reportClient.stepStart("Close the app");
                // inject Audio to device
                pars.Clear();
                pars.Add("name", "YouTube");
                driver.ExecuteScript("mobile:application:close", pars);
                reportClient.stepEnd();

                if (audioR.ToLower().Equals("true"))
                {
                    reportClient.reportiumAssert("Audio is playing", true);
                    reportClient.testStop(TestResultFactory.createSuccess());
                }
                else
                {
                    reportClient.reportiumAssert("Audio failed", false);
                    reportClient.testStop(TestResultFactory.createFailure("Audio failed", null));
                }
            }
            catch (Exception e)
            {
                reportClient.testStop(TestResultFactory.createFailure(e.Message, e));
                Trace.Write(e.StackTrace);
                Trace.WriteLine(" ");
            }
        }
        public void AppiumTestMethod()
        {
            try
            {
                reportiumClient.testStart("Calendar assignment", new TestContextTags("assignment3", "calendarApp"));

                // write your code here

                reportiumClient.stepStart("Open the Calendar app");
                Dictionary <String, Object> pars = new Dictionary <String, Object>();
                try
                {
                    // close the calendar if open to verify that starting from fresh app
                    pars.Add("name", "Calendar");
                    driver.ExecuteScript("mobile:application:close", pars);
                }
                catch (Exception e)
                {
                    Trace.Write(e.StackTrace);
                    Trace.WriteLine(" ");
                }
                pars.Clear();
                pars.Add("name", "Calendar");
                driver.ExecuteScript("mobile:application:open", pars);
                reportiumClient.stepEnd();

                // Check for What's New Screen and dismiss
                reportiumClient.stepStart("Dismiss popup");
                pars.Clear();
                pars.Add("content", "What's New");
                pars.Add("timeout", 10);
                String result = (String)driver.ExecuteScript("mobile:checkpoint:text", pars);
                if (result.ToLower().Equals("true"))
                {
                    pars.Clear();
                    pars.Add("label", "Continue");
                    pars.Add("threshold", 80);
                    pars.Add("ignorecase", "nocase");
                    driver.ExecuteScript("mobile:button-text:click", pars);
                }
                pars.Clear();
                pars.Add("content", "Access");
                pars.Add("timeout", 10);
                result = (String)driver.ExecuteScript("mobile:checkpoint:text", pars);
                if (result.ToLower().Equals("true"))
                {
                    pars.Clear();
                    pars.Add("label", "Don't Allow");
                    pars.Add("threshold", 80);
                    pars.Add("ignorecase", "nocase");
                    driver.ExecuteScript("mobile:button-text:click", pars);
                }
                reportiumClient.stepEnd();

                // Go to add the event screen
                reportiumClient.stepStart("Open the event add screen");
                driver.Context = "NATIVE_APP";
                driver.FindElementByName("Add").Click();

                // use a checkpoint to visually check that we are on the correct screen
                pars.Clear();
                pars.Add("content", "new event");
                pars.Add("timeout", 20);
                result = (String)driver.ExecuteScript("mobile:checkpoint:text", pars);

                reportiumClient.stepEnd();

                reportiumClient.stepStart("Add location & title");
                IWebElement inField = driver.FindElementsByClassName("XCUIElementTypeTextField").ElementAt(1);
                inField.SendKeys("fun day");
                System.Threading.Thread.Sleep(2000);
                inField = driver.FindElementByName("Location");
                inField.SendKeys("London");
                driver.FindElementByName("Done").Click();

                reportiumClient.stepEnd();

                reportiumClient.stepStart("Set start time");
                driver.FindElementByName("Starts").Click();
                System.Threading.Thread.Sleep(1000);
                IWebElement hour = driver.FindElementsByClassName("XCUIElementTypePickerWheel").ElementAt(1);
                String      hr   = hour.GetAttribute("value");
                hour.SendKeys("9");
                IWebElement mins = driver.FindElementsByClassName("XCUIElementTypePickerWheel").ElementAt(2);
                String      min  = mins.GetAttribute("value");
                mins.SendKeys("45");
                Trace.WriteLine("old time: " + hr + ':' + min);
                hr  = hour.GetAttribute("value");
                min = mins.GetAttribute("value");
                Trace.WriteLine("new time: " + hr + ':' + min);
                reportiumClient.stepEnd();

                reportiumClient.stepStart("Set End Time");
                driver.FindElementByName("Ends").Click();
                System.Threading.Thread.Sleep(2000);
                hour = driver.FindElementsByClassName("XCUIElementTypePickerWheel").ElementAt(1);
                hr   = hour.GetAttribute("value");
                hour.SendKeys("11");
                mins = driver.FindElementsByClassName("XCUIElementTypePickerWheel").ElementAt(2);
                min  = mins.GetAttribute("value");
                mins.SendKeys("15");
                Trace.WriteLine("old end time: " + hr + ':' + min);
                hr  = hour.GetAttribute("value");
                min = mins.GetAttribute("value");
                Trace.WriteLine("new end time: " + hr + ':' + min);
                driver.FindElementByName("Ends").Click();
                reportiumClient.stepEnd();

                reportiumClient.stepStart("Recurring Event");
                driver.FindElementByName("Repeat").Click();
                driver.FindElementByName("Every Month").Click();
                driver.FindElementByName("End Repeat").Click();
                driver.FindElementByName("On Date").Click();
                System.Threading.Thread.Sleep(3000);
                IWebElement month    = driver.FindElementsByClassName("XCUIElementTypePickerWheel").ElementAt(0);
                String      endMonth = month.GetAttribute("value");
                month.SendKeys("December");
                IWebElement day     = driver.FindElementsByClassName("XCUIElementTypePickerWheel").ElementAt(1);
                String      endDate = day.GetAttribute("value");
                day.SendKeys("5");
                IWebElement year    = driver.FindElementsByClassName("XCUIElementTypePickerWheel").ElementAt(2);
                String      endYear = year.GetAttribute("value");
                year.SendKeys("2020");
                Trace.WriteLine("old end date: " + endMonth + ' ' + endDate + ", " + endYear);
                endMonth = month.GetAttribute("value");
                endDate  = day.GetAttribute("value");
                endYear  = year.GetAttribute("value");
                Trace.WriteLine("new end date: " + endMonth + ' ' + endDate + ", " + endYear);

                // go back to Event definition screen
                driver.FindElementByName("New Event").Click();
                reportiumClient.stepEnd();

                reportiumClient.stepStart("Add Travel time");
                driver.FindElementByName("Travel Time").Click();
                IWebElement travelToggle = driver.FindElementsByClassName("XCUIElementTypeSwitch").ElementAt(0);
                travelToggle.Click();
                driver.FindElementByName("2 hours").Click();
                // go back to Event definition screen
                driver.FindElementByName("New Event").Click();

                reportiumClient.stepEnd();

                reportiumClient.stepStart("Close application");
                pars.Clear();
                pars.Add("name", "Calendar");
                driver.ExecuteScript("mobile:application:close", pars);

                reportiumClient.stepEnd();
                reportiumClient.testStop(TestResultFactory.createSuccess());
            }
            catch (Exception e)
            {
                reportiumClient.testStop(TestResultFactory.createFailure(e.Message, e));
                Trace.Write(e.StackTrace);
                Trace.WriteLine(" ");
            }
        }
        public void WebDriverTestMethod()
        {
            try
            {
                reportiumClient.testStart("Location assignment", new TestContextTags("assignment2", "location"));
                Dictionary <String, Object> pars = new Dictionary <String, Object>();
                String res;
                IJavaScriptExecutor jse = (IJavaScriptExecutor)driver;

                // write your code here

                reportiumClient.stepStart("navigate to web page");
                driver.Navigate().GoToUrl("https://training.perfecto.io");

                // Verification of website is dependent on the environment
                // Branching needed as desktop does not support image analysis
                if (os.ToLower().Equals("windows"))
                {
                    pars.Clear();
                    pars.Add("content", "taking the first step");
                    pars.Add("timeout", 20);
                    res = (String)driver.ExecuteScript("mobile:checkpoint:text", pars);
                }
                else
                {
                    pars.Clear();
                    pars.Add("content", "PRIVATE:trainingHomepage.png");                     //remember, this image needs to be created!
                    pars.Add("timeout", 30);
                    Object result1 = driver.ExecuteScript("mobile:checkpoint:image", pars);

                    // clicking on hamburger icon, required only for mobile
                    driver.FindElementByXPath("//*[@class=\"mobile-menu\"]").Click();
                }
                reportiumClient.stepEnd();

                reportiumClient.stepStart("location page");
                pars.Clear();
                pars.Add("label", "location");
                pars.Add("timeout", 20);
                res = (String)driver.ExecuteScript("mobile:button-text:click", pars);

                // The location page SOMETIMES asks for approval to share location, in a popup. We need to click allow to approve
                try
                {
                    pars.Clear();
                    pars.Add("label", "Allow location");
                    pars.Add("timeout", 20);
                    res = (String)driver.ExecuteScript("mobile:button-text:click", pars);
                }
                catch (Exception e)
                {
                    // if not found then just print a note and continue
                    Trace.WriteLine("Popup to allow location not displayed");
                }

                reportiumClient.stepStart("Visual Analysis to verify on right page");
                pars.Clear();
                pars.Add("content", "peek");
                pars.Add("timeout", 20);
                res = (String)driver.ExecuteScript("mobile:checkpoint:text", pars);

                if (os.ToLower().Equals("android"))
                {
                    pars.Clear();
                    pars.Add("content", "you are within");
                    pars.Add("scrolling", "scroll");
                    res = (String)driver.ExecuteScript("mobile:checkpoint:text", pars);
                }
                else
                {
                    for (int i = 0; i < 5; i++)
                    {
                        pars.Clear();
                        pars.Add("content", "You are within");
                        pars.Add("timeout", 10);
                        res = (String)driver.ExecuteScript("mobile:checkpoint:text", pars);

                        if (res.ToLower().Equals("false"))
                        {
                            // scroll down
                            jse.ExecuteScript("window.scrollBy(0, 200)");
                        }
                        else
                        {
                            break;
                        }
                    }
                }
                reportiumClient.stepEnd();

                if (res.ToLower().Equals("true"))
                {
                    reportiumClient.testStop(TestResultFactory.createSuccess());
                }
                else
                {
                    reportiumClient.testStop(TestResultFactory.createFailure("test failed", null));
                }
            }
            catch (Exception e)
            {
                reportiumClient.testStop(TestResultFactory.createFailure(e.Message, e));
                Trace.Write(e.StackTrace);
                Trace.WriteLine(" ");
            }
        }