Represents an image of the page currently loaded in the browser.
Ejemplo n.º 1
0
        public RemoteWebDriver GetLoginedDriver(Account acc)
        {
            //   RemoteWebDriver phantomJs = new PhantomJSDriver();
            RemoteWebDriver driver = ChromeInstance.Driver();

            driver.Url = "http://youlikehits.com/";
            List <DCookie> dCookie;

            using (var reader = new StreamReader(this._dirPath + "/" + acc.Login + ".xml"))
            {
                XmlSerializer deserializer = new XmlSerializer(typeof(List <DCookie>),
                                                               new XmlRootAttribute("list"));
                dCookie = (List <DCookie>)deserializer.Deserialize(reader);
            }

            foreach (var cookie in dCookie)
            {
                driver.Manage().Cookies.AddCookie(cookie.GetCookie());
            }



            driver.Url = "https://youlikehits.com/";
            OpenQA.Selenium.Screenshot screenshot = ((ITakesScreenshot)driver).GetScreenshot();
            screenshot.SaveAsFile("cookie.jpg", ScreenshotImageFormat.Jpeg);
            return(driver);
        }
 public void Mositestart(IWebDriver driver)
 {
     new GeneralLibrary();
     try
     {
         _datarow.Col();
         //  new Modrophenialive().modrophenialiveproducts(, driver);
         new Modropheniaproducts().Product(_datarow, driver);
         // new UserJourney().UserJourn(this.datarow,driver);
         // new UserData().Userdata(this.datarow,driver);
         // new Mopaysite().MoPay(driver, , this.datarow);
     }
     catch (Exception exception)
     {
         Console.Write(exception);
         var actual = exception.ToString();
         var screenshot = new Screenshot();
         _datarow.Newrow("Exception", "Not Expected", actual, "FAIL", driver);
         screenshot.Screenshotfailed(driver);
     }
     finally
     {
         _datarow.Excelsave("MoSiteReport", driver, "*****@*****.**");
         _datarow.Dataflush();
         driver.Quit();
     }
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Get a screen shot of the current window
        /// </summary>
        /// <param name="savePath"></param>
        public void TakeScreenshot(string savePath)
        {
            QA.Screenshot theScreenshot = null;
            switch (this.browser)
            {
            case Browsers.IE:
            {
                theScreenshot = ((QA.IE.InternetExplorerDriver)wd).GetScreenshot();
            }; break;

            case Browsers.Chrome:
            {
                theScreenshot = ((QA.Chrome.ChromeDriver)wd).GetScreenshot();
            }; break;

            case Browsers.Firefox:
            {
                theScreenshot = ((QA.Firefox.FirefoxDriver)wd).GetScreenshot();
            }; break;

            case Browsers.Safari:
            {
                theScreenshot = ((QA.Safari.SafariDriver)wd).GetScreenshot();
            }; break;

            default:
            {
                theScreenshot = ((QA.IE.InternetExplorerDriver)wd).GetScreenshot();
            }; break;
            }
            if (theScreenshot != null)
            {
                theScreenshot.SaveAsFile(savePath, QA.ScreenshotImageFormat.Jpeg);
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Get a screen shot of the current window
        /// </summary>
        /// <param name="savePath"></param>
        public QA.Screenshot GetScreenshot()
        {
            QA.Screenshot theScreenshot = null;
            switch (this.browser)
            {
            case Browsers.IE:
            {
                theScreenshot = ((QA.IE.InternetExplorerDriver)wd).GetScreenshot();
            }; break;

            case Browsers.Chrome:
            {
                theScreenshot = ((QA.Chrome.ChromeDriver)wd).GetScreenshot();
            }; break;

            case Browsers.Firefox:
            {
                theScreenshot = ((QA.Firefox.FirefoxDriver)wd).GetScreenshot();
            }; break;

            case Browsers.Safari:
            {
                theScreenshot = ((QA.Safari.SafariDriver)wd).GetScreenshot();
            }; break;

            default:
            {
                theScreenshot = ((QA.IE.InternetExplorerDriver)wd).GetScreenshot();
            }; break;
            }
            return(theScreenshot);
        }
 /// <summary>
 /// Get a screen shot of the current window
 /// </summary>
 /// <param name="savePath"></param>
 protected void TakeScreenshot(string savePath)
 {
     QA.Screenshot theScreenshot = ((QA.PhantomJS.PhantomJSDriver)_WebDriver).GetScreenshot();
     if (theScreenshot != null)
     {
         theScreenshot.SaveAsFile(savePath, System.Drawing.Imaging.ImageFormat.Png);
     }
 }
        public void Mosite(IWebDriver driver, Datarow datarow, string urls, string items)
        {
            var screenshot = new Screenshot();

            var strArray = items.Split(new[] {','});
            var urlarray = urls.Split(new[] {','});
            try
            {
                foreach (var url in urlarray)
                {
                    foreach (var str in strArray.Where(str => str != null))
                    {
                        if (str == "Test All Links in Mosite")
                        {
                            datarow.Newrow("", "", "Test All Links in Mosite", "", driver);
                            var tick = new Tickle();
                            tick.HomepageTabsTickle(datarow, driver, url);
                        }

                        if (str == "Test Footer Links")
                        {
                            datarow.Newrow("", "", "Test Footer Links", "", driver);
                        }
                        if (str == "Test Basket Functionality")
                        {
                            datarow.Newrow("", "", "Test Basket Functionality", "", driver);
                        }
                        if (str == "Test Produict Page - Test Add Product to Basket")
                        {
                            datarow.Newrow("", "", "Test Produict Page - Test Add Product to Basket", "", driver);
                        }
                        if (str == "Test Delete From Basket - Test Product Unavailable")
                        {
                            datarow.Newrow("", "", "Test Delete From Basket - Test Product Unavailable", "", driver);
                        }
                        if (str == "Test Registration/Login - CheckOut Pages")
                        {
                            datarow.Newrow("", "", "Test Registration/Login - CheckOut Pages", "", driver);
                        }
                        if (str == "Test Mopay")
                        {
                            datarow.Newrow("", "", "Test Mopay", "", driver);
                        }
                    }
                }
            }
            catch (Exception)
            {
                datarow.Newrow("Exception", "", "Exception Not Expected", "FAIL", driver);
                screenshot.Screenshotfailed(driver);
            }
            finally
            {
                datarow.Excelsave("MoshopConsole", driver, "*****@*****.**");
                screenshot.Screenshotfailed(driver);
                driver.Quit();
            }
        }
Ejemplo n.º 7
0
        private static Image ScreenshotToImage(QA.Screenshot screenshot)
        {
            Image screenshotImage;

            using (var memStream = new MemoryStream(screenshot.AsByteArray))
            {
                screenshotImage = Image.FromStream(memStream);
            }
            return(screenshotImage);
        }
Ejemplo n.º 8
0
        public void GetElementScreenshot()
        {
            WindowsDriver <WindowsElement> desktopSession = null;

            try
            {
                // Locate the AlarmPivotItem element in Alarms & Clock app to be captured
                WindowsElement             alarmPivotItem1           = session.FindElementByAccessibilityId(AlarmTabAutomationId);
                OpenQA.Selenium.Screenshot alarmPivotItemScreenshot1 = alarmPivotItem1.GetScreenshot();

                // Save the AlarmPivotItem screenshot capture locally on the machine running the test
                alarmPivotItemScreenshot1.SaveAsFile(@"ScreenshotAlarmPivotItem.png", ScreenshotImageFormat.Png);

                // Using the Desktop session, locate the same AlarmPivotItem element in Alarms & Clock app to be captured
                desktopSession = Utility.CreateNewSession(CommonTestSettings.DesktopAppId);
                WindowsElement             alarmPivotItem2           = desktopSession.FindElementByAccessibilityId(AlarmTabAutomationId);
                OpenQA.Selenium.Screenshot alarmPivotItemScreenshot2 = alarmPivotItem2.GetScreenshot();

                // Using the Desktop session, locate the Alarms & Clock app top level window to be captured
                WindowsElement             alarmsClockWindowTopWindow           = desktopSession.FindElementByName("Alarms & Clock");
                OpenQA.Selenium.Screenshot alarmsClockWindowTopWindowScreenshot = alarmsClockWindowTopWindow.GetScreenshot();

                using (MemoryStream msScreenshot1 = new MemoryStream(alarmPivotItemScreenshot1.AsByteArray))
                    using (MemoryStream msScreenshot2 = new MemoryStream(alarmPivotItemScreenshot2.AsByteArray))
                        using (MemoryStream msScreenshot3 = new MemoryStream(alarmsClockWindowTopWindowScreenshot.AsByteArray))
                        {
                            // Verify that the element screenshot has a valid size
                            Image screenshotImage1 = Image.FromStream(msScreenshot1);
                            Assert.AreEqual(alarmPivotItem1.Size.Height, screenshotImage1.Height);
                            Assert.AreEqual(alarmPivotItem1.Size.Width, screenshotImage1.Width);

                            // Verify that the element screenshot captured using the Alarms & Clock session
                            // is identical in size with the one taken using the desktop session
                            Image screenshotImage2 = Image.FromStream(msScreenshot2);
                            Assert.AreEqual(screenshotImage1.Height, screenshotImage2.Height);
                            Assert.AreEqual(screenshotImage1.Width, screenshotImage2.Width);

                            // Verify that the element screenshot is smaller in size compared to the application top level window
                            Image screenshotImage3 = Image.FromStream(msScreenshot3);
                            Assert.AreEqual(alarmsClockWindowTopWindow.Size.Height, screenshotImage3.Height);
                            Assert.AreEqual(alarmsClockWindowTopWindow.Size.Width, screenshotImage3.Width);
                            Assert.IsTrue(screenshotImage3.Height > screenshotImage1.Height);
                            Assert.IsTrue(screenshotImage3.Width > screenshotImage1.Width);
                        }
            }
            finally
            {
                if (desktopSession != null)
                {
                    desktopSession.Quit();
                }
            }
        }
        public void Finally(IWebDriver driver, string url, Datarow datarow, string emails)
        {
            new GeneralLibrary();
            try
            {
                //Footer_TPS footer = new Footer_TPS();
                //footer.Footer(driver, , url, datarow);

                //Baskets_TPS basket = new Baskets_TPS();
                //basket.Basket(driver, datarow);

                //links_TPS hom = new links_TPS();
                //hom.Links(datarow,driver, url);

                //UserJourney_TPS userjour = new UserJourney_TPS();
                //userjour.UserJourn(datarow,driver, url);

                //Mopay_TPS Mopay = new Mopay_TPS();
                //Mopay.Mopay(driver, datarow);
            }
            catch (Exception e)
            {
                Console.Write(e);
                var ex = e.ToString();
                var scree = new Screenshot();
                datarow.Newrow("Exception", "Not Expected", ex, "FAIL", driver);
                scree.Screenshotfailed(driver);
            }
            finally
            {
                var split = url.Split(new[] {' ', ',', '.', '/', '\t'});

                foreach (var sr in split)
                {
                    if (split[2] == "m" || split[2] == "www")
                    {
                        if (sr != split[3]) continue;
                        datarow.consolidatedreport(emails);
                        datarow.Excelsave("Mosite-" + sr + "", driver, emails);

                        driver.Quit();
                        break;
                    }
                    if (sr != split[2]) continue;
                    datarow.consolidatedreport(emails);
                    datarow.Excelsave("Mosite-" + sr + "", driver, emails);

                    driver.Quit();
                    break;
                }
            }
        }
Ejemplo n.º 10
0
 public void TakeScreenShot(IWebDriver driver, string filename)
 {
     try
     {
         OpenQA.Selenium.Screenshot image = ((ITakesScreenshot)driver).GetScreenshot();
         image.SaveAsFile(filename, ScreenshotImageFormat.Jpeg);
     }
     catch (Exception e)
     {
         Console.WriteLine(e);
         Assert.Fail("Could not screencapture. Exception: " + e);
     }
 }
Ejemplo n.º 11
0
 /// <summary>
 /// Capture screen
 /// </summary>
 /// <returns></returns>
 public static string CaptureScreen()
 {
     try
     {
         ITakesScreenshot           ssdriver   = Browser.driver as ITakesScreenshot;
         OpenQA.Selenium.Screenshot screenshot = ssdriver.GetScreenshot();
         screenshot.SaveAsFile(screenShotPath);
         return(screenShotPath);
     }
     catch (Exception e)
     {
         return(e.Message);
     }
 }
Ejemplo n.º 12
0
        /// <summary>
        /// Get a screen shot of the current window
        /// </summary>
        /// <param name="savePath"></param>
        public void TakeScreenshot(string savePath)
        {
            QA.Screenshot theScreenshot = null;
            switch (this.browser)
            {
            case Browsers.IE:
            {
                theScreenshot = ((QA.IE.InternetExplorerDriver)wd).GetScreenshot();
            }; break;

            case Browsers.Chrome:
            {
                theScreenshot = ((QA.Chrome.ChromeDriver)wd).GetScreenshot();
            }; break;

            case Browsers.Firefox:
            {
                theScreenshot = ((QA.Firefox.FirefoxDriver)wd).GetScreenshot();
            }; break;

            case Browsers.Safari:
            {
                theScreenshot = ((QA.Safari.SafariDriver)wd).GetScreenshot();
            }; break;

            default:
            {
                theScreenshot = ((QA.IE.InternetExplorerDriver)wd).GetScreenshot();
            }; break;
            }
            if (theScreenshot != null)
            {
                for (int i = 0; i < 5; i++)
                {
                    try
                    {
                        theScreenshot.SaveAsFile(savePath, QA.ScreenshotImageFormat.Jpeg);
                        return;
                    }
                    catch (Exception ex)
                    {
                        Commons.Wait(new Random().Next(3, 7));
                    }
                }
            }
        }
        public void Registration(IWebDriver driver, Datarow datarow)
        {
            var screenshot = new Screenshot();

            var logintitle = driver.Url;
            try
            {
                if (logintitle.Contains("Login") || logintitle.Contains("StepSelectAccountType") ||
                    driver.PageSource.Contains("Login"))
                {
                    //IF the User is a Guest Activate guest Class

                    //Guest guest = new Guest();
                    //guest.guest(driver, datarow);

                    //Calling the Login Class
                    var login = new LoginandRegistrationTps();
                    login.Login_TPS(driver, datarow);
                }

                else if (logintitle.Contains("Checkout"))
                {
                    // calling the checkout class
                    var data = new UserDataTps();
                    data.userdata_TPS(driver, datarow);
                }
                else
                {
                    datarow.Newrow("Checkout Process Not covered in the Framework", "Expected", logintitle, "FAIL",
                                   driver);
                    screenshot.Screenshotfailed(driver);
                }
            }
            catch (Exception ex)
            {
                var e = ex.ToString();
                datarow.Newrow("Exception", "Not Expected", e, "FAIL", driver);
                screenshot.Screenshotfailed(driver);
            }
        }
Ejemplo n.º 14
0
        /// <summary>
        /// Get a screen shot of the current window
        /// </summary>
        /// <param name="savePath"></param>
        public Image TakeScreenshot()
        {
            QA.Screenshot theScreenshot = null;
            switch (this.browser)
            {
            case Browsers.IE:
            {
                theScreenshot = ((QA.IE.InternetExplorerDriver)wd).GetScreenshot();
            }; break;

            case Browsers.Chrome:
            {
                theScreenshot = ((QA.Chrome.ChromeDriver)wd).GetScreenshot();
            }; break;

            case Browsers.Firefox:
            {
                theScreenshot = ((QA.Firefox.FirefoxDriver)wd).GetScreenshot();
            }; break;

            case Browsers.Safari:
            {
                theScreenshot = ((QA.Safari.SafariDriver)wd).GetScreenshot();
            }; break;

            default:
            {
                theScreenshot = ((QA.IE.InternetExplorerDriver)wd).GetScreenshot();
            }; break;
            }
            if (theScreenshot != null)
            {
                MemoryStream ms    = new MemoryStream(theScreenshot.AsByteArray);
                Image        image = Image.FromStream(ms);
                return(image);
            }
            return(null);
        }
Ejemplo n.º 15
0
        /// <summary>
        /// capture screen with screen shot
        /// </summary>
        /// <returns></returns>
        public static string CaptureScreenWithCallStack()
        {
            try
            {
                if (BoolScreenShotOnException)
                {
                    screenShotPath = string.Empty;
                    screenShotPath = ConfigurationManager.AppSettings["ScreenShotPath"] + DateTime.Now.ToLongDateString();
                    string filename = DateTime.Now.ToString("HH:mm");

                    string CallStack = GetCallStack();
                    screenShotPath = screenShotPath + "\\\\" + "_" + CallStack + "_" + filename.Replace(":", "_") + ".png";
                    ITakesScreenshot ssdriver = Browser.driver as ITakesScreenshot;

                    OpenQA.Selenium.Screenshot screenshot = ssdriver.GetScreenshot();
                    screenshot.SaveAsFile(screenShotPath);
                    return(screenShotPath);
                }
                else
                {
                    return(string.Empty);
                }
            }
            catch (UnhandledAlertException ex)
            {
                AlertMessage Alert = new AlertMessage();
                Alert.CloseAlertBox();
                ITakesScreenshot           ssdriver   = Browser.driver as ITakesScreenshot;
                OpenQA.Selenium.Screenshot screenshot = ssdriver.GetScreenshot();
                screenshot.SaveAsFile(screenShotPath);
                return(screenShotPath);
            }
            catch (Exception e)
            {
                return(screenShotPath);
            }
        }
Ejemplo n.º 16
0
 public void SaveScreenshot(Screenshot screenshot, string path)
 {
     screenshot.SaveAsFile(path, System.Drawing.Imaging.ImageFormat.Png);
 }
Ejemplo n.º 17
0
        public void GetScreenshot()
        {
            WindowsDriver <WindowsElement> notepadSession = null;
            WindowsDriver <WindowsElement> desktopSession = null;

            try
            {
                // Launch and capture a screenshot of a maximized Notepad application. The steps below intentionally use
                // the Notepad application window to fully cover the Alarms & Clock application. This setup demonstrates
                // that capturing Alarms & Clock screenshot afterward will implicitly bring its window to foreground.
                notepadSession = Utility.CreateNewSession(CommonTestSettings.NotepadAppId);
                notepadSession.Manage().Window.Maximize();
                System.Threading.Thread.Sleep(TimeSpan.FromSeconds(1));
                OpenQA.Selenium.Screenshot notepadScreenshot = notepadSession.GetScreenshot();

                // Capture a screenshot of Alarms & Clock application
                // This implicitly brings the application window to foreground
                OpenQA.Selenium.Screenshot alarmsClockScreenshot = session.GetScreenshot();

                // Save the application screenshot capture locally on the machine running the test
                alarmsClockScreenshot.SaveAsFile(@"ScreenshotAlarmsClockApplication.png", ScreenshotImageFormat.Png);

                // Capture the entire desktop using the Desktop session
                desktopSession = Utility.CreateNewSession(CommonTestSettings.DesktopAppId);
                OpenQA.Selenium.Screenshot desktopScreenshot = desktopSession.GetScreenshot();

                // Save the desktop screenshot capture locally on the machine running the test
                desktopScreenshot.SaveAsFile(@"ScreenshotDesktop.png", ScreenshotImageFormat.Png);

                using (MemoryStream msScreenshot1 = new MemoryStream(alarmsClockScreenshot.AsByteArray))
                    using (MemoryStream msScreenshot2 = new MemoryStream(notepadScreenshot.AsByteArray))
                        using (MemoryStream msScreenshot3 = new MemoryStream(desktopScreenshot.AsByteArray))
                        {
                            // Verify that the Alarms & Clock application screenshot has a valid size
                            Image screenshotImage1 = Image.FromStream(msScreenshot1);
                            Assert.AreEqual(session.Manage().Window.Size.Height, screenshotImage1.Height);
                            Assert.AreEqual(session.Manage().Window.Size.Width, screenshotImage1.Width);

                            // Verify that the maximized Notepad application screenshot has a valid size
                            Image screenshotImage2 = Image.FromStream(msScreenshot2);
                            Assert.AreEqual(notepadSession.Manage().Window.Size.Height, screenshotImage2.Height);
                            Assert.AreEqual(notepadSession.Manage().Window.Size.Width, screenshotImage2.Width);

                            // Verify that the application screenshot is smaller in size compared to the entire desktop
                            Image screenshotImage3 = Image.FromStream(msScreenshot3);
                            Assert.IsTrue(screenshotImage2.Height >= screenshotImage1.Height);
                            Assert.IsTrue(screenshotImage2.Width >= screenshotImage1.Width);
                        }
            }
            finally
            {
                if (notepadSession != null)
                {
                    notepadSession.Quit();
                }

                if (desktopSession != null)
                {
                    desktopSession.Quit();
                }
            }
        }
        public void Login_TPS(IWebDriver driver, Datarow datarow)
        {
            var screenshot = new Screenshot();
            try
            {
                if (IsElementPresent(driver, By.XPath("//form[@id='ctl00']/section/div/input"), 30))
                {
                    driver.FindElement(By.XPath("//form[@id='ctl00']/section/div/input"))
                          .SendKeys("*****@*****.**");
                    datarow.Newrow("Login Name Element", "Login Name Field Is Expected", "Login Name Field Is Present",
                                   "PASS", driver);
                }
                else if (IsElementPresent(driver, By.Id("UserName"), 30))
                {
                    driver.FindElement(By.Id("UserName")).SendKeys("*****@*****.**");
                    datarow.Newrow("Login Name Element", "Login Name Field Is Expected", "Login Name Field Is Present",
                                   "PASS", driver);
                }
                else
                {
                    datarow.Newrow("Login Name Element", "Login Name Field Is Expected",
                                   "Blocker-Login Name Field Is Not Present", "FAIL", driver);
                    screenshot.Screenshotfailed(driver);
                }
                if (IsElementPresent(driver, By.XPath("//form[@id='ctl00']/section/div[2]/input"), 30))
                {
                    driver.FindElement(By.XPath("//form[@id='ctl00']/section/div[2]/input")).SendKeys("M0Test08");
                    datarow.Newrow("Login Name Element", "Login Password Field Is Expected",
                                   "Login Password Field Is Present", "PASS", driver);
                }
                else if (IsElementPresent(driver, By.Id("Password"), 30))
                {
                    driver.FindElement(By.Id("Password")).SendKeys("M0Test08");
                    datarow.Newrow("Login Name Element", "Login Password Field Is Expected",
                                   "Login Password Field Is Present", "PASS", driver);
                }
                else
                {
                    datarow.Newrow("Login Password Element", "Login Password Field Is Expected",
                                   "Blocker - Login Password Field Is Not Present", "FAIL", driver);
                    screenshot.Screenshotfailed(driver);
                }
                if (IsElementPresent(driver, By.XPath("//form[@id='ctl00']/section/div[3]/div/input"), 30))
                {
                    driver.FindElement(By.XPath("//form[@id='ctl00']/section/div[3]/div/input")).Click();
                }
                else if (IsElementPresent(driver, By.CssSelector("input.ui-btn-hidden"), 30))
                {
                    driver.FindElement(By.CssSelector("input.ui-btn-hidden")).Click();
                }
                else
                {
                    datarow.Newrow("Login Element", "Login Button Is Expected", "Blocker - Login Button Is Not Present",
                                   "FAIL", driver);
                    screenshot.Screenshotfailed(driver);
                }
                if (IsElementPresent(driver, By.Id("BasketInfo"), 30))
                {
                    var basvalue = driver.FindElement(By.Id("BasketInfo")).Text;

                    if (basvalue == "(1)")
                    {
                        datarow.Newrow("Basket Value", "(1)", basvalue, "PASS", driver);
                    }
                    else
                    {
                        datarow.Newrow("Basket Value", "(1)", basvalue, "FAIL", driver);
                        screenshot.Screenshotfailed(driver);
                    }
                }
                else
                {
                    datarow.Newrow("Basket Value", "(1)", "No Basket Information", "FAIL", driver);
                    screenshot.Screenshotfailed(driver);
                }

                if (IsElementPresent(driver,
                                     By.XPath("//html/body/div/div[2]/div[2]/form/section/p/a/span/span/span/span"), 30))
                {
                    datarow.Newrow("Change Details Element", "Change Details Button is Expected",
                                   "Change Details Button Is Present", "PASS", driver);
                    driver.FindElement(By.XPath("//html/body/div/div[2]/div[2]/form/section/p/a/span/span/span/span"))
                          .Click();

                    try
                    {
                        decimal count = driver.FindElements(By.XPath("//form[@id='ctl00']/section/div")).Count;
                        for (var i = 1; i <= count; i++)
                        {
                            if (!IsElementPresent(driver, By.XPath("//form[@id='ctl00']/section/div[" + i + "]/label"),
                                30)) continue;
                            var valuet =
                                driver.FindElement(By.XPath("//form[@id='ctl00']/section/div[" + i + "]/label"))
                                    .Text;
                            //if (valuet == "Telephone:")
                            //{
                            //    driver.FindElement(By.XPath("//form[@id='ctl00']/section/div[" + i + "]/input")).SendKeys("123456789");
                            //}

                            if (valuet.Contains("*") || valuet != "Country: *")
                            {
                                try
                                {
                                    driver.FindElement(By.XPath("//form[@id='ctl00']/section/div[" + i + "]/input"))
                                        .SendKeys("TEST");
                                    datarow.Newrow("Registration Field Name", "", valuet, "PASS", driver);
                                }
                                catch (Exception ex)
                                {
                                    Console.Write(ex);
                                }
                            }

                            if (valuet != "Country: *") continue;
                            var element = driver.FindElement(By.Id("Pagecontent_ddlCountry"));
                            IList<IWebElement> alllist = element.FindElements(By.TagName("option"));

                            string values = null;
                            foreach (var value in alllist)
                            {
                                values = values + "\r\n" + value;
                                new SelectElement(driver.FindElement(By.Id("Pagecontent_ddlCountry")))
                                    .SelectByText(value.Text);
                            }
                            datarow.Newrow("Registration Field Countries", "", values, "PASS", driver);
                        }
                    }
                    catch (Exception ex)
                    {
                        var e = ex.ToString();
                        datarow.Newrow("Exception", "exception Not Expected", e, "FAIL", driver);
                        screenshot.Screenshotfailed(driver);
                    }
                }
                var loc = driver.Url;
                if (loc.Contains("Error"))
                {
                    datarow.Newrow("Error Page", "Error Page After Logging Not Expected", loc, "FAIL", driver);
                    screenshot.Screenshotfailed(driver);
                }

                driver.Navigate().Back();

                //selecting delivery method
                try
                {
                    if (IsElementPresent(driver,
                                         By.XPath(
                                             "//html/body/div/div[2]/div[2]/form/section/div[2]/fieldset/div/label/span/span"),
                                         30))
                    {
                        decimal count =
                            driver.FindElements(By.XPath("/html/body/div/div[2]/div[2]/form/section/div[2]/fieldset/div"))
                                  .Count;
                        for (var i = 1; i < count; i++)
                        {
                            var text =
                                driver.FindElement(
                                    By.XPath("//html/body/div/div[2]/div[2]/form/section/div[2]/fieldset/div[" + i +
                                             "]/label/span/span")).Text;
                            driver.FindElement(
                                By.XPath("//html/body/div/div[2]/div[2]/form/section/div[2]/fieldset/div[" + i +
                                         "]/label/span/span")).Click();
                            datarow.Newrow("Delivery Method", "", text, "PASS", driver);
                        }
                    }
                    else
                    {
                        var loca = driver.Url;
                        datarow.Newrow("Delivery Method", "Unexpected Format", loca, "FAIL", driver);
                        screenshot.Screenshotfailed(driver);
                    }
                }
                catch (Exception ex)
                {
                    var e = ex.ToString();
                    datarow.Newrow("Delivery Method Exception", "Exception Not Expected", e, "FAIL", driver);
                    screenshot.Screenshotfailed(driver);
                }
                // Click continue to next page
                try
                {
                    if (IsElementPresent(driver, By.XPath("Pagecontent_ButtonCheckoutStep2"), 30))
                    {
                        var location = driver.Url;
                        datarow.Newrow("Checkout process url", "", location, "PASS", driver);
                        driver.FindElement(By.Id("Pagecontent_ButtonCheckoutStep2")).Click();
                    }
                    else
                    {
                        datarow.Newrow("Continue Button in Checkout Page", "Error Not Expected",
                                       "Pagecontent_ButtonCheckoutStep2-Element Not Present", "FAIL", driver);
                        screenshot.Screenshotfailed(driver);
                    }
                }
                catch (Exception ex)
                {
                    var e = ex.ToString();
                    datarow.Newrow("Continue Button Exception", "Exception Not Expected", e, "FAIL", driver);
                    screenshot.Screenshotfailed(driver);
                }
                //Pay Button
                try
                {
                    if (IsElementPresent(driver, By.Id("Pagecontent_ButtonConfirmCheckout"), 30))
                    {
                        driver.FindElement(By.Id("Pagecontent_ButtonConfirmCheckout")).Click();

                        var title = driver.Title;
                        datarow.Newrow("Mopay Title", "", title, "PASS", driver);
                    }
                    else
                    {
                        datarow.Newrow("Confirm Button in Checkout page", "Error Not Expected",
                                       "Pagecontent_ButtonConfirmCheckout - Element Not Present", "FAIL", driver);
                        screenshot.Screenshotfailed(driver);
                    }
                }
                catch (Exception ex)
                {
                    var e = ex.ToString();
                    datarow.Newrow("Pay Button Exception", "Exception Not Expected", e, "FAIL", driver);
                    screenshot.Screenshotfailed(driver);
                }
            }
            catch (Exception ex)
            {
                var exc = ex.ToString();
                datarow.Newrow("Exception", "Exception Not Expected", exc, "FAIL", driver);
                screenshot.Screenshotfailed(driver);
            }
        }
Ejemplo n.º 19
0
		public void TestTakeScreenshotWhenCalledWithoutErrorTakesScreenshot()
		{
			var driver = this.CreateMockWebDriverExpectingInitialization();
			driver.As<ITakesScreenshot>().Setup(s => s.GetScreenshot()).Throws<InvalidOperationException>();

			var basePath = Path.GetTempPath();
			var fileName = Guid.NewGuid().ToString();

			Screenshot screenshot;
			using (var ms = new MemoryStream())
			{
				var image = TestResource.TestImage;
				image.Save(ms, ImageFormat.Jpeg);

				screenshot = new Screenshot(Convert.ToBase64String(ms.ToArray()));
			}

			var screenShot = driver.As<ITakesScreenshot>();
			screenShot.Setup(s => s.GetScreenshot()).Returns(screenshot);

			this.TestBrowserWith(driver, browser =>
			{
				string fullPath = null;

				try
				{
					fullPath = browser.TakeScreenshot(basePath, fileName);
				}
				finally
				{
					if (fullPath != null && File.Exists(fullPath))
					{
						File.Delete(fullPath);
					}
				}

				Assert.IsNotNull(fullPath);
			});
		}
Ejemplo n.º 20
0
 internal void UpdateBrowserScreenshot(Screenshot screenshot)
 {
     
 }
Ejemplo n.º 21
0
 static void takeScreenshots()
 {
     screenshots = ((ITakesScreenshot)driver).GetScreenshot();
     string cas = DateTime.Now.ToString("dd_MM_yy_HH_mm_ss");
     screenshots.SaveAsFile("C:/Users/ivoss_000/Desktop/Selenium Test/Selenium Test/Screeny/test_" + cas + ".jpg", System.Drawing.Imaging.ImageFormat.Jpeg);
 }
        public void Footer(IWebDriver driver, Datarow datarow, string url)
        {
            // Generic Method to test footer links on all the sites.
            try
            {
                var pagesource = driver.PageSource;

                string footer;
                string footerlink;
                string sociallin;
                string sociallink;
                string mopowered;
                string lowerfooter;
                string lowerfooterlink;

                #region

                var title = driver.Title;
                var screenshot = new Screenshot();

                if (pagesource.Contains("user-scalable=yes"))
                {
                    footer = FooterV2.Footer;
                    footerlink = FooterV2.Footerlink;
                    sociallink = FooterV2.Sociallink;
                    sociallin = FooterV2.Sociallin;
                    mopowered = FooterV2.Mopowered;
                    lowerfooter = FooterV2.Lowerfooter;
                    lowerfooterlink = FooterV2.lowerfooterlink;
                }
                else
                {
                    footer = FooterV1.Footer;
                    footerlink = FooterV1.Footerlink;
                    sociallink = FooterV1.Sociallink;
                    sociallin = FooterV1.Sociallin;
                    mopowered = FooterV1.Mopowered;
                    lowerfooter = FooterV1.Lowerfooter;
                    lowerfooterlink = FooterV1.Lowerfooterlink;
                }
                try
                {
                    var count = GetXpathCount(driver, footer);
                    for (var i = 1; i <= count; i++)
                    {
                        driver.FindElement(By.XPath("" + footer + "[" + i + "]" + footerlink + "")).Click();

                        var Title = driver.Title;
                        datarow.Newrow("Footer Title", "", Title, "PASS", driver);
                        driver.Navigate().Back();
                    }
                }
                catch (Exception ex)
                {
                    var e = ex.ToString();
                    datarow.Newrow("Exception", "Exception Not Expected", e, "FAIL", driver);
                    screenshot.Screenshotfailed(driver);
                }

                try
                {
                    var count1 = GetXpathCount(driver, sociallin);
                    for (var i = 1; i <= count1; i++)
                    {
                        driver.FindElement(By.XPath("" + sociallin + "[" + i + "]" + sociallink + "")).Click();

                        var tile = driver.Title;
                        datarow.Newrow("Footer Social Image Title", "", tile, "PASS", driver);
                        if (title == "testshop")
                        {
                            driver.Navigate().GoToUrl(url);
                        }
                        else
                        {
                            driver.Navigate().Back();
                        }
                    }
                }
                catch (Exception ex)
                {
                    var e = ex.ToString();
                    datarow.Newrow("Exception", "Exception Not Expected", e, "FAIL", driver);
                    screenshot.Screenshotfailed(driver);
                }

                try
                {
                    var count3 = GetXpathCount(driver, lowerfooter);
                    for (var i = 1; i <= count3; i++)
                    {
                        driver.FindElement(By.XPath("" + lowerfooter + "[" + i + "]" + lowerfooterlink + "")).Click();

                        var tile = driver.Title;
                        datarow.Newrow("Lower Footer Title", "", tile, "PASS", driver);
                        if (title == "testshop")
                        {
                        }
                        else
                        {
                            driver.Navigate().Back();
                        }
                    }
                }
                catch (Exception ex)
                {
                    var e = ex.ToString();
                    datarow.Newrow("Exception", "Exception Not Expected", e, "FAIL", driver);
                    screenshot.Screenshotfailed(driver);
                }
                try
                {
                    if (IsElementPresent(driver, By.Name(mopowered)))
                    {
                        driver.FindElement(By.XPath(mopowered)).Click();

                        var tile = driver.Title;
                        datarow.Newrow("Footer Title", "", tile, "PASS", driver);
                        if (title == "testshop")
                        {
                            driver.Navigate().GoToUrl(url);
                        }
                        else
                        {
                            driver.Navigate().Back();
                        }
                    }
                    else
                    {
                        datarow.Newrow("Footer Element", "", "Footer Element Not Present" + mopowered, "FAIL", driver
                            );
                        screenshot.Screenshotfailed(driver);
                    }
                }
                catch (Exception ex)
                {
                    var e = ex.ToString();
                    datarow.Newrow("Exception", "Exception Not Expected", e, "FAIL", driver);
                    screenshot.Screenshotfailed(driver);
                }
            }
            catch (Exception)
            {
                datarow.Newrow("Exception", "", "Exception Not Expected", "FAIL", driver);
                _screenshot.Screenshotfailed(driver);
            }

            #endregion
        }
Ejemplo n.º 23
0
            public Screenshot TakeSreenShot()
            {
                try
                {
                    sShot = chrome.GetScreenshot();
                    return sShot;
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                    return null;
                }
                //lock (locker)
                //{
                //    return chrome.GetScreenshot();            
                //}

            }
        public void MoPay(IWebDriver driver, Datarow datarow)
        {
            _generalLibrary = new GeneralLibrary();
            var table =
                _generalLibrary.GetExcelData(@"C:\\Input Data\CardDetails.xls", "CardDetails").Tables[0];
            var screenshot = new Screenshot();
            try
            {
                var actual = driver.FindElement(By.XPath("//div[@id='total-amount']/dl/dd")).Text;
                datarow.Newrow("Currency Validation", "\x00a3", actual, actual.Contains("\x00a3") ? "PASS" : "FAIL",
                    driver);
            }
            catch (Exception exception)
            {
                var str2 = exception.ToString();
                datarow.Newrow("Exception", "Exception Not Expected", str2, "FAIL", driver);
            }
            var num = 0;
            var count = table.Rows.Count;
            for (var i = 0; i < count; i++)
            {
                try
                {
                    var input = table.Rows[i]["FirstName"].ToString();
                    var str4 = table.Rows[i]["LastName"].ToString();
                    var str5 = table.Rows[i]["Card Number"].ToString();
                    var str6 = table.Rows[i]["Security Code"].ToString();
                    var str8 = table.Rows[i]["Name on Card"].ToString();
                    var text = table.Rows[i]["ExpiryMonth"].ToString();
                    var str10 = table.Rows[i]["Expiry Year"].ToString();
                    var str11 = table.Rows[i]["E-mail"].ToString();
                    var str12 = table.Rows[i]["Phone Number"].ToString();
                    var str13 = table.Rows[i]["Address"].ToString();
                    var str14 = table.Rows[i]["City"].ToString();
                    var str15 = table.Rows[i]["Post Code"].ToString();
                    var str16 = table.Rows[i]["County"].ToString();
                    var str17 = table.Rows[i]["Country"].ToString();
                    new SelectElement(driver.FindElement(By.Id("Card_Type"))).SelectByText("Visa Debit");
                    driver.FindElement(By.Id("Card_Number")).Clear();
                    driver.FindElement(By.Id("Card_Number")).SendKeys(str5);
                    driver.FindElement(By.Id("Card_SecurityCode")).Clear();
                    driver.FindElement(By.Id("Card_SecurityCode")).SendKeys(str6);
                    driver.FindElement(By.Id("Card_Name")).Clear();
                    driver.FindElement(By.Id("Card_Name")).SendKeys(str8);
                    new SelectElement(driver.FindElement(By.Id("Card_ExpiryDate_Month"))).SelectByText(text);
                    new SelectElement(driver.FindElement(By.Id("Card_ExpiryDate_Year"))).SelectByText(str10);
                    if (num < 1)
                    {
                        driver.FindElement(By.Id("change-address")).Click();

                        num++;
                    }
                    driver.FindElement(By.Id("BillingContact_FirstName")).Clear();
                    driver.FindElement(By.Id("BillingContact_FirstName")).SendKeys(input);
                    driver.FindElement(By.Id("BillingContact_LastName")).Clear();
                    driver.FindElement(By.Id("BillingContact_LastName")).SendKeys(str4);
                    driver.FindElement(By.Id("BillingContact_Email")).Clear();
                    driver.FindElement(By.Id("BillingContact_Email")).SendKeys(str11);
                    driver.FindElement(By.Id("BillingContact_Phone_Number")).Clear();
                    driver.FindElement(By.Id("BillingContact_Phone_Number")).SendKeys(str12);
                    driver.FindElement(By.Id("BillingContact_Address_Line1")).Clear();
                    driver.FindElement(By.Id("BillingContact_Address_Line1")).SendKeys(str13);
                    driver.FindElement(By.Id("BillingContact_Address_Line2")).Clear();
                    driver.FindElement(By.Id("BillingContact_Address_Line2")).SendKeys("Address2");
                    driver.FindElement(By.Id("BillingContact_Address_Postcode")).Clear();
                    driver.FindElement(By.Id("BillingContact_Address_Postcode")).SendKeys(str15);
                    driver.FindElement(By.Id("BillingContact_Address_Town")).Clear();
                    driver.FindElement(By.Id("BillingContact_Address_Town")).SendKeys(str14);
                    driver.FindElement(By.Id("BillingContact_Address_County")).Clear();
                    driver.FindElement(By.Id("BillingContact_Address_County")).SendKeys(str16);
                    if (str17.Length == 0)
                    {
                        var elem = driver.FindElement(By.Id("BillingContact_Address_Country"));
                        IList<IWebElement> options = elem.FindElements(By.TagName("option"));
                        foreach (var str18 in options)
                        {
                            new SelectElement(driver.FindElement(By.Id("BillingContact_Address_Country"))).SelectByText(
                                str18.Text);
                            if (str18.Text == "")
                            {
                                break;
                            }
                        }
                    }
                    if (str17.Length > 0)
                    {
                        var elem = driver.FindElement(By.Id("BillingContact_Address_Country"));
                        IList<IWebElement> options = elem.FindElements(By.TagName("option"));

                        foreach (var str19 in options)
                        {
                            new SelectElement(driver.FindElement(By.Id("BillingContact_Address_Country"))).SelectByText(
                                str19.Text);
                            if (str19.Text == "United Kingdom")
                            {
                                break;
                            }
                        }
                    }
                    driver.FindElement(By.Name("PostAction[Complete]")).Click();

                    Thread.Sleep(0xbb8);
                    if (Regex.IsMatch(str5, "^[0-9'']"))
                    {
                        datarow.Newrow("Card Number", str5, str5, "PASS", driver);
                    }
                    else if (driver.PageSource.Contains("Number required") ||
                             driver.PageSource.Contains("Number invalid"))
                    {
                        datarow.Newrow("Card Number", str5, "Number Invalid", "PASS", driver);
                    }
                    else
                    {
                        datarow.Newrow("Card Number", str5, "No Error Message Displayed", "FAIL", driver);
                        screenshot.Screenshotfailed(driver);
                    }
                    datarow.Newrow("Card Type", "Visa Debit", "Visa Debit", "PASS", driver);
                    var regex = new Regex("^[0-9]{3}$");
                    if (regex.IsMatch(str6))
                    {
                        datarow.Newrow("Security Code", str6, "Valid 3 Digits", "PASS", driver);
                    }
                    else if (driver.PageSource.Contains("Security code required") ||
                             driver.PageSource.Contains("Security code invalid"))
                    {
                        datarow.Newrow("Security Code", str6, "Security code required", "PASS", driver);
                    }
                    else
                    {
                        datarow.Newrow("Security Code", str6, "No Error Message Displayed", "FAIL", driver);
                        screenshot.Screenshotfailed(driver);
                    }
                    if (Regex.IsMatch(str8, "^[a-zA-Z'']"))
                    {
                        datarow.Newrow("Name on Card", str8, str8, "PASS", driver);
                    }
                    else if (driver.PageSource.Contains("Name required"))
                    {
                        datarow.Newrow("Name on Card", str8, "Name Required", "PASS", driver);
                    }
                    else
                    {
                        datarow.Newrow("Name on Card", str8, "No Error Message Displayed", "PASS", driver);
                        screenshot.Screenshotfailed(driver);
                    }
                    if (Regex.IsMatch(input, "^[a-zA-Z'']"))
                    {
                        datarow.Newrow("First Name", input, input, "PASS", driver);
                    }
                    else if (driver.PageSource.Contains("The First Name field is required."))
                    {
                        datarow.Newrow("First Name", input, "The First Name field is required.", "PASS", driver
                            );
                    }
                    else
                    {
                        datarow.Newrow("First Name", input, "No Error Message Displayed", "FAIL", driver);
                        screenshot.Screenshotfailed(driver);
                    }
                    if (Regex.IsMatch(str4, "^[a-zA-Z'']"))
                    {
                        datarow.Newrow("Last Name", str4, str4, "PASS", driver);
                    }
                    else if (driver.PageSource.Contains("The Last Name field is required."))
                    {
                        datarow.Newrow("Last Name", str4, "The Last Name field is required.", "PASS", driver);
                    }
                    else
                    {
                        datarow.Newrow("Last Name", str4, "No Error message Displayed", "FAIL", driver);
                        screenshot.Screenshotfailed(driver);
                    }
                    if (Regex.IsMatch(str13, "^[a-zA-Z0-9'']"))
                    {
                        datarow.Newrow("Address", str13, str13, "PASS", driver);
                    }
                    else if (driver.PageSource.Contains("The Address field is required"))
                    {
                        datarow.Newrow("Address", str13, "The Address field is required", "PASS", driver);
                    }
                    else
                    {
                        datarow.Newrow("Address", str13, "No Error message Displayed", "FAIL", driver);
                        screenshot.Screenshotfailed(driver);
                    }
                    if (Regex.IsMatch(str15, "^[a-zA-Z0-9'']"))
                    {
                        datarow.Newrow("Post Code", str15, str15, "PASS", driver);
                    }
                    else if (driver.PageSource.Contains("The Postcode field is required"))
                    {
                        datarow.Newrow("Post Code", str15, "The Postcode field is required.", "PASS", driver);
                    }
                    else
                    {
                        datarow.Newrow("Post Code", str15, "No Error Message Displayed", "FAIL", driver);
                        screenshot.Screenshotfailed(driver);
                    }
                    if (Regex.IsMatch(str17, "^[a-zA-Z'']"))
                    {
                        datarow.Newrow("Country", str17, str17, "PASS", driver);
                    }
                    else if (driver.PageSource.Contains("The Country field is required."))
                    {
                        datarow.Newrow("Country", str17, "The Country field is required.", "PASS", driver);
                    }
                    else
                    {
                        datarow.Newrow("Country", str17, "No Error Message", "FAIL", driver);
                        screenshot.Screenshotfailed(driver);
                    }
                    if (driver.Title == "Secure Payment Page")
                    {
                    }
                    var location = driver.Url;
                    var str22 = driver.Title;
                    if (location.Contains("State=Accepted") || str22.Contains("Payment Accepted"))
                    {
                        datarow.Newrow("Transaction", location, "State=Accepted", "PASS", driver);
                        break;
                    }
                    if (location.Contains("State=NotAccepted"))
                    {
                        datarow.Newrow("Transaction", location, "Transaction Declined", "FAIL", driver);
                        break;
                    }
                    if ((!driver.PageSource.Contains("Checkout Declined") &&
                         !driver.PageSource.Contains("Checkout Error")) && !driver.PageSource.Contains("Not Found"))
                        continue;
                    datarow.Newrow("Checkout", "Checkout Declined", "Checkout Declined", "PASS", driver);
                    break;
                }
                catch (Exception exception2)
                {
                    Console.Write(exception2);
                    var str23 = exception2.ToString();
                    var screenshot2 = new Screenshot();
                    datarow.Newrow("Exception", "Exceptio not Expected", str23, "FAIL", driver);
                    screenshot2.Screenshotfailed(driver);
                }
            }
        }
        public void MoPayTPS(IWebDriver driver, Datarow datarow)
        {
            _generalLibrary = new GeneralLibrary();
            var dss = _generalLibrary.GetExcelData(@"C:\Selenium\Input Data\CardDetails.xls", "CardDetails");

            var personaldata = dss.Tables[0];
            var screenshot1 = new Screenshot();
            try
            {
                var totalamount = driver.FindElement(By.XPath("//div[@id='total-amount']/dl/dd")).Text;
                datarow.Newrow("Currency Validation", "₹", totalamount, totalamount.Contains("₹") ? "PASS" : "FAIL",
                    driver);
            }
            catch (Exception ex)
            {
                var e = ex.ToString();
                datarow.Newrow("Exception", "Exception Not Expected", e, "FAIL", driver);
            }
            var j = 0;
            var n = personaldata.Rows.Count;

            for (var icount = 0; icount < n; icount++)
            {
                try
                {
                    #region Read Excel

                    var FirstName = personaldata.Rows[icount]["FirstName"].ToString();
                    var LastName = personaldata.Rows[icount]["LastName"].ToString();
                    var CardNumber = personaldata.Rows[icount]["Card Number"].ToString();
                    var SecurityCode = personaldata.Rows[icount]["Security Code"].ToString();
                    var CardType = personaldata.Rows[icount]["CardType"].ToString();
                    var NameonCard = personaldata.Rows[icount]["Name on Card"].ToString();
                    var Expirymonth = personaldata.Rows[icount]["ExpiryMonth"].ToString();
                    var Expiryyear = personaldata.Rows[icount]["Expiry Year"].ToString();
                    var Email = personaldata.Rows[icount]["E-mail"].ToString();
                    var PhoneNumber = personaldata.Rows[icount]["Phone Number"].ToString();
                    var Address = personaldata.Rows[icount]["Address"].ToString();
                    var City = personaldata.Rows[icount]["City"].ToString();
                    var PostCode = personaldata.Rows[icount]["Post Code"].ToString();
                    var County = personaldata.Rows[icount]["County"].ToString();
                    var Country = personaldata.Rows[icount]["Country"].ToString();

                    #endregion

                    Selectanoption(driver, By.Id("Card_Type"), CardType);
                    // new SelectElement(driver.FindElement(By.Id("Card_Type"))).SelectByText(CardType);
                    driver.FindElement(By.Id("Card_Number")).Clear();
                    driver.FindElement(By.Id("Card_Number")).SendKeys(CardNumber);
                    driver.FindElement(By.Id("Card_SecurityCode")).Clear();
                    driver.FindElement(By.Id("Card_SecurityCode")).SendKeys(SecurityCode);
                    driver.FindElement(By.Id("Card_Name")).Clear();
                    driver.FindElement(By.Id("Card_Name")).SendKeys(NameonCard);
                    Selectanoption(driver, By.Id("Card_ExpiryDate_Month"), Expirymonth);
                    // new SelectElement(driver.FindElement(By.Id("Card_ExpiryDate_Month"))).SelectByText(Expirymonth);
                    Selectanoption(driver, By.Id("Card_ExpiryDate_Year"), Expiryyear);
                    new SelectElement(driver.FindElement(By.Id("Card_ExpiryDate_Year"))).SelectByText(Expiryyear);

                    if (j < 1)
                    {
                        driver.FindElement(By.Id("change-address")).Click();

                        j++;
                    }
                    driver.FindElement(By.Id("BillingContact_FirstName")).Clear();
                    driver.FindElement(By.Id("BillingContact_FirstName")).SendKeys(FirstName);
                    driver.FindElement(By.Id("BillingContact_LastName")).Clear();
                    driver.FindElement(By.Id("BillingContact_LastName")).SendKeys(LastName);
                    driver.FindElement(By.Id("BillingContact_Email")).Clear();
                    driver.FindElement(By.Id("BillingContact_Email")).SendKeys(Email);
                    driver.FindElement(By.Id("BillingContact_Phone_Number")).Clear();
                    driver.FindElement(By.Id("BillingContact_Phone_Number")).SendKeys(PhoneNumber);
                    driver.FindElement(By.Id("BillingContact_Address_Line1")).Clear();
                    driver.FindElement(By.Id("BillingContact_Address_Line1")).SendKeys(Address);
                    driver.FindElement(By.Id("BillingContact_Address_Line2")).Clear();
                    driver.FindElement(By.Id("BillingContact_Address_Line2")).SendKeys("Address2");
                    driver.FindElement(By.Id("BillingContact_Address_Postcode")).Clear();
                    driver.FindElement(By.Id("BillingContact_Address_Postcode")).SendKeys(PostCode);
                    driver.FindElement(By.Id("BillingContact_Address_Town")).Clear();
                    driver.FindElement(By.Id("BillingContact_Address_Town")).SendKeys(City);
                    driver.FindElement(By.Id("BillingContact_Address_County")).Clear();
                    driver.FindElement(By.Id("BillingContact_Address_County")).SendKeys(County);
                    if (Country.Length == 0)
                    {
                        var con = driver.FindElement(By.Id("BillingContact_Address_Country"));
                        IList<IWebElement> contry = con.FindElements(By.TagName("option"));

                        foreach (var cou in contry)
                        {
                            new SelectElement(driver.FindElement(By.Id("BillingContact_Address_Country"))).SelectByText(
                                cou.Text);
                            if (cou.Text == "")
                            {
                                break;
                            }
                        }
                    }

                    if (Country.Length > 0)

                    {
                        //IWebElement con = driver.FindElement(By.Id("BillingContact_Address_Country"));
                        //IList<IWebElement> countries = con.FindElements(By.TagName("option"));

                        //foreach (IWebElement country in countries)
                        //{
                        new SelectElement(driver.FindElement(By.Id("BillingContact_Address_Country"))).SelectByText(
                            "United Kingdom");
                        //}
                    }
                    driver.FindElement(By.Name("PostAction[Complete]")).Click();

                    Thread.Sleep(3000);

                    #region Validation

                    if (Regex.IsMatch(CardNumber, "^[0-9'']"))
                    {
                        datarow.Newrow("Card Number", CardNumber, CardNumber, "PASS", driver);
                    }
                    else if (driver.PageSource.Contains("Number required") ||
                             driver.PageSource.Contains("Number invalid"))
                    {
                        datarow.Newrow("Card Number", CardNumber, "Number Invalid", "PASS", driver);
                    }
                    else
                    {
                        datarow.Newrow("Card Number", CardNumber, "No Error Message Displayed", "FAIL", driver);
                        screenshot1.Screenshotfailed(driver);
                    }

                    if (CardType.Length == 0)
                    {
                        if (driver.PageSource.Contains("Type required"))
                        {
                            datarow.Newrow("Card Type", CardType, "Type Required", "PASS", driver);
                        }
                        else
                        {
                            datarow.Newrow("Card Type", CardType, CardType, "FAIL", driver);

                            screenshot1.Screenshotfailed(driver);
                        }
                    }

                    else
                    {
                        datarow.Newrow("Card Type", "Visa Debit", "Visa Debit", "PASS", driver);
                    }

                    var reg = new Regex("^[0-9]{3}$");
                    if (reg.IsMatch(SecurityCode))
                    {
                        datarow.Newrow("Security Code", SecurityCode, "Valid 3 Digits", "PASS", driver);
                    }
                    else if (driver.PageSource.Contains("Security code required") ||
                             driver.PageSource.Contains("Security code invalid"))
                    {
                        datarow.Newrow("Security Code", SecurityCode, "Security code required", "PASS", driver
                            );
                    }
                    else
                    {
                        datarow.Newrow("Security Code", SecurityCode, "No Error Message Displayed", "FAIL", driver
                            );

                        screenshot1.Screenshotfailed(driver);
                    }

                    if (Regex.IsMatch(NameonCard, "^[a-zA-Z'']"))
                    {
                        datarow.Newrow("Name on Card", NameonCard, NameonCard, "PASS", driver);
                    }
                    else if (driver.PageSource.Contains("Name required"))
                    {
                        datarow.Newrow("Name on Card", NameonCard, "Name Required", "PASS", driver);
                    }
                    else
                    {
                        datarow.Newrow("Name on Card", NameonCard, "No Error Message Displayed", "PASS", driver
                            );

                        screenshot1.Screenshotfailed(driver);
                    }
                    if (Regex.IsMatch(FirstName, "^[a-zA-Z'']"))
                    {
                        datarow.Newrow("First Name", FirstName, FirstName, "PASS", driver);
                    }

                    else if (driver.PageSource.Contains("The First Name field is required."))
                    {
                        datarow.Newrow("First Name", FirstName, "The First Name field is required.", "PASS", driver
                            );
                    }
                    else
                    {
                        datarow.Newrow("First Name", FirstName, "No Error Message Displayed", "FAIL", driver);

                        screenshot1.Screenshotfailed(driver);
                    }

                    if (Regex.IsMatch(LastName, "^[a-zA-Z'']"))
                    {
                        datarow.Newrow("Last Name", LastName, LastName, "PASS", driver);
                    }
                    else if (driver.PageSource.Contains("The Last Name field is required."))
                    {
                        datarow.Newrow("Last Name", LastName, "The Last Name field is required.", "PASS", driver
                            );
                    }
                    else
                    {
                        datarow.Newrow("Last Name", LastName, "No Error message Displayed", "FAIL", driver);

                        screenshot1.Screenshotfailed(driver);
                    }

                    if (Regex.IsMatch(Address, "^[a-zA-Z0-9'']"))
                    {
                        datarow.Newrow("Address", Address, Address, "PASS", driver);
                    }
                    else if (driver.PageSource.Contains("The Address field is required"))
                    {
                        datarow.Newrow("Address", Address, "The Address field is required", "PASS", driver);
                    }
                    else
                    {
                        datarow.Newrow("Address", Address, "No Error message Displayed", "FAIL", driver);

                        screenshot1.Screenshotfailed(driver);
                    }

                    if (Regex.IsMatch(PostCode, "^[a-zA-Z0-9'']"))
                    {
                        datarow.Newrow("Post Code", PostCode, PostCode, "PASS", driver);
                    }
                    else if (driver.PageSource.Contains("The Postcode field is required"))
                    {
                        datarow.Newrow("Post Code", PostCode, "The Postcode field is required.", "PASS", driver
                            );
                    }
                    else
                    {
                        datarow.Newrow("Post Code", PostCode, "No Error Message Displayed", "FAIL", driver);

                        screenshot1.Screenshotfailed(driver);
                    }

                    if (Regex.IsMatch(Country, "^[a-zA-Z'']"))
                    {
                        datarow.Newrow("Country", Country, Country, "PASS", driver);
                    }
                    else if (driver.PageSource.Contains("The Country field is required."))
                    {
                        datarow.Newrow("Country", Country, "The Country field is required.", "PASS", driver);
                    }
                    else
                    {
                        datarow.Newrow("Country", Country, "No Error Message", "FAIL", driver);
                        screenshot1.Screenshotfailed(driver);
                    }

                    #endregion

                    var title = driver.Title;
                    if (title == "Secure Payment Page")
                    {
                    }

                    var url = driver.Url;
                    var title1 = driver.Title;
                    if (url.Contains("State=Accepted") || title1.Contains("Payment Accepted"))
                    {
                        datarow.Newrow("Transaction", url, "State=Accepted", "PASS", driver);
                        break;
                    }

                    if (url.Contains("State=NotAccepted"))
                    {
                        datarow.Newrow("Transaction", url, "Transaction Declined", "FAIL", driver);
                        break;
                    }

                    if (!driver.PageSource.Contains("Checkout Declined") && !driver.PageSource.Contains("Error") &&
                        !driver.PageSource.Contains("Not Found")) continue;
                    datarow.Newrow("Checkout", "Checkout Declined", "Checkout Declined", "PASS", driver);
                    break;
                }

                catch (Exception e)
                {
                    Console.Write(e);
                    var ex = e.ToString();
                    var scree = new Screenshot();
                    datarow.Newrow("Exception", "Exceptio not Expected", ex, "FAIL", driver);
                    scree.Screenshotfailed(driver);
                }
            }
        }
Ejemplo n.º 26
0
        /// <summary>
        ///     Uses the Selenium GetScreenshot method to take a screenshot.
        ///     If the dircetories do not exists in the project structure, then they are created.
        /// </summary>
        /// <param name="testContext">Contains test name</param>
        /// <param name="driver">The driver used during the test</param>
        public static void takeScreenShot(TestContext testContext, Object driver)
        {
            //Define the test name
            string testName = testContext.Test.Name;

            //get current date time with Date() to create unique file name
            string dateTime = string.Format("{0:dd_MMM_yyyy__hh_mm_ssfff}", DateTime.Now);

            //Get the current directory
            string cwd = Directory.GetCurrentDirectory();

            //Define the output directory name
            string dirScreenshots = "\\test-output\\screenshots\\";

            //Define the directory name to house the screenshots for this test
            string dirTestScreenshots = testName + "\\";

            //To identify the system on which the test was executed
            IPHostEntry host = Dns.GetHostEntry(Dns.GetHostName());
            IPAddress ipAddress = host.AddressList.FirstOrDefault(ip => ip.AddressFamily == AddressFamily.InterNetwork);
            string hostAddress = "__" + ipAddress.ToString() + "__";

            //Define the screenshot file name using the dateTime string
            string filename = hostAddress + dateTime + ".png";

            //Define the fully qualified directory path
            string path = cwd + dirScreenshots + dirTestScreenshots;

            //Define the fully qualified file path
            string filePath = path + filename;

            if (!Directory.Exists(path))
            {
                DirectoryInfo dirInfo = Directory.CreateDirectory(path);
            }

            if (driver is RemoteWebDriver)
            {
                ss = ((ITakesScreenshot)driver).GetScreenshot();
            }
            //else
            //{
            //    driver = (RemoteWebDriver)driver;
            //    ss = driver.GetScreenshot();
            //}

            ss.SaveAsFile(filePath, ImageFormat.Png); //use any of the built in image formating
        }
        public void MoPay(IWebDriver driver)
        {
            _generalLibrary = new GeneralLibrary();
            var excelData = _generalLibrary.GetExcelData(@"C:\\Input Data\CardDetails.xls", "CardDetails");
            var set2 = _generalLibrary.GetExcelData(@"C:\\Input Data\CardDetails.xls", "Account");
            _datarow.Col();
            var table = excelData.Tables[0];
            var table2 = set2.Tables[0];
            var count = table2.Rows.Count;
            try
            {
                for (var i = 0; i < count; i++)
                {
                    var locator = table2.Rows[i]["Account"].ToString();
                    var str2 = table2.Rows[i]["Type"].ToString();
                    var str3 = table2.Rows[i]["E-mail"].ToString();
                    var str4 = table2.Rows[i]["FormData"].ToString();
                    var str5 = table2.Rows[i]["FormValue"].ToString();
                    var str6 = table2.Rows[i]["CookieData"].ToString();
                    var str7 = table2.Rows[i]["CookieValue"].ToString();
                    driver.Navigate().GoToUrl("http://devpaytest.mobankdev.com/");
                    driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(15.0));
                    driver.FindElement(By.XPath("//div[@id='ReferenceControl']/div/input"));
                    driver.FindElement(By.XPath(locator)).Click();
                    driver.FindElement(By.Id(locator)).Click();
                    driver.FindElement(By.Id(str2)).Click();
                    driver.FindElement(By.XPath("//div[@id='ReferenceControl']/div/input"))
                        .GetAttribute("Reference");
                    driver.FindElement(By.XPath("//div[@id='TotalAmountControl']/div/input")).GetAttribute("Amt");
                    driver.FindElement(By.XPath("//div[@id='CurrencyCodeControl']/div/select")).GetAttribute("Cur");
                    var input = table.Rows[0]["FirstName"].ToString();
                    var str12 = table.Rows[0]["LastName"].ToString();
                    Assert.AreEqual("The MoShop Sale",
                                    driver.FindElement(By.XPath("//div[@id='DescriptionControl']/div/textarea")).Text);
                    var screenshot = new Screenshot();
                    driver.FindElement(By.XPath("//div[@id='FirstNameControl']/div/input")).Clear();
                    driver.FindElement(By.XPath("//div[@id='FirstNameControl']/div/input")).SendKeys(input);
                    driver.FindElement(By.XPath("//div[@id='LastNameControl']/div/input")).Clear();
                    driver.FindElement(By.XPath("//div[@id='LastNameControl']/div/input")).SendKeys(str12);
                    driver.FindElement(By.XPath("//div[@id='EmailControl']/div/input")).Clear();
                    driver.FindElement(By.XPath("//div[@id='EmailControl']/div/input")).SendKeys(str3);
                    driver.FindElement(By.CssSelector("button")).Click();
                    driver.FindElement(By.Name("FormData[1].Key")).SendKeys(str4);
                    driver.FindElement(By.Name("FormData[1].Value")).SendKeys(str5);
                    driver.FindElement(By.CssSelector("#CookieData > button")).Click();
                    driver.FindElement(By.Name("CookieData[1].Key")).SendKeys(str6);
                    driver.FindElement(By.Name("CookieData[1].Value")).SendKeys(str7);
                    driver.FindElement(By.CssSelector("input[type=\"submit\"]")).Click();
                    try
                    {
                    }
                    catch (Exception exception)
                    {
                        Console.Write(exception);
                    }
                    var num3 = table.Rows.Count;
                    for (var j = 0; j < num3; j++)
                    {
                        var str13 = table.Rows[j]["Card Number"].ToString();
                        var str14 = table.Rows[j]["Security Code"].ToString();
                        var expected = table.Rows[j]["CardType"].ToString();
                        var str16 = table.Rows[j]["Name on Card"].ToString();
                        var optionLocator = table.Rows[j]["ExpiryMonth"].ToString();
                        var str18 = table.Rows[j]["Expiry Year"].ToString();
                        var str19 = table.Rows[j]["Phone Number"].ToString();
                        var str20 = table.Rows[j]["Address"].ToString();
                        var str21 = table.Rows[j]["City"].ToString();
                        var str22 = table.Rows[j]["Post Code"].ToString();
                        var str23 = table.Rows[j]["County"].ToString();
                        var str24 = table.Rows[j]["Country"].ToString();
                        driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(60.0));
                        driver.FindElement(By.XPath("//div[@id='Card.NameControl']/input"));
                        Assert.AreEqual("Secure Payment Page", driver.Title);
                        driver.FindElement(By.XPath("//*[@id='Card_Number']")).SendKeys(str13);
                        driver.FindElement(By.Id("//*[@id='Card_SecurityCode']")).SendKeys(str14);
                        new SelectElement(driver.FindElement(By.Id("Card_Type"))).SelectByText("Visa Debit");
                        new SelectElement(driver.FindElement(By.Id("Card_ExpiryDate_Month"))).SelectByText(optionLocator);
                        new SelectElement(driver.FindElement(By.Id("Card_ExpiryDate_Year"))).SelectByText(str18);
                        driver.FindElement(By.XPath("//div[@id='Card.NameControl']/input")).SendKeys(str16);
                        switch (str2)
                        {
                            case "id=actionPay":
                                driver.FindElement(By.Id("BillingContact_Phone_Number")).SendKeys(str19);
                                driver.FindElement(By.Id("BillingContact_Address_Line1")).SendKeys(str20);
                                driver.FindElement(By.XPath("//div[@id='BillingContact.Address.Line2Control']/input"))
                                      .SendKeys("s");
                                driver.FindElement(By.Id("BillingContact_Address_Postcode")).SendKeys(str22);
                                driver.FindElement(By.XPath("//div[@id='BillingContact.Address.TownControl']/input"))
                                      .SendKeys(str21);
                                driver.FindElement(By.Id("BillingContact_Address_County")).SendKeys(str23);
                                new SelectElement(
                                    driver.FindElement(
                                        By.XPath("//div[@id='BillingContact.Address.CountryControl']/div/div/select")))
                                    .SelectByText(str24);

                                break;

                            case "id=actionToken":
                                driver.FindElement(By.Id("Contact_Phone_Number")).SendKeys(str19);
                                driver.FindElement(By.Id("Contact_Address_Line1")).SendKeys(str20);
                                driver.FindElement(By.XPath("//div[@id='Contact.Address.Line2Control']/input"))
                                      .SendKeys("s");
                                driver.FindElement(By.Id("Contact_Address_Postcode")).SendKeys(str22);
                                driver.FindElement(By.XPath("//div[@id='Contact.Address.TownControl']/input"))
                                      .SendKeys(str21);
                                driver.FindElement(By.Id("Contact_Address_County")).SendKeys(str23);
                                new SelectElement(
                                    driver.FindElement(
                                        By.XPath("//div[@id='Contact.Address.CountryControl']/div/div/select")))
                                    .SelectByText(str24);
                                break;
                        }
                        driver.FindElement(By.Name("PostAction[Complete]")).Click();

                        Thread.Sleep(0x1388);
                        if (Regex.IsMatch(str13, "^[0-9'']"))
                        {
                            _datarow.Newrow("Card Number", str13, str13, "PASS", driver);
                        }
                        else if (driver.PageSource.Contains("Number required") ||
                                 driver.PageSource.Contains("Number invalid"))
                        {
                            _datarow.Newrow("Card Number", str13, "Number Invalid", "PASS", driver);
                        }
                        else
                        {
                            _datarow.Newrow("Card Number", str13, "No Error Message Displayed", "FAIL", driver);
                            screenshot.Screenshotfailed(driver);
                        }
                        _datarow.Newrow("Card Type", expected, expected, "PASS", driver);
                        var regex = new Regex("^[0-9]{3}$");
                        if (regex.IsMatch(str14))
                        {
                            _datarow.Newrow("Security Code", str14, "Valid 3 Digits", "PASS", driver);
                        }
                        else if (driver.PageSource.Contains("Security code required") ||
                                 driver.PageSource.Contains("Security code invalid"))
                        {
                            _datarow.Newrow("Security Code", str14, "Security code required", "PASS", driver
                                );
                        }
                        else
                        {
                            _datarow.Newrow("Security Code", str14, "No Error Message Displayed", "FAIL", driver
                                );
                            screenshot.Screenshotfailed(driver);
                        }
                        if (Regex.IsMatch(str16, "^[a-zA-Z'']"))
                        {
                            _datarow.Newrow("Name on Card", str16, str16, "PASS", driver);
                        }
                        else if (driver.PageSource.Contains("Name required"))
                        {
                            _datarow.Newrow("Name on Card", str16, "Name Required", "PASS", driver);
                        }
                        else
                        {
                            _datarow.Newrow("Name on Card", str16, "No Error Message Displayed", "PASS", driver);
                            screenshot.Screenshotfailed(driver);
                        }
                        if (Regex.IsMatch(input, "^[a-zA-Z'']"))
                        {
                            _datarow.Newrow("First Name", input, input, "PASS", driver);
                        }
                        else if (driver.PageSource.Contains("The First Name field is required."))
                        {
                            _datarow.Newrow("First Name", input, "The First Name field is required.", "PASS", driver
                                );
                        }
                        else
                        {
                            _datarow.Newrow("First Name", input, "No Error Message Displayed", "FAIL", driver);
                            screenshot.Screenshotfailed(driver);
                        }
                        if (Regex.IsMatch(str12, "^[a-zA-Z'']"))
                        {
                            _datarow.Newrow("Last Name", str12, str12, "PASS", driver);
                        }
                        else if (driver.PageSource.Contains("The Last Name field is required."))
                        {
                            _datarow.Newrow("Last Name", str12, "The Last Name field is required.", "PASS", driver
                                );
                        }
                        else
                        {
                            _datarow.Newrow("Last Name", str12, "No Error message Displayed", "FAIL", driver);
                            screenshot.Screenshotfailed(driver);
                        }
                        if (Regex.IsMatch(str20, "^[a-zA-Z0-9'']"))
                        {
                            _datarow.Newrow("Address", str20, str20, "PASS", driver);
                        }
                        else if (driver.PageSource.Contains("The Address field is required"))
                        {
                            _datarow.Newrow("Address", str20, "The Address field is required", "PASS", driver);
                        }
                        else
                        {
                            _datarow.Newrow("Address", str20, "No Error message Displayed", "FAIL", driver);
                            screenshot.Screenshotfailed(driver);
                        }
                        if (Regex.IsMatch(str22, "^[a-zA-Z0-9'']"))
                        {
                            _datarow.Newrow("Post Code", str22, str22, "PASS", driver);
                        }
                        else if (driver.PageSource.Contains("The Postcode field is required"))
                        {
                            _datarow.Newrow("Post Code", str22, "The Postcode field is required.", "PASS", driver
                                );
                        }
                        else
                        {
                            _datarow.Newrow("Post Code", str22, "No Error Message Displayed", "FAIL", driver);
                            screenshot.Screenshotfailed(driver);
                        }
                        if (Regex.IsMatch(str24, "^[a-zA-Z'']"))
                        {
                            _datarow.Newrow("Country", str24, str24, "PASS", driver);
                        }
                        else if (driver.PageSource.Contains("The Country field is required."))
                        {
                            _datarow.Newrow("Country", str24, "The Country field is required.", "PASS", driver);
                        }
                        else
                        {
                            _datarow.Newrow("Country", str24, "No Error Message", "FAIL", driver);
                            screenshot.Screenshotfailed(driver);
                        }
                        var title = driver.Title;
                        if (title == "Secure Payment Page") continue;
                        if (title == "Redirect to External")
                        {
                            Dsecure(driver);
                            break;
                        }
                        if (driver.PageSource.Contains("Checkout Accepted"))
                        {
                            Normaltransaction(driver);
                            break;
                        }
                        if (!driver.PageSource.Contains("Checkout Declined") &&
                            !driver.PageSource.Contains("Checkout Error")) continue;
                        _datarow.Newrow("Checkout", "Checkout Declined", "Checkout Declined", "PASS", driver
                            );
                        driver.FindElement(By.LinkText("start again")).Click();
                        break;
                    }
                }
            }
            catch (Exception exception2)
            {
                Console.Write(exception2);
                var actual = exception2.ToString();
                var screenshot2 = new Screenshot();
                _datarow.Newrow("Checkout", "Server Error", actual, "FAIL", driver);
                screenshot2.Screenshotfailed(driver);
            }
            finally
            {
                new Screenshot().Screenshotnotifications(driver);
                _datarow.Excelsave("MoPayReport", driver, "*****@*****.**");
                driver.Quit();
            }
        }
        public void Batchmoshop(IWebDriver driver, Datarow datarow, string items, string vers)
        {
            var screenshot = new Screenshot();
            try
            {
                var moshop = new MoShopConsole();
                moshop.Homepagetabs(driver, datarow);
                driver.Manage().Window.Maximize();

                var strArray = items.Split(new[] {','});

                foreach (var str in strArray.Where(str => str.Length != 0))
                {
                    #region Test Shop

                    if (str == "Create a Test Shop")
                    {
                        datarow.Newrow("", "", "Create a Test Shop", "", driver);
                        var testshop = new CreateShop();
                        testshop.Testshop(driver, datarow);

                        new LookandFeel().Lookandfeel(driver, datarow);

                        #region Global Settings

                        new GlobalSetting();
                        // global.globalsetting(driver);

                        #endregion
                    }

                    #endregion

                    #region Test Scrape

                    if (str == "Create a Test Scrape")
                    {
                        datarow.Newrow("", "", "Create a Test Scarpe", "", driver);
                        new Createscrape().CreateScrape(driver, datarow);
                    }

                    #endregion

                    #region Run Manual Scrape

                    if (str == "Run Manual Scrape")
                    {
                        datarow.Newrow("", "", "Run Manual Scrape", "", driver);
                        var run = new RunScrape();
                        run.Runscrape(driver, datarow);
                    }

                    #endregion

                    #region Custom Domain Name Feature and Localisation

                    if (str == "Validate Custom Domain Name Feature and Localisation")
                    {
                        datarow.Newrow("", "", "Validate Custom domain Name", "", driver);
                        new Shop().Culture(driver, datarow);
                    }

                    #endregion

                    #region "Run the Test Site - Scrape

                    if (str == "Run the Test Site - Scrape")
                    {
                        try
                        {
                            driver.Manage().Window.Size = new Size(400, 550);
                            datarow.Newrow("", "", "Run the Test Site", "", driver);
                            driver.Navigate().GoToUrl("http://testshop.mobankdev.com/");

                            new BlobStorage();
                            //blob.Blob(driver,datarow, "http://testshop.mobankdev.com/");
                            commtest(driver, datarow);
                        }
                        catch (Exception ex)
                        {
                            var e = ex.ToString();
                            datarow.Newrow("Exception", "Exception Not Expected", e, "FAIL", driver);
                        }
                    }

                    #endregion

                    #region Run the Test Site - DataFeed XML

                    if (str == "Run the Test Site - DataFeed XML")
                    {
                        var datafeed = new DatafeedXml();
                        datafeed.Datafeed(driver, datarow);
                        datarow.Newrow("", "", "Run the Test Site-DataFeed", "", driver);
                        driver.Navigate().GoToUrl("http://testshop.mobankdev.com/");

                        datarow.Newrow("", "", "Footer Links", "", driver);
                        var footer = new FooterTps();
                        footer.Footerhome(driver, "http://testshop.mobankdev.com/", datarow);
                        var relatedproduct = new RelatedProducts();
                        relatedproduct.Relatedproducts(driver, datarow);
                        //commtest(driver, datarow);
                    }

                    #endregion

                    #region Validate Products Against Live Site - Modropenia

                    if (str == "Validate Products Against Live Site - Modropenia")
                    {
                        var modrophenia = new Modrophenialive();
                        modrophenia.modrophenialiveproducts(driver);
                        var products = new Modropheniaproducts();
                        products.Product(datarow, driver);
                    }

                    #endregion

                    # region Delete Shop And Scrape

                    if (str != "Delete TestShop And TestScrape") continue;
                    var delete = new DeleteTestShop();
                    delete.Deleteshop(driver);
                    delete.Deletedscrape(driver);
        }

        #endregion Methods
    }

    catch(Exception exception)
    {
        var str2 = exception.ToString();
                datarow.Newrow("Exception", "Exception Not Expected", str2, "FAIL", driver);
                screenshot.Screenshotfailed(driver);
    }

     finally
    {
        datarow.Excelsave("MoshopConsole", driver, "*****@*****.**");
                screenshot.Screenshotfailed(driver);
                driver.Quit();
    }
}
        public void AllLink(IWebDriver driver, Datarow datarow)
        {
            var url = driver.PageSource;
            string categorylink;
            string cat;
            string products;
            string productlink;
            if (url.Contains("user-scalable=yes"))
            {
                categorylink = CollectionMapV2.Categorylink;
                cat = CollectionMapV2.Cat;
                products = CollectionMapV2.Products;
                productlink = CollectionMapV2.Productlink;
            }
            else
            {
                categorylink = CollectionMapV1.Categorylink;
                cat = CollectionMapV1.Cat;
                products = CollectionMapV1.Products;
                productlink = CollectionMapV1.Productlink;
            }
            // This method counts the categories,sub-categories, product pages and validate every product link
            var screenshot = new Screenshot();

            try
            {
                var image = new Imagevalidation();
                //Home Page Image validation

                image.Homepageimage(driver, datarow);
                //Counting the number of Categories
                decimal linkcount = driver.FindElements(By.XPath(categorylink)).Count;
                if (linkcount == 0)
                {
                    datarow.Newrow("Category Validation in Home Page", "Atleast One Category/product is Expected",
                                   "No Categories/Products are Identified", "FAIL", driver);
                }
                var j = 0;
                var s = 1;

                //Running the loop through the category links
                for (var i = 1; i <= linkcount; i++)
                {
                    try
                    {
                        driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(10));
                        driver.FindElement(By.XPath("" + categorylink + "[" + i + "]" + cat + ""));
                        driver.FindElement(By.XPath("" + categorylink + "[" + i + "]" + cat + "")).Click();
                    }
                    catch (Exception ex)
                    {
                        var e = ex.ToString();
                        datarow.Newrow("Category Element Exception", "Exception Not Expected", e, "FAIL", driver);
                        screenshot.Screenshotfailed(driver);
                    }
                    var categorycount = GetXpathCount(driver, categorylink);
                    if (categorycount == 0)
                    {
                        datarow.Newrow("Category Validation in  Page", "Atleast One Category/product",
                                       "No Categories/Products", "FAIL", driver);
                        screenshot.Screenshotfailed(driver);
                    }
                    //Running the loop through sub category pages.
                    for (var k = 1; ; k++)
                    {
                        try
                        {
                            if (IsElementPresent(driver, By.XPath("" + categorylink + "[" + k + "]" + cat + "")))
                            {
                                //*[@id="productList"]/article[1]/a/div[1]/img
                                // Category Image validation
                                image.categoryimage(driver, datarow);
                                driver.FindElement(By.XPath("" + categorylink + "[" + k + "]" + cat + "")).Click();

                                var titlecategory = driver.Title;

                                // Sub-Category Image validation
                                image.subcategoryimage(driver, datarow);

                                try
                                {
                                    if (IsElementPresent(driver,
                                                         By.XPath("" + products + "[" + 1 + "]" + productlink + "")))
                                    {
                                        datarow.Newrow("Product Title", "", titlecategory, "PASS", driver);
                                        //This is to test the product page
                                        var productcount = GetXpathCount(driver, products);
                                        for (var p = 1; p <= productcount; p++)
                                        {
                                            driver.FindElement(By.XPath("" + products + "[" + p + "]" + productlink + ""))
                                                  .Click();

                                            var page = new Productpage();
                                            page.ProductPage(driver, datarow);

                                            driver.Navigate().Back();
                                        }
                                    }
                                    else
                                    {
                                        datarow.Newrow("Category Title", "", titlecategory, "PASS", driver);
                                        k = 0;
                                    }
                                }
                                catch (Exception exc)
                                {
                                    var e = exc.ToString();
                                    datarow.Newrow("Exception For Product Details", "Exception Not Expected", e, "FAIL",
                                                   driver);
                                    screenshot.Screenshotfailed(driver);
                                }
                            }

                            k = s;
                            driver.Navigate().Back();

                            s++;
                            var url2 = driver.Url;
                            if (url2.Contains("category"))
                            {
                                datarow.Newrow("Category URL", "", url2, "PASS", driver);
                            }
                            else
                            {
                                s = 1;
                                break;
                            }
                        }
                        catch (Exception ex)
                        {
                            var e = ex.ToString();
                            datarow.Newrow("Category/Product Link Exception", "Exception Not Expected", e, "FAIL",
                                           driver);
                            screenshot.Screenshotfailed(driver);
                        }
                    }

                    j++;

                    //driver.Navigate().Back();
                    //
                }
            }
            catch (Exception)
            {
                datarow.Newrow("Exception", "", "Exception Not Expected", "FAIL", driver);
                screenshot.Screenshotfailed(driver);
            }
        }
 public static void SaveScreenshot(Screenshot screenshot)
 {
     screenshot.SaveAsFile(ConfigurationManager.AppSettings["remoteLocation"] + Test.testName + Test.testID + ".jpg", ImageFormat.Jpeg);
 }
Ejemplo n.º 31
0
 public static void AddScreenshot(string guid, Screenshot screenshot)
 {
     Screenshots.Add(new TempScreenshot { Guid = guid, Screenshot = screenshot });
 }
Ejemplo n.º 32
0
        public void TestTakeScreenshotWhenCalledWithoutErrorTakesScreenshot()
        {
            var driver = new Mock<IWebDriver>(MockBehavior.Strict);
            driver.As<ITakesScreenshot>().Setup(s => s.GetScreenshot()).Throws<InvalidOperationException>();

            var basePath = Path.GetTempPath();
            var fileName = Guid.NewGuid().ToString();
            
            Screenshot screenshot;
            using (var ms = new MemoryStream())
            {
                var image = TestResource.TestImage;
                image.Save(ms, ImageFormat.Jpeg);
                
                screenshot = new Screenshot(Convert.ToBase64String(ms.ToArray()));
            }

            var screenShot = driver.As<ITakesScreenshot>();
            screenShot.Setup(s => s.GetScreenshot()).Returns(screenshot);

            var logger = new Mock<ILogger>(MockBehavior.Loose);

            var browser = new SeleniumBrowser(new Lazy<IWebDriver>(() => driver.Object), logger.Object);

            string fullPath = null;
            try
            {
                fullPath = browser.TakeScreenshot(basePath, fileName);
            }
            finally
            {
                if (fullPath != null && File.Exists(fullPath))
                {
                    File.Delete(fullPath);
                }
            }

            Assert.IsNotNull(fullPath);
            driver.VerifyAll();
        }
 private static void TekeScreeshot()
 {
     screenshot = ((ITakesScreenshot)Browser.Browser.Instance).GetScreenshot();
     Util.SaveScreenshot(screenshot);
 }
Ejemplo n.º 34
0
 /// <summary>
 /// Takes screenshot and saves it in desired location
 /// </summary>
 /// <param name="format">Format of image file</param>
 public static void TakeScreenshot(ScreenshotImageFormat format = ScreenshotImageFormat.Png)
 {
     OpenQA.Selenium.Screenshot shot = ((ITakesScreenshot)Browser.Driver).GetScreenshot();
     shot.SaveAsFile(ShotPath + ShotName, format);
 }
        //Product page validations
        public void Product(IWebDriver driver, Datarow datarow)
        {
            var image = new Imagevalidation();
            try
            {
                var url = driver.PageSource;

                string producttitle;
                string addToBasket;
                string checkout;
                string basketvalue;
                var screenshot1 = new Screenshot();

                #region object reading

                if (url.Contains("user-scalable=yes"))
                {
                    producttitle = CollectionMapV2.Producttitle;
                    addToBasket = CollectionMapV2.Addtobasket;
                    checkout = CollectionMapV2.Checkout;
                    basketvalue = BasketV2.basketvalue;
                }
                else
                {
                    producttitle = CollectionMapV1.Producttitle;
                    addToBasket = CollectionMapV1.Addtobasket;
                    checkout = CollectionMapV1.Checkout;
                    basketvalue = BasketV1.basketvalue;
                }

                #endregion

                image.productImage(driver, datarow);
                new ProductDetail().Productdetail(driver, datarow);
                new ProductPrice().Price(driver, datarow);

                #region Product Title

                // Product Title
                var title = driver.FindElement(By.ClassName(producttitle)).Text;
                datarow.Newrow("Product Title", "", title, "PASS", driver);

                if (IsElementPresent(driver, By.ClassName(producttitle)) == false)
                {
                    datarow.Newrow("Product Title", "Product Title Element is Expected",
                                   "Product Title Element Not Found", "FAIL", driver);
                }

                #endregion

                #region Product Variant

                /*
                // Product Variants
                if(IsElementPresent(driver,By.Id("" + productVarinat + "")))
                {
                    try
                    {
                        decimal couent =GetXpathCount(driver,"//html/body/div/div[2]/div/div[4]/form/ul/li[2]/fieldset/div[2]/div/label/span");

                        if (couent != 1)
                        {
                                  IWebElement con = driver.FindElement(By.Id(" + productVarinat + "));
                                  IList<IWebElement> selectOptions = con.FindElements(By.TagName("option"));

                            string values = null;
                            foreach (IWebElement value in selectOptions)
                            {
                                if (value.Text != "Please Select")
                                {
                                    values = values + "\r\n" + value;
                                    new SelectElement(driver.FindElement(By.Id(productVarinat))).SelectByText(value.Text);
                                }
                            }
                            datarow.newrow("Variants", "", values, "PASS",driver);
                        }

                        else
                        {
                            string varinats = GetValue(driver, By.Id("" + productVarinat + ""));
                            datarow.newrow("Variants", "", varinats, "PASS",driver);
                        }
                    }
                    catch (Exception ex)
                    {
                        string e = ex.ToString();

                        datarow.newrow("Exception Not Expected", "Exception Not Expected", e, "FAIL");
                    }
                }

                else if(IsElementPresent(driver,By.Id("" + productVarinat + "_0")))
                {
                    try
                    {
                        string values = null;
                        for (int q = 1;; q++)
                        {
                            if (IsElementPresent(driver,By.Id("" + productVarinat + "" + q + "")))
                            {
                                string varinats =  driver.FindElement(By.Id("" + productVarinat + "" + q + "")).Text;
                                if (varinats != "Please Select" || varinats != null)
                                {
                                    values = values + "\r\n" + varinats;
                                    driver.FindElement(By.Id("" + productVarinat + "" + q + "")).Click();
                                }
                            }

                            else
                            {
                                break;
                            }
                        }
                        datarow.newrow("Variants", "", values, "PASS",driver);
                    }
                    catch (Exception ex)
                    {
                        string e = ex.ToString();
                        throw;
                    }
                }
                else
                {
                    datarow.newrow("Variants", "", "No Variants", "PASS", driver);
                }

                #endregion

                #region V2 Product Variant

                if (url.Contains("user-scalable=yes"))
                {
                    if (IsElementPresent(driver,By.XPath("//a[@id='showOptions']/span")))
                    {
                        driver.FindElement(By.XPath("//a[@id='showOptions']/span")).Click();

                        IWebElement con = driver.FindElement(By.Id("Variants_1__OptionValue"));
                         IList<IWebElement> vainats = con.FindElements(By.TagName("option"));
                       ;
                        string vales = null;
                        foreach (IWebElement value in vainats)
                        {
                            if (value.Text != "Please Select")
                            {
                                vales = vales + "\r\n" + value;
                                new SelectElement(driver.FindElement(By.Id("Variants_1__OptionValue"))).SelectByText(value.Text);
                            }
                        }

                        datarow.newrow("Variants", "", vales, "PASS",driver);
                        if (IsElementPresent(driver,By.Id("" + productvariant2 + "_0")))
                        {
                            string values = null;
                            for (int q = 1;; q++)
                            {
                                if (IsElementPresent(driver,By.Id("" + productvariant2 + "_" + q + "")))
                                {
                                    string varinats =  driver.FindElement(By.Id("" + productvariant2 + "_" + q + "")).Text;
                                    if (varinats != "Please Select" || varinats != null)
                                    {
                                        values = values + "\r\n" + varinats;
                                        driver.FindElement(By.Id("" + productvariant2 + "_" + q + "")).Click();
                                    }
                                }
                                else
                                {
                                    break;
                                }
                            }
                        }
                    }
                }
            */

                #endregion

                try
                {
                    driver.FindElement(By.XPath(addToBasket)).Click();

                    datarow.Newrow("Add to Basket Button", "Add To Basket Button is Expected",
                                   addToBasket + "Add To Basket Element Is Present", "PASS", driver);
                    new SuccessMessage().Message(driver, datarow);
                }
                catch (Exception ex)
                {
                    var e = ex.ToString();
                    datarow.Newrow("Add to Basket Button", "Add To Basket Button is Expected", e, "FAIL", driver);
                    screenshot1.Screenshotfailed(driver);
                }

                var basval = driver.FindElement(By.XPath(basketvalue)).Text;

                if (basval == "(1)")
                {
                    datarow.Newrow("Basket Value", "(1)", basval, "PASS", driver);
                }
                else
                {
                    datarow.Newrow("Basket Value", "(1)", basval, "FAIL", driver);
                    screenshot1.Screenshotfailed(driver);
                }

                //Footer_TPS footer = new Footer_TPS();
                //footer.Footer(driver, datarow);

                driver.FindElement(By.Id("BasketInfo")).Click();

                new SelectElement(driver.FindElement(By.Id("Items_0__Quantity")));

                // driver.FindElement(By.Id()).Click();("css=option");
                var pric = driver.FindElement(By.CssSelector("strong")).Text;
                new SelectElement(driver.FindElement(By.Id("Items_0__Quantity"))).SelectByText("4");

                Thread.Sleep(3000);
                var prirc = driver.FindElement(By.CssSelector("strong")).Text;

                datarow.Newrow("Price Change with Quantity in Basket Page", pric, prirc, pric == prirc ? "FAIL" : "PASS",
                    driver);

                driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(10));
                driver.FindElement(By.XPath(checkout));
                if (url.Contains("user-scalable=yes") == false)
                {
                    var value1 = driver.FindElement(By.Id("BasketInfo")).Text;

                    if (value1 == "(4)")
                    {
                        datarow.Newrow("Basket Value", "(4)", value1, "PASS", driver);
                    }
                    else
                    {
                        datarow.Newrow("Basket Value", "(4)", value1, "FAIL", driver);
                        screenshot1.Screenshotfailed(driver);
                    }
                }
                new SelectElement(driver.FindElement(By.Id("Items_0__Quantity")));
            }
            catch (Exception ex)
            {
                var e = ex.ToString();
                datarow.Newrow("Exception", "Exception Not Expected", e, "FAIL", driver);
                _screenshot.Screenshotfailed(driver);
            }
        }
        /*
        private readonly Screenshot screenshot = new Screenshot();
        */
        public void userdata_TPS(IWebDriver driver, Datarow datarow)
        {
            var url = driver.PageSource;

            string field;
            string fieldlabel;
            string fieldinput;
            string fieldcountry;
            string countryvalue;
            string submitbutton;
            string letters;
            string termsncond;
            string submitterms = null;
            string paybutton;

            var screenshot1 = new Screenshot();

            if (url.Contains("user-scalable=yes"))
            {
                field = AddressMapV2.field;
                fieldlabel = AddressMapV2.fieldlabel;
                fieldinput = AddressMapV2.fieldinput;
                fieldcountry = AddressMapV2.fieldcountry;
                countryvalue = AddressMapV2.coutryvalue;
                submitbutton = AddressMapV2.submitbutton;
                letters = AddressMapV2.terms;
                termsncond = CheckoutMapV2.termsncond;
                submitterms = CheckoutMapV2.submitterms;
                paybutton = CheckoutMapV2.paybutton;
            }
            else
            {
                field = AddressMapV1.field;
                fieldlabel = AddressMapV1.fieldlabel;
                fieldinput = AddressMapV1.fieldinput;
                fieldcountry = AddressMapV1.fieldcountry;
                countryvalue = AddressMapV1.coutryvalue;
                submitbutton = AddressMapV1.submitbutton;
                letters = AddressMapV1.sendletters;
                termsncond = CheckoutMapV1.termsncond;
                paybutton = CheckoutMapV1.paybutton;
            }
            try
            {
                driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(10));
                driver.FindElement(By.XPath(submitbutton));

                var count = GetXpathCount(driver, field);
                if (count == 0)
                {
                    datarow.Newrow("User Data Form Details", "Expected User Form Fields",
                                   "User Form Fields Doesnot Exist", "FAIL", driver);
                }
                //Populating Customer Details from Excel Sheet
                for (var i = 1; i <= count; i++)
                {
                    if (!IsElementPresent(driver, By.XPath("" + field + "[" + i + "]" + fieldlabel + ""))) continue;
                    var valuet = driver.FindElement(By.XPath("" + field + "[" + i + "]" + fieldlabel + "")).Text;

                    if (!valuet.Contains("Country"))
                    {
                        driver.FindElement(By.XPath("" + field + "[" + i + "]" + fieldinput + "")).Clear();
                        driver.FindElement(By.XPath("" + field + "[" + i + "]" + fieldinput + "")).SendKeys("TEST");
                        datarow.Newrow("Form Field", "", valuet, "PASS", driver);
                    }

                    #region Country

                    // selecting the country
                    if (valuet.Contains("Country"))
                    {
                        try
                        {
                            var j = i - 1;
                            var con =
                                driver.FindElement(By.Id("" + fieldcountry + "" + j + "" + countryvalue + ""));
                            IList<IWebElement> countries = con.FindElements(By.TagName("option"));

                            string values = null;
                            foreach (var value in countries.Where(value => !value.Text.Contains("Please") || value.Text != "Select country"))
                            {
                                if (value.Text == "United Kingdom")
                                {
                                    values = values + "\r\n" + value;
                                    new SelectElement(
                                        driver.FindElement(
                                            By.Id("" + fieldcountry + "" + j + "" + countryvalue + "")))
                                        .SelectByText(value.Text);
                                    break;
                                }

                                values = values + "\r\n" + value;
                                // new SelectElement(driver.FindElement(By.Id("" + fieldcountry + "" + j + "" + countryvalue + "")))  new SelectElement(driver.FindElement(By.Id(""))).SelectByText("");ByText(value);

                            }
                            datarow.Newrow("Country Field", "", values, "PASS", driver);
                        }
                        catch (Exception ex)
                        {
                            var e = ex.ToString();
                            datarow.Newrow("Country Field Exception", "Exception Not Expected", e, "PASS", driver
                                );
                        }
                    }

                    #endregion

                    #region Email

                    if (!valuet.Contains("Email")) continue;
                    try
                    {
                        driver.FindElement(By.XPath("" + field + "[" + i + "]" + fieldinput + "")).Clear();
                        driver.FindElement(By.XPath("" + field + "[" + i + "]" + fieldinput + ""))
                            .SendKeys("*****@*****.**");
                    }
                    catch (Exception ex)
                    {
                        var e = ex.ToString();
                        datarow.Newrow("Email Field Exception", "Exception Not Expected", e, "FAIL", driver
                            );
                        screenshot1.Screenshotfailed(driver);
                    }

                    #endregion
                }
            }
            catch (Exception ex)
            {
                var e = ex.ToString();
                datarow.Newrow("Exception in DataForm", "Exception Not Expected", e, "FAIL", driver);
                screenshot1.Screenshotfailed(driver);
            }
            try
            {
                //Email/ Letter sending Confirmation
                if (IsElementPresent(driver, By.XPath("" + field + "[" + 11 + "]" + letters + "")))
                {
                    driver.FindElement(By.XPath("" + field + "[" + 11 + "]" + letters + "")).Click();
                }

                driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(10));
                driver.FindElement(By.XPath(submitbutton));
                driver.FindElement(By.XPath(submitbutton)).Click();

                var basval = driver.FindElement(By.Id("BasketInfo")).Text;

                // Terms and Conditions
                if (IsElementPresent(driver, By.XPath(termsncond)))
                {
                    driver.FindElement(By.XPath(termsncond)).Click();
                }
                //Submit button
                if (IsElementPresent(driver, By.XPath(submitterms)))
                //*[@id="main-page"]/div[9]/div/div[2]/div/button
                {
                    //html/body/div/div[7]/div/div[2]/div/button
                    driver.FindElement(By.XPath(submitterms)).Click();

                    Thread.Sleep(2000);
                }
                //string details =  driver.FindElement(By.Id("")).Text;("css=div.ui-content.ui-body-c > p");

                //Pay Button
                if (IsElementPresent(driver, By.XPath(paybutton)))
                {
                    //html/body/div/div[7]/div/div[2]/a/span/span
                    driver.FindElement(By.XPath(paybutton)).Click();
                }
            }
            catch (Exception ex)
            {
                var e = ex.ToString();
                datarow.Newrow("Exception in DataForm", "Exception Not Expected", e, "FAIL", driver);
                screenshot1.Screenshotfailed(driver);
            }
        }
Ejemplo n.º 37
0
		private void HandleResult(ITestWorker testWorker, TestResult testResult)
		{
			if (testWorker.WorkItem != null &&
			    (testResult.TestState == TestState.Error || testResult.TestState == TestState.ErrorRepeat) &&
			    testWorker.WorkItem.RunCount < RegtestingServerConfiguration.MaxRunCount)
			{
				_testPool.ReAddWorkItem(testWorker.WorkItem);
				testWorker.WorkItem = null;
				return;
			}
			
			WorkItem workItem = testWorker.WorkItem;
			workItem.TestState = testResult.TestState;

			string imagefile = null;
			if (!String.IsNullOrEmpty(testResult.Screenshot))
			{
				string folder = RegtestingServerConfiguration.Screenshotsfolder;
				string subFolder = DateTime.Now.Year + "-" + DateTime.Now.Month + "\\";
				string fileName = "screen" + Helper.GetScreenshotString() + ".png";
				Directory.CreateDirectory(folder + subFolder);
				imagefile = subFolder + fileName;
				Screenshot screenshot = new Screenshot(testResult.Screenshot);
				screenshot.SaveAsFile(folder + imagefile, ImageFormat.Png);
			}

			Result result = _resultRepository.Get(workItem.Testsystem, workItem.Testcase, workItem.Browser,
				workItem.Language);
			result.ResultCode = testResult.TestState;
			result.DetailLog = CreateLog(testResult.Log);
			result.Error = testResult.Error;
			result.Testtime = DateTime.Now;
			result.ScreenshotFile = imagefile;
			if (result.ResultCode == TestState.Error || result.ResultCode == TestState.ErrorRepeat ||
			    result.ResultCode == TestState.KnownError)
			{
				if (result.ErrorCount == null)
				{
					result.ErrorCount = 1;
					result.ErrorSince = result.Testtime;
				}
				else
				{
					result.ErrorCount = result.ErrorCount + 1;
				}
			}
			else
			{
				result.ErrorSince = null;
				result.ErrorCount = null;
			}
			_resultRepository.Store(result);
			workItem.Result = result;


			foreach (ITestJobManager testJobManager in workItem.TestJobManagers)
			{
				HistoryResult historyResult = Mapper.Map<HistoryResult>(workItem);
				historyResult.DetailLog = CreateLog(testResult.Log);
				historyResult.ResultCode = testResult.TestState;
				historyResult.Error = testResult.Error;
				historyResult.Testtime = DateTime.Now;
				historyResult.TestJob = testJobManager.TestJob;
				historyResult.ScreenshotFile = imagefile;
				_historyResultRepository.Store(historyResult);
			}
			lock (TestsystemSummariesCache.Cache.GetLock(workItem.Testsystem.ID))
			{
				TestsystemSummariesCache.Cache.Set(workItem.Testsystem.ID, null);
			}
			testWorker.WorkItem = null;

			_testPool.WorkItemFinished(workItem);

		}
Ejemplo n.º 38
0
 public ErrorDetails(Screenshot screenshot, DateTime dateTime, Exception exception)
 {
     this.Screenshot = screenshot;
     this.DateTime = DateTime;
     this.Exception = exception;
 }
Ejemplo n.º 39
-2
 private void SaveScreenshot(Screenshot screenshot, string fileName)
 {
     screenshot.SaveAsFile(string.Format("{0}{1}", ConfigurationHelper.FolderPicture, fileName), ImageFormat.Png);
 }