Пример #1
0
        public void FirefoxTest5()
        {
            WebDriverUtil webDriverUtil = new WebDriverUtil();
            IWebDriver    Driver        = webDriverUtil.GetDriver(BrowserType.Firefox);

            Driver.Navigate().GoToUrl("http://automationpractice.com/index.php");
            Driver.FindElement(By.Id("search_query_top")).SendKeys(Guid.NewGuid().ToString());
            Driver.FindElement(By.XPath("//button[@name='submit_search']")).Click();
            string messageAfterClickingSearch = Driver.FindElement(By.XPath("//div[@id='center_column']//p[@class='alert alert-warning']")).Text;

            Assert.That(messageAfterClickingSearch, Does.Contain("No results were found for your search"));
            Driver.Quit();
            Driver.Dispose();
        }
Пример #2
0
        public void TestCreateNewClaimantsForEG(string testdata, string createType, string docId, string docType, string classType, string claimantId, string taxType, string taxID, string firstName, string middleName, string lastName, string suffix, string businessName, string addressType, string address1, string address2, string city, string state, string zipCode, string emailAddress, string confirmEmail, string homePhone, string mobile, string mobileProvider, string commPref, string lawFirmYN, string lawFirmName, string facilityynid, string sign)
        {
            string cid = null;

            ReActions.GoToDocCat();
            switch (createType)
            {
            case "GetNext":
                ReActions.ClickOnGetNext();
                break;

            case "DocID":
                ReActions.ClickOnDocLink(docId);
                break;
            }
            ReActions.AddNewClaimForm(docType, classType, claimantId);
            string parentWindowHandle = WebDriverUtil.GetParentWindowHandle();

            ReActions.SwitchToIFrame();
            ReActions.SetClaimantInfo(taxType, taxID, firstName, middleName, lastName, suffix, businessName, addressType, address1, address2, city, state, zipCode, emailAddress, confirmEmail, homePhone, mobile, mobileProvider, commPref);
            ReActions.ClickPage1Next();
            cid = ReActions.SaveGenClaimantId();
            ReActions.ClickPage2Next();
            ReActions.SetLawFirm(lawFirmYN, lawFirmName);
            ReActions.ClickPage3Next();
            if (facilityynid == "Y")
            {
                List <TestCaseData> facilitydata = ExcelColumnReader.GetAncillaryData(@"\NewClaimantEG.xlsx", "Facility", testdata);
                if (facilitydata != null)
                {
                    foreach (TestCaseData currFacilityData in facilitydata)
                    {
                        if (classType.Equals("Ethanol"))
                        {
                            ReActions.SetFacilityInfoForEthanol(currFacilityData.Arguments.GetValue(1).ToString(), currFacilityData.Arguments.GetValue(2).ToString(), currFacilityData.Arguments.GetValue(3).ToString(), currFacilityData.Arguments.GetValue(4).ToString(), currFacilityData.Arguments.GetValue(5).ToString(), currFacilityData.Arguments.GetValue(6).ToString(), currFacilityData.Arguments.GetValue(7).ToString(), currFacilityData.Arguments.GetValue(9).ToString(), currFacilityData.Arguments.GetValue(10).ToString(), currFacilityData.Arguments.GetValue(11).ToString(), currFacilityData.Arguments.GetValue(12).ToString(), currFacilityData.Arguments.GetValue(13).ToString(), currFacilityData.Arguments.GetValue(19).ToString());
                        }
                        else
                        {
                            ReActions.SetFacilityInfoForGrain(currFacilityData.Arguments.GetValue(1).ToString(), currFacilityData.Arguments.GetValue(2).ToString(), currFacilityData.Arguments.GetValue(3).ToString(), currFacilityData.Arguments.GetValue(4).ToString(), currFacilityData.Arguments.GetValue(5).ToString(), currFacilityData.Arguments.GetValue(6).ToString(), currFacilityData.Arguments.GetValue(8).ToString(), currFacilityData.Arguments.GetValue(14).ToString(), currFacilityData.Arguments.GetValue(15).ToString(), currFacilityData.Arguments.GetValue(16).ToString(), currFacilityData.Arguments.GetValue(17).ToString(), currFacilityData.Arguments.GetValue(18).ToString(), currFacilityData.Arguments.GetValue(19).ToString());
                        }
                    }
                }
            }
            ReActions.ClickPage4Next();
            ReActions.EnterSignAndSubmitClaim(sign);
            ReActions.CheckInIntakeDocument(parentWindowHandle);
        }
        public void OneTimeSetUp()
        {
            WebDriverUtil.InitializeBrowser(projectUrl);
            UIActions.Login(userid, password);
            ReActions.GoToReview();
            switch (reviewType)
            {
            case "AwaitingQueue":
                RqActions.SearchReviewClaimant(claimantId, reviewQueueType);
                RqActions.StartReview();
                break;

            case "PendingQueue":
                RqActions.CheckOutClaimant(claimantId);
                break;
            }
        }
Пример #4
0
        public void Handle(ref Request request, IDownloader downloader)
        {
            if (!(downloader is WebDriverDownloader d) || d._driver != null)
            {
                return;
            }
            d._driver     = WebDriverUtil.Open(_browser, _option);
            d._driver.Url = request.Url;
            Logger?.LogInformation("实例化浏览器");
            var cookies = GetAllCookies(CookieContainer);

            foreach (System.Net.Cookie cookie in cookies)
            {
// 此处不能通过直接调用AddCookie来添加, 会导致CookieContainer添加重复值
                d._driver.Manage().Cookies.AddCookie(new OpenQA.Selenium.Cookie(cookie.Name, cookie.Value,
                                                                                cookie.Domain, cookie.Path
                                                                                , null));
            }
        }
        public void Handle(ref Request request, IDownloader downloader)
        {
            if (_driver == null)
            {
                _driver = WebDriverUtil.Open(_browser, _option);

                if (_domains != null)
                {
                    foreach (var domain in _domains)
                    {
                        var cookies = CookieContainer.GetCookies(new Uri(domain));
                        foreach (System.Net.Cookie cookie in cookies)
                        {
                            // 此处不能通过直接调用AddCookie来添加, 会导致CookieContainer添加重复值
                            _driver.Manage().Cookies.AddCookie(new OpenQA.Selenium.Cookie(cookie.Name, cookie.Value, cookie.Domain, cookie.Path, null));
                        }
                    }
                }
            }
        }
Пример #6
0
        public static void CreateTestStatus(string projectName)
        {
            try
            {
                var    status       = TestContext.CurrentContext.Result.Outcome.Status;
                var    stacktrace   = "" + TestContext.CurrentContext.Result.StackTrace + "";
                var    errorMessage = TestContext.CurrentContext.Result.Message;
                Status logstatus;
                switch (status)
                {
                case TestStatus.Failed:
                    fCount++;
                    emailBody = emailBody + "<tr><td>" + TestContext.CurrentContext.Test.Name + "</td><td>Failed</td><td>" + errorMessage + "</td></tr>";
                    logstatus = Status.Fail;
                    string screenShotPath = WebDriverUtil.Capture(TestContext.CurrentContext.Test.MethodName, projectName);
                    _test.Log(logstatus, "Test ended with " + logstatus + " – " + errorMessage);
                    _test.Log(logstatus, "Snapshot below: " + _test.AddScreenCaptureFromPath(screenShotPath));
                    break;

                case TestStatus.Skipped:
                    sCount++;
                    emailBody = emailBody + "<tr><td>" + TestContext.CurrentContext.Test.Name + "</td><td>Skipped</td><td>" + errorMessage + "</td></tr>";
                    logstatus = Status.Skip;
                    _test.Log(logstatus, "Test ended with " + logstatus + " - " + errorMessage);
                    break;

                default:
                    pCount++;
                    emailBody = emailBody + "<tr><td>" + TestContext.CurrentContext.Test.Name + "</td><td>Passed</td><td>" + errorMessage + "</td></tr>";
                    logstatus = Status.Pass;
                    _test.Log(logstatus, "Test ended with " + logstatus + " " + errorMessage);
                    break;
                }
            }
            catch (Exception e)
            {
                throw (e);
            }
        }
Пример #7
0
 public void OneTimeSetUp()
 {
     WebDriverUtil.InitializeBrowser(projectUrl);
     UIActions.Login(userid, password);
 }
Пример #8
0
 public void TearDown()
 {
     //UIActions.Logout();
     WebDriverUtil.CloseAll();
 }
 public void OneTimeTearDown()
 {
     WebDriverUtil.CloseAll();
 }
Пример #10
0
 public void TearDown()
 {
     WebDriverUtil.Close();
 }
 public void BeforeSuite()
 {
     driver = WebDriverUtil.GetDriver();
 }
Пример #12
0
        protected override Page DowloadContent(Request request, ISpider spider)
        {
            Site site = spider.Site;

            try
            {
                lock (this)
                {
                    if (_webDriver == null)
                    {
                        _webDriver = WebDriverUtil.Open(Browser.Chrome, _option);
                    }
                    if (!_isLogined && Login != null)
                    {
                        _isLogined = Login.Invoke(_webDriver as RemoteWebDriver);
                        if (!_isLogined)
                        {
                            throw new SpiderException("Login failed. Please check your login codes.");
                        }
                    }

                    //中文乱码URL
                    Uri    uri     = request.Url;
                    string query   = uri.Query;
                    string realUrl = uri.Scheme + "://" + uri.DnsSafeHost + ":" + uri.Port + uri.AbsolutePath + (string.IsNullOrEmpty(query) ? "" : ("?" + HttpUtility.UrlPathEncode(uri.Query.Substring(1, uri.Query.Length - 1))));

                    if (UrlFormat != null)
                    {
                        realUrl = UrlFormat(realUrl);
                    }

                    NetworkCenter.Current.Execute("fid-d", () =>
                    {
                        _webDriver.Navigate().GoToUrl(realUrl);
                    });

                    Thread.Sleep(_webDriverWaitTime);

                    AfterNavigate?.Invoke((RemoteWebDriver)_webDriver);

                    Page page = new Page(request, spider.Site.ContentType, site.RemoveOutboundLinks ? site.Domains : null);
                    page.Content = _fiddlerClient.ResponseBodyString;
                    _fiddlerClient.Clear();
                    page.TargetUrl = _webDriver.Url;
                    page.Title     = _webDriver.Title;
                    // 结束后要置空, 这个值存到Redis会导置无限循环跑单个任务
                    request.PutExtra(Request.CycleTriedTimes, null);

                    return(page);
                }
            }
            catch (DownloadException)
            {
                throw;
            }
            catch (Exception e)
            {
                Page page = new Page(request, site.ContentType, null)
                {
                    Exception = e
                };
                return(page);
            }
        }
Пример #13
0
 public void EnterMessage(string messageText)
 {
     WebDriverUtil.SwtichToFrame(0);
     MessageTextField.SendText(messageText);
     WebDriverUtil.SwtichToDefaultContent();
 }
Пример #14
0
 public string GetPageTitle()
 {
     return(WebDriverUtil.GetWebDriver().Title);
 }
Пример #15
0
 public void ClickBack(string parentWindowHandle)
 {
     WebDriverUtil.SwitchToParentWindow(parentWindowHandle);
     elementUtils.ClickElement(DocumentIntakeDetailsPage.Back);
 }
Пример #16
0
 public void ClickOnReportByName()
 {
     WebDriverUtil.SwitchToChildWindow(ReportTreePage.ReportName);
 }
Пример #17
0
 public void WhenIToggleMessageFlag()
 {
     messagePage.FlagMessage(0);
     WebDriverUtil.Refresh();
 }
Пример #18
0
 public void WhenINavigateToSentMessagesFolder()
 {
     sendMessagePage.SentMessagesButtonClick();
     WebDriverUtil.Refresh();
 }
Пример #19
0
 public SendLetterPage()
 {
     PageFactory.InitElements(WebDriverUtil.GetWebDriver(), this);
 }
Пример #20
0
 public virtual void TearDown()
 {
     WebDriverUtil.DisposeDriver();
 }
        public string GetPageTitle()
        {
            var title = (string)WebDriverUtil.Execute("return document.title");

            return(title);
        }
Пример #22
0
        /// <summary>
        /// 下载工作的具体实现
        /// </summary>
        /// <param name="request">请求信息</param>
        /// <param name="spider">爬虫</param>
        /// <returns>页面数据</returns>
        protected override Task <Page> DowloadContent(Request request, ISpider spider)
        {
            Site site = spider.Site;

            try
            {
                lock (_locker)
                {
                    if (_webDriver == null)
                    {
                        _webDriver = WebDriverUtil.Open(_browser, _option);

                        if (_domains != null)
                        {
                            foreach (var domain in _domains)
                            {
                                var cookies = CookieContainer.GetCookies(new Uri(domain));
                                foreach (System.Net.Cookie cookie in cookies)
                                {
                                    AddCookieToDownloadClient(cookie);
                                }
                            }
                        }

                        if (!_isLogined && CookieInjector != null)
                        {
                            var webdriverLoginHandler = CookieInjector as WebDriverLoginHandler;
                            if (webdriverLoginHandler != null)
                            {
                                webdriverLoginHandler.Driver = _webDriver as RemoteWebDriver;
                            }
                            CookieInjector.Inject(this, spider);
                            _isLogined = true;
                        }
                    }
                }

                //#if NET_CORE
                //				string query = string.IsNullOrEmpty(uri.Query) ? "" : $"?{WebUtility.UrlEncode(uri.Query.Substring(1, uri.Query.Length - 1))}";
                //#else
                //				string query = string.IsNullOrEmpty(uri.Query) ? "" : $"?{HttpUtility.UrlPathEncode(uri.Query.Substring(1, uri.Query.Length - 1))}";
                //#endif
                //				string realUrl = $"{uri.Scheme}://{uri.DnsSafeHost}{(uri.Port == 80 ? "" : ":" + uri.Port)}{uri.AbsolutePath}{query}";

                var domainUrl = $"{request.Uri.Scheme}://{request.Uri.DnsSafeHost}{(request.Uri.Port == 80 ? "" : ":" + request.Uri.Port)}";

                string realUrl = request.Url.ToString();

                NetworkCenter.Current.Execute("webdriver-download", () =>
                {
                    _webDriver.Navigate().GoToUrl(realUrl);

                    if (WebDriverHandlers != null)
                    {
                        foreach (var handler in WebDriverHandlers)
                        {
                            handler.Handle((RemoteWebDriver)_webDriver);
                        }
                    }
                });

                Thread.Sleep(_webDriverWaitTime);

                Page page = new Page(request)
                {
                    Content   = _webDriver.PageSource,
                    TargetUrl = _webDriver.Url
                };

                return(Task.FromResult(page));
            }
            catch (DownloadException de)
            {
                Page page = new Page(request)
                {
                    Exception = de
                };
                if (site.CycleRetryTimes > 0)
                {
                    page = site.AddToCycleRetry(request);
                }
                spider.Logger.Error($"下载 {request.Url} 失败: {de.Message}.");
                return(Task.FromResult(page));
            }
            catch (Exception e)
            {
                spider.Logger.Error($"下载 {request.Url} 失败: {e.Message}.");
                Page page = new Page(request)
                {
                    Exception = e
                };
                return(Task.FromResult(page));
            }
        }
Пример #23
0
 public void GoToHomeWithWindowHandle(string parentWindowHandle)
 {
     WebDriverUtil.SwitchToParentWindow(parentWindowHandle);
     elementUtils.ClickElement(HomePage.Home);
 }
Пример #24
0
 public virtual void SetUp()
 {
     WebDriverUtil.GetInstance().Manage().Window.Maximize();
 }
Пример #25
0
 public MessagePage()
 {
     PageFactory.InitElements(WebDriverUtil.GetInstance(), this);
 }
Пример #26
0
        public void TestDeterminationNoticeData(string testdata, string createType, string docId, string docType, string classType, string searchString, string taxType, string taxID, string firstName, string middleName, string lastName, string suffix, string businessName, string addressType, string address1, string address2, string city, string state, string zipCode, string emailAddress, string confirmEmail, string homePhone, string mobile, string mobileProvider, string commPref, string repClaimant, string repReasonType, string repRelation, string repTaxType, string repTaxID, string repFN, string repMN, string repLN, string repSuffix, string lawFirmYN, string lawFirmName, string cropreport13to17, string cropreportplan, string cropinsurance, string landlordinterest, string nonfsaynid, string f13, string f14, string f15, string f16, string f17, string vipteraYN, string sign)
        {
            string cid = null;
            string parentWindowHandle = null;

            ReActions.GoToDocCat();
            switch (createType)
            {
            case "GetNext":
                ReActions.ClickOnGetNext();
                break;

            case "DocID":
                ReActions.ClickOnDocLink(docId);
                break;
            }
            ReActions.AddNewClaimForm(docType, classType, searchString);
            parentWindowHandle = WebDriverUtil.GetParentWindowHandle();
            ReActions.SwitchToIFrame();
            ReActions.SetClaimantInfo(taxType, taxID, firstName, middleName, lastName, suffix, businessName, addressType, address1, address2, city, state, zipCode, emailAddress, confirmEmail, homePhone, mobile, mobileProvider, commPref);
            ReActions.SetRepClaimant(repClaimant);
            ReActions.ClickPage1Next();
            cid = ReActions.SaveGenClaimantId();
            ReActions.ClickPage2Next();
            ReActions.CheckRepClaimant(repClaimant, repReasonType, repRelation, repTaxType, repTaxID, repFN, repMN, repLN, repSuffix);
            ReActions.SetLawFirm(lawFirmYN, lawFirmName);
            ReActions.ClickPage3Next();
            ReActions.SetCornReportingInfo(cropreport13to17, cropreportplan, cropinsurance, landlordinterest);
            ReActions.ClickPage4Next();
            if (nonfsaynid.Equals("Y"))
            {
                List <TestCaseData> nonFSAData = ExcelColumnReader.GetAncillaryData(@"\NewClaimantPL.xlsx", "NonFSA", testdata);
                if (nonFSAData != null)
                {
                    foreach (TestCaseData currNonFSA in nonFSAData)
                    {
                        if (classType.Equals("Producer"))
                        {
                            ReActions.SetNonFSAAcresForProducer(currNonFSA.Arguments.GetValue(1).ToString(), currNonFSA.Arguments.GetValue(2).ToString(), currNonFSA.Arguments.GetValue(3).ToString(), currNonFSA.Arguments.GetValue(4).ToString(), currNonFSA.Arguments.GetValue(5).ToString(), currNonFSA.Arguments.GetValue(6).ToString(), currNonFSA.Arguments.GetValue(11).ToString(), currNonFSA.Arguments.GetValue(10).ToString(), currNonFSA.Arguments.GetValue(12).ToString(), currNonFSA.Arguments.GetValue(13).ToString());
                        }
                        else
                        {
                            ReActions.SetNonFSAAcresForLandlord(currNonFSA.Arguments.GetValue(1).ToString(), currNonFSA.Arguments.GetValue(2).ToString(), currNonFSA.Arguments.GetValue(3).ToString(), currNonFSA.Arguments.GetValue(4).ToString(), currNonFSA.Arguments.GetValue(5).ToString(), currNonFSA.Arguments.GetValue(7).ToString(), currNonFSA.Arguments.GetValue(8).ToString(), currNonFSA.Arguments.GetValue(9).ToString(), currNonFSA.Arguments.GetValue(11).ToString(), currNonFSA.Arguments.GetValue(10).ToString(), currNonFSA.Arguments.GetValue(12).ToString(), currNonFSA.Arguments.GetValue(13).ToString());
                        }
                    }
                }
                ReActions.ClickPage5Next();
            }
            else
            {
                ReActions.ClickPage5NextWhenNoNonFSA();
            }
            ReActions.SetFedOnFarmAndViptera(f13, f14, f15, f16, f17, vipteraYN);
            ReActions.ClickPage6Next();
            ReActions.EnterSignAndSubmitClaim(sign);
            ReActions.CheckInIntakeDocument(parentWindowHandle);
            UIActions.GoToHome();
            UtilActions.ClickUtilities();
            UtilActions.OpenBulkEventManagement();
            UtilActions.ApplyEventForAClaimant("Events", "Assign", "Name / Tax ID Confirmed", cid);
            UIActions.GoToHome();
            CSActions.ClickClaimantSearch();
            List <string> claimantLink = CSActions.SearchClaimants("ClaimantId", cid);

            CDActions.ClickClaimantID();
            CDActions.ClickEditW9Form();
            CDActions.SwitchToIFrame();
            parentWindowHandle = WebDriverUtil.GetParentWindowHandle();
            CDActions.FillW9Form("C Corporation", "Yes", "Yes", "Anusha");
            UIActions.GoToHomeWithWindowHandle(parentWindowHandle);
        }
Пример #27
0
 public LoginPage()
 {
     PageFactory.InitElements(WebDriverUtil.GetWebDriver(), this);
 }
Пример #28
0
 public void TestClass()
 {
     WebDriverUtil.InitializeBrowser(projectUrl);
     UIActions.Login(userid, password);
 }