public void clickimage(IWebDriver driver, Datarow datarow, By by)
 {
     driver.FindElement(by).Click();
     var url = driver.Url;
     datarow.Newrow("Image Click Validation", "http://qamodrophenia.mobankdev.com/", url,
         url == "http://qamodrophenia.mobankdev.com/" ? "PASS" : "FAIL");
     driver.Navigate().Back();
 }
        public void Homepageimage(IWebDriver driver, Datarow datarow)
        {
            try
            {
                var url = driver.Url;

                var title = driver.PageSource;
                _homepageimage = title.Contains("user-scalable=yes") ? ImagesV2.Homepageimage : ImagesV1.Homepageimage;

                // Home Page Image Validation
                if (IsElementPresent(driver, By.XPath("Homepageimage"), 30))
                {
                    if (title.Contains("user-scalable=yes"))
                    {
                        var contactus = driver.FindElement(By.XPath("//*[@id='main-page']/div[4]/h1/a/img"));
                        var path1 = contactus.GetAttribute("src");
                        datarow.Newrow("Contact US Image Validation", "", path1, "PASS", driver);
                    }
                    var element = driver.FindElement(By.XPath(_homepageimage));
                    var path = element.GetAttribute("src");
                    datarow.Newrow("Image Validation", "", path, "PASS", driver);
                    if (path.Contains("http") || path.Contains("https") || path.Contains("blob"))
                    {
                        datarow.Newrow("Image URL Validation", "Image url shouldnot contain http/https", path, "FAIL",
                                       driver);
                    }
                    else
                    {
                        datarow.Newrow("Image URL Validation", "Image url shouldnot contain http/https", path, "PASS",
                                       driver);
                    }
                    clickimage(driver, datarow, By.XPath(_homepageimage));
                }
                else if (IsElementPresent(driver, By.CssSelector("img.categoryImage"), 30))
                {
                    var element = driver.FindElement(By.CssSelector("img.categoryImage"));
                    var path = element.GetAttribute("src");
                    datarow.Newrow("Image Validation", "", path, "PASS", driver);
                    clickimage(driver, datarow, By.CssSelector("img.categoryImage"));
                }
                else
                {
                    datarow.Newrow("Image Validation", "", "No Image for Home Page" + "-" + url, "FAIL", driver);
                }
            }

            catch (Exception)
            {
                datarow.Newrow("Exception", "", "Exception Not Expected", "FAIL", driver);
            }
        }
 public void categoryimage(IWebDriver driver, Datarow datarow)
 {
     try
     {
         if (_l >= 3) return;
         var title = driver.PageSource;
         _categoryimagecss = title.Contains("user-scalable=yes") ? ImagesV2.Categoryimagecss : ImagesV1.Categoryimagecss;
         var location = driver.Url;
         if (IsElementPresent(driver, By.CssSelector(_categoryimagecss), 30))
         {
             var element = driver.FindElement(By.CssSelector(_categoryimagecss));
             var path = element.GetAttribute("src");
             datarow.Newrow("Image Validation", "", path, "PASS", driver);
             if (path.Contains("http") || path.Contains("https") || path.Contains("blob"))
             {
                 datarow.Newrow("Image URL Validation", "Image url shouldnot contain http/https", path,
                     "FAIL", driver);
             }
             else
             {
                 datarow.Newrow("Image URL Validation", "Image url shouldnot contain http/https", path,
                     "PASS", driver);
             }
             clickimage(driver, datarow, By.CssSelector(_categoryimagecss));
         }
         else
         {
             datarow.Newrow("Image Validation", "", "No Image for Category page" + "-" + location, "FAIL",
                 driver);
         }
         _l++;
     }
     catch (Exception)
     {
         datarow.Newrow("Exception", "", "Exception Not Expected", "FAIL", driver);
     }
 }
        public void Tabbatch(Datarow datarow, IWebDriver driver)
        {
            //Method Homapge validations

            #region HomePage Validations

            driver.Navigate().GoToUrl("http://tablet.mobankdev.com");
            new Driverdefining();

            var title = driver.Title;
            //Validating the Home page title.

            datarow.Newrow("Home Page Title", "Tablet: Tickle Shop", title,
                title == "Tablet: Tickle Shop" ? "PASS" : "FAIL");
            var blob = new BlobStorage();
            blob.Blob(driver, datarow, "http://tablet.mobankdev.com");
            var home = new HomepageTab();
            home.Homepage(driver, datarow);
            var allproducts = new LinksExpand();
            allproducts.AllLink(driver, datarow);

            #endregion
        }
        public void Blob(IWebDriver driver, Datarow datarow, string url)
        {
            try
            {
                // Validating the Cache control and Cache - Public
                var request = (HttpWebRequest) WebRequest.Create(url);
                request.Method = "GET";
                request.ServicePoint.Expect100Continue = false;
                request.ContentType = "application/x-www-form-urlencoded";
                datarow.Newrow("", "", "Validating Blob URL", "");
                using (var response = request.GetResponse())
                {
                    using (var reader = new StreamReader(response.GetResponseStream()))
                    {
                        reader.ReadToEnd();
                        var rawHeaders = request.GetResponse().Headers.ToString();
                        if (rawHeaders.Contains("public"))
                        {
                            datarow.Newrow("Cache Control", "Cache Control is Public", rawHeaders, "PASS");
                            var cache = rawHeaders.Split('f');
                            foreach (var s in cache.Where(s => s.Contains("Date")))
                            {
                                datarow.Newrow("Cache Control", "Cache Limit is Set to 30 Mins", s, "PASS");
                            }
                        }
                        else
                        {
                            datarow.Newrow("Cache Control", "Cache Control is not Public", rawHeaders, "PASS");
                        }
                    }
                }

                // Validating CSS URL from the page source
                var css = driver.PageSource;
                var selectedvalue = css.Split('<');
                foreach (var ss in selectedvalue.Where(ss => ss.Contains("themes")))
                {
                    if (ss.Contains("http") || ss.Contains("https") || ss.Contains("blob"))
                    {
                        datarow.Newrow("CSS Validation", "Http/Https and Blob shouldnot contain inside the CSS Url",
                            ss, "FAIL");
                    }
                    else
                    {
                        datarow.Newrow("CSS Validation", "Http/Https and Blob shouldnot contain inside the CSS Url",
                            ss, "PASS");
                    }

                    break;
                }
                datarow.Newrow("", "", "Validating GET for Search Results", "");
                foreach (var GET in selectedvalue.Where(GET => GET.Contains("GET")))
                {
                    datarow.Newrow("Validate Search Results Using GET", "Search Results Using GET method", GET,
                        "PASS");
                }

                var image = new Imagevalidation();
                image.Homepageimage(driver, datarow);
            }
            catch (Exception ex)
            {
                var e = ex.ToString();
                datarow.Newrow("Exception", "Exception Not Expected", e, "FAIL");
            }
        }
        public void subcategoryimage(IWebDriver driver, Datarow datarow)
        {
            try
            {
                //string location = driver.Url;
                //if (IsElementPresent("css=img.categoryImage"))
                //{
                //    IWebElement element = driver.FindElement(By.XPath("//body[@id='page-categories-details']/div/div[2]/div/img"));
                //    string path = element.GetAttribute("src");
                //    datarow.newrow("Image Validation", "", path, "PASS",driver);

                //}
                //else
                //{
                //    datarow.newrow("Image Validation", "", "No Image for Sub-Category page" + "-" + location, "FAIL",driver);

                //}
            }
            catch (Exception)
            {
                datarow.Newrow("Exception", "", "Exception Not Expected", "FAIL", driver);
            }
        }
        public void productImage(IWebDriver driver, Datarow datarow)
        {
            try
            {
                string productimage;
                string productimagelink;
                string multiproductimage;

                var url = driver.PageSource;
                var location = driver.Url;
                if (url.Contains("user-scalable=yes"))
                {
                    productimage = ImagesV2.productimage;
                    productimagelink = ImagesV2.productimagelink;
                    multiproductimage = ImagesV2.multiproductimage;
                }
                else
                {
                    productimage = ImagesV1.productimage;
                    productimagelink = ImagesV1.productimagelink;
                    multiproductimage = ImagesV1.multiproductimage;
                }

                if (IsElementPresent(driver, By.XPath("" + productimage + "" + productimagelink + "")))
                {
                    var element = driver.FindElement(By.XPath("" + productimage + "" + productimagelink + ""));
                    var path = element.GetAttribute("src");
                    datarow.Newrow("Image Validation", "", path, "PASS", driver);
                }
                    //multi- Product Image
                    //body[@id='page-products-details']/div/div[2]/div/div[2]/div/ul/li[2]/img
                else if (IsElementPresent(driver, By.XPath(multiproductimage)))
                {
                    decimal count = driver.FindElements(By.XPath("" + productimage + "")).Count;
                    for (var o = 2; o < count; o++)
                    {
                        var element =
                            driver.FindElement(By.XPath("" + productimage + "[" + o + "]" + productimagelink + ""));
                        var path = element.GetAttribute("src");
                        datarow.Newrow("Image Validation", "", path, "PASS", driver);
                    }
                }
                else
                {
                    datarow.Newrow("Image Validation", "", "No Image in Product Page" + "-" + location, "FAIL", driver);
                }
            }
            catch (Exception)
            {
                datarow.Newrow("Exception", "", "Exception Not Expected", "FAIL", driver);
            }
        }
        public void Mositetp(string url, Datarow datarow)
        {
            try
            {
                var item = checkedListBox3.CheckedItems.Cast<object>().Aggregate<object, string>(null, (current, items) => current + "," + items);

                if (item == null)
                {
                    MessageBox.Show(@"Please Select Atleast One Functionality To Test From Options Available");
                }
                else
                {
                    try
                    {
                        // Initialising the firefox driver

                        // An Static url should be given for the browser to launch.

                        var prof = new FirefoxProfile();
                        //changing the User agent to Iphone 4.
                        prof.SetPreference("general.useragent.override",
                                           "Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_0 like Mac OS X; en-us) AppleWebKit/532.9 (KHTML, like Gecko) Version/4.0.5 Mobile/8A293 Safari/6531.22.7");
                        IWebDriver driver = new FirefoxDriver(prof);
                        driver.Navigate().GoToUrl(url);

                        Thread.Sleep(2000);

                        var mobileurl = driver.Url;
                        datarow.Newrow("Mobile URL Validation", "Mobile URL", mobileurl,
                            mobileurl == url ? "FAIL" : "PASS", driver);

                        var testing = new BatchTesting();
                        testing.Batchtesting(item, url, driver, datarow);
                        var emails = _textBox2.Text;
                        var site = new MositeGeneral();
                        site.Finally(driver, url, datarow, emails);
                    }
                    catch (Exception)
                    {
                    }
                }
            }
            catch (Exception ex)
            {
                var u = ex.ToString();
                MessageBox.Show(u);
            }
        }