public void CanUseComponentAndStaticContentFromExternalNuGetPackage()
        {
            var appElement = MountTestComponent <ExternalContentPackage>();

            // NuGet packages can use Blazor's JS interop features to provide
            // .NET code access to browser APIs
            var showPromptButton = appElement.FindElements(By.TagName("button")).First();

            showPromptButton.Click();

            var modal = new WebDriverWait(Browser, TimeSpan.FromSeconds(3))
                        .Until(SwitchToAlert);

            modal.SendKeys("Some value from test");
            modal.Accept();
            var promptResult = appElement.FindElement(By.TagName("strong"));

            WaitAssert.Equal("Some value from test", () => promptResult.Text);

            // NuGet packages can also embed entire Blazor components (themselves
            // authored as Razor files), including static content. The CSS value
            // here is in a .css file, so if it's correct we know that static content
            // file was loaded.
            var specialStyleDiv = appElement.FindElement(By.ClassName("special-style"));

            Assert.Equal("50px", specialStyleDiv.GetCssValue("padding"));

            // The external Blazor components are fully functional, not just static HTML
            var externalComponentButton = specialStyleDiv.FindElement(By.TagName("button"));

            Assert.Equal("Click me", externalComponentButton.Text);
            externalComponentButton.Click();
            WaitAssert.Equal("It works", () => externalComponentButton.Text);
        }
Beispiel #2
0
        public void SendKeys(string elementDescriptor, By by, string textToSend)
        {
            try
            {
                IWebElement myElement = new WebDriverWait(this.driver, TimeSpan.FromSeconds(10)).Until(driver =>
                {
                    IWebElement tempElement = this.driver.FindElement(by);
                    return((tempElement.Displayed && tempElement.Enabled) ? tempElement : null);
                });

                myElement.Clear();
                myElement.SendKeys(textToSend);
                this.driver.Report().Step(
                    description: $"Sent '{textToSend}' to element '{elementDescriptor}' located by {by}",
                    passed: true);
            }
            catch (WebDriverException)
            {
                string errorMessage = $"Error in SendKeys(): could not locate element '{elementDescriptor}' located by {by}";

                this.driver.Report().Step(
                    description: errorMessage,
                    passed: false,
                    screenshot: true);

                Assert.Fail(errorMessage);
            }
        }
Beispiel #3
0
        public void ValidaOptin(int status)
        {
            _CNH = gerador.NumeroRandomico(11);

            var abaDocumentosLocaliza = new WebDriverWait(driver, TimeSpan.FromSeconds(10)).Until(ExpectedConditions.ElementToBeClickable(abaDocumentos));

            abaDocumentosLocaliza.Click();

            driver.FindElement(txtCPF).SendKeys(CpfGerado + Keys.Tab);
            cpfComPontuacao = driver.FindElement(txtCPF).GetAttribute("value");

            if (status == 0)
            {
                var txtNrDocLocaliza = new WebDriverWait(driver, TimeSpan.FromSeconds(10)).Until(ExpectedConditions.ElementToBeClickable(txtNrDoc));
                txtNrDocLocaliza.Clear();
                txtNrDocLocaliza.SendKeys(_CNH);

                driver.FindElement(txtNrReg).SendKeys(_CNH);
                driver.FindElement(btnSalvar).Click();
            }
            else if (status == 1 || status == 2)
            {
                Thread.Sleep(5000);

                driver.SwitchTo().ParentFrame();
                driver.SwitchTo().Frame(FRAME1);

                var txtNomeLocaliza = new WebDriverWait(driver, TimeSpan.FromSeconds(10)).Until(ExpectedConditions.ElementIsVisible(txtNome));
                Assert.Contains("TESTE AUTOMACAO OPTIN", txtNomeLocaliza.GetAttribute("value"));
                Assert.Equal("(47) 99911-8329", driver.FindElement(txtTelefone).GetAttribute("value"));
                Assert.Equal(cpfComPontuacao, driver.FindElement(txtCPF).GetAttribute("value"));
            }
        }
        public void SearchWithGoogle(DesiredCapabilities dCaps)
        {
            var environment = dCaps.GetCapability("platformName") + " " + dCaps.GetCapability("browserName");

            var driver = PerfectoOpenConnection(dCaps);

            try
            {
                // Implicit wait set to zero so does not interfere with fluent waits
                driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.Zero);

                // Maximize browser window
                driver.Manage().Window.Maximize();
                Debug.WriteLine(environment + " Browser Window was maximized");

                // Search Google
                const string searchKey = "Perfecto Mobile";
                Debug.WriteLine(environment + " Search " + searchKey + " in google");
                driver.Url = "http://www.google.com";
                var element = new WebDriverWait(driver, TimeSpan.FromSeconds(30)).Until(ExpectedConditions.ElementToBeClickable(By.Name("q")));
                Debug.WriteLine(environment + " Enter " + searchKey);
                element.SendKeys(searchKey);
                Debug.WriteLine(environment + " submit");
                element.Submit();

                new WebDriverWait(driver, TimeSpan.FromSeconds(30)).Until(d => d.Title.StartsWith(searchKey, StringComparison.CurrentCultureIgnoreCase));
                Debug.WriteLine(environment + " Got " + searchKey + " results");
            }
            finally
            {
                driver.PerfectoCloseConnectionGetReports();
            }
        }
Beispiel #5
0
        public void RunGoogleSearch(string url)
        {
            // Navigate to Google
            _log.LogInformation("Opening Google...");
            _chromeDriver.Navigate().GoToUrl(url);
            int timeoutSeconds = 60;

            string query = _searchHelper.GetRandomSearch();

            // Create new wait timer and set it to 10 seconds
            var wait = new WebDriverWait(_chromeDriver, TimeSpan.FromSeconds(timeoutSeconds));

            _log.LogInformation("Waiting for search page to load...");
            _log.LogInformation($"Searching for phrase '{query}'");
            wait.Until(SeleniumExtras.WaitHelpers.ExpectedConditions.ElementIsVisible(By.Name("q"))).SendKeys(query);

            // Wait until Google Search button is visible
            _log.LogInformation("Waiting for search button to become visible...");
            IWebElement searchButton = new WebDriverWait(_chromeDriver, TimeSpan.FromSeconds(timeoutSeconds)).Until(SeleniumExtras.WaitHelpers.ExpectedConditions.ElementToBeClickable(By.Name("q")));

            _log.LogInformation("Clicking search button...");
            searchButton.SendKeys(Keys.Enter);

            // Wait until search results stats appear which confirms that the search finished
            _log.LogInformation("Waiting for result stats...");
            wait.Until(SeleniumExtras.WaitHelpers.ExpectedConditions.ElementIsVisible(By.Id("result-stats")));

            // Find result stats and assign to variable name resultStats
            var resultStats = _chromeDriver.FindElement(By.Id("result-stats"));

            // Find a search result in the list
            var results = _chromeDriver.FindElements(By.ClassName("g"));

            int page = 1;

            while (!EvaluateResults("Google", query, page, results) && _googleResultsPage <= 10)
            {
                // Get the next page of the results
                IWebElement nextLink = _chromeDriver.FindElement(By.Id("pnnext"));
                _googleResultsPage++;

                _log.LogInformation("Clicking through the next page...");
                nextLink.Click();

                // Wait until search results stats appear which confirms that the search finished
                _log.LogInformation("Waiting for result stats...");
                wait.Until(SeleniumExtras.WaitHelpers.ExpectedConditions.ElementIsVisible(By.Id("result-stats")));

                // Find a search result in the list
                results = _chromeDriver.FindElements(By.ClassName("g"));
            }

            if (_googleResultsPage > 10)
            {
                // We didn't find a match in the first 10 pages
                // Log the stat for further action later
                LogStats("Google", query, -1, -1);
            }
        }
Beispiel #6
0
        public void TestCase()
        {
            Console.WriteLine("1. tekan tombol login google");
            HomePage home = new HomePage(driver);

            home.click();
            var parentWindow = driver.CurrentWindowHandle;
            var googletab    = driver.WindowHandles;

            foreach (var next_tab in googletab)
            {
                if (next_tab != parentWindow)
                {
                    Console.WriteLine("2. Isi email dan password");
                    driver.SwitchTo().Window(next_tab);
                    WebDriverWait wait2 = new WebDriverWait(driver, TimeSpan.FromSeconds(30000));
                    wait2.Until(ExpectedConditions.ElementToBeClickable(By.CssSelector("input[name='identifier'][type='email']"))).SendKeys("*****@*****.**");
                    var next = driver.FindElement(By.Id("identifierNext"));
                    next.Click();

                    var pass = new WebDriverWait(driver, TimeSpan.FromSeconds(30000)).Until(ExpectedConditions.ElementToBeClickable((By.CssSelector("input[name='password'][type='password']"))));
                    pass.SendKeys("7471063kartika");
                    next = driver.FindElement(By.Id("passwordNext"));
                    next.Click();
                }
            }


            driver.SwitchTo().Window(parentWindow);
            home = new HomePage(driver);
            var username = home.username();

            Assert.That(username, Is.Not.Empty, "user berhasil login");

            Console.WriteLine("3. Klik satu berita trending");
            home.FirstTendingClick();

            DetailPage detail = new DetailPage(driver);
            var        title  = detail.titleNews();

            Assert.That(title, Is.Not.Empty, "halaman detail berita berhasil terbuka");

            Console.WriteLine("4. Isi kolum komentar ");
            Console.WriteLine("5. Cek Tombol posting  ");
            detail.clickcomment();
            detail.Writecomment("tested");
            var isBtnEnable = detail.IsbtnCommentEnable();

            Assert.That(isBtnEnable, Is.True, "Tombol posting enabled ");

            Console.WriteLine("6. Kosongkan kolum komentar ");
            Console.WriteLine("7. Cek tombol posting ");
            detail = new DetailPage(driver);
            detail.clickcomment();
            detail.Deletecomment();
            isBtnEnable = detail.IsbtnCommentEnable();
            Assert.That(isBtnEnable, Is.False, "Tombol posting disabled ");
        }
        public void CreateContact_AllFields_Success()
        {
            IWebDriver driver = new ChromeDriver();

            try
            {
                driver.Navigate().GoToUrl("http://93.174.133.33/");

                new WebDriverWait(driver, TimeSpan.FromSeconds(1))
                .Until(ExpectedConditions.ElementExists(By.CssSelector("div.list-data")));

                driver.FindElement(By.ClassName("js-create")).Click();

                IWebElement firstName = new WebDriverWait(driver, TimeSpan.FromSeconds(1))
                                        .Until(ExpectedConditions.ElementExists(By.Id("FirstName")));

                // Test data
                firstName.SendKeys("Name");
                driver.FindElement(By.Id("SecondName")).SendKeys("Secondname");
                string expectedSureName = Guid.NewGuid().ToString(); //Id for future search in the grid
                driver.FindElement(By.Id("SureName")).SendKeys(expectedSureName);
                driver.FindElement(By.Id("PhoneStringValue")).SendKeys("8(822)6111111");
                driver.FindElement(By.Id("Email")).SendKeys("*****@*****.**");

                driver.FindElement(By.ClassName("js-save")).Click();

                new WebDriverWait(driver, TimeSpan.FromSeconds(1))
                .Until(ExpectedConditions.InvisibilityOfElementLocated(By.CssSelector("div.form-item")));

                var elements = driver.FindElements(By.XPath(string.Format("//div[contains(text(),'{0}')]", expectedSureName)));

                Assert.AreEqual(elements.Count, 1);
            }
            catch (Exception ex)
            {
                var screenshotFolder = "C:/Temp/TestOuput/";
                Directory.CreateDirectory(screenshotFolder);
                var screenshotPath = screenshotFolder + String.Format(DateTime.Now.ToString("HHmmss")) + ".png";
                var screenShot     = ((ITakesScreenshot)driver).GetScreenshot();

                screenShot.SaveAsFile(screenshotPath, ScreenshotImageFormat.Png);

                throw;
            }
            finally
            {
                driver.Quit();
            }
        }
        public static void SendedToField(IWebDriver driver, By to, string inputText)
        {
            var inputElement = new WebDriverWait(driver, TimeSpan.FromSeconds(4)).
                               Until(SeleniumExtras.WaitHelpers.ExpectedConditions.ElementIsVisible(to));

            new WebDriverWait(driver, TimeSpan.FromSeconds(5))
            .Until <IWebElement>((d) =>
            {
                inputElement.Clear();
                inputElement.SendKeys(inputText);

                if (inputElement.GetAttribute("value").Equals(inputText, StringComparison.Ordinal))
                {
                    return(inputElement);
                }

                return(null);
            });
        }
Beispiel #9
0
    public static IWebElement FillWebElement(this IWebDriver d, string xPath, string text, int delay = 5)
    {
        IWebElement el = null;

        try
        {
            el = new WebDriverWait(d, TimeSpan.FromSeconds(delay)).Until(SeleniumExtras.WaitHelpers.ExpectedConditions.ElementExists(By.XPath(xPath)));
            el = d.FindElement(By.XPath(xPath));
        }
        catch (Exception e)
        {
            if (e.Message != "")
            {
                el = null;
            }
        }
        if (el != null)
        {
            el.SendKeys(text);
        }
        return(el);
    }
Beispiel #10
0
        static IWebDriver LoginMailRu(string login, string password)//method for login in mail.ru account, returns ChromeDriver after login
        {
            string mailruURL = "https://mail.ru/";

            string idOfLoginField    = "mailbox:login";
            string idOfPasswordField = "mailbox:password";

            int timeoutInSeconds = 5;

            IWebDriver chromeDriver = new ChromeDriver();

            chromeDriver.Navigate().GoToUrl(mailruURL);

            IWebElement loginField = new WebDriverWait(chromeDriver, TimeSpan.FromSeconds(timeoutInSeconds)).Until(ExpectedConditions.ElementIsVisible(By.Id(idOfLoginField)));

            loginField.SendKeys(login + Keys.Enter);

            IWebElement passwordField = new WebDriverWait(chromeDriver, TimeSpan.FromSeconds(timeoutInSeconds)).Until(ExpectedConditions.ElementIsVisible(By.Id(idOfPasswordField)));

            passwordField.SendKeys(password + Keys.Enter);

            return(chromeDriver);
        }
Beispiel #11
0
        public void CadastroMotoristaCompleto()
        {
            _RG  = gerador.NumeroRandomico(9);
            _CNH = gerador.NumeroRandomico(11);

            //Espera localizar o campo e logo em seguida começa o cadastro de motorista
            var rgLocaliza = new WebDriverWait(driver, TimeSpan.FromSeconds(10)).Until(ExpectedConditions.ElementToBeClickable(txtRG));

            Assert.Equal(null, rgLocaliza.GetAttribute("disabled"));
            rgLocaliza.SendKeys(_RG);

            //driver.FindElement(txtRG).SendKeys(rg);
            driver.FindElement(cmbOrgaoExp).SendKeys("ssp" + Keys.Tab);
            driver.FindElement(edtDataEmissao).SendKeys("10/03/2008");
            driver.FindElement(cmbVinculo).SendKeys("AGREGADO" + Keys.Tab);

            driver.FindElement(txtNrDoc).SendKeys(_CNH);
            driver.FindElement(txtNrReg).SendKeys(_CNH);
            driver.FindElement(cmbUF).SendKeys("RS" + Keys.Tab);
            driver.FindElement(edtEmissaoHab).SendKeys("10/03/2008");
            driver.FindElement(edtVencimentoHab).SendKeys("21/09/2030");
            driver.FindElement(cmbCategoria).SendKeys("AE" + Keys.Tab);

            driver.FindElement(abaReferencias).Click();

            for (int i = 0; i < 3; i++)
            {
                if (i == 0)
                {
                    driver.FindElement(txtNomeReferencia).SendKeys("MAE Referencia");
                    driver.FindElement(cmbTipoRelacionamento).SendKeys("MAE" + Keys.Tab);
                }
                if (i == 1)
                {
                    driver.FindElement(txtNomeReferencia).SendKeys("PAI Referencia");
                    driver.FindElement(cmbTipoRelacionamento).SendKeys("PAI" + Keys.Tab);
                }
                if (i == 2)
                {
                    driver.FindElement(txtNomeReferencia).SendKeys("AVO Referencia");
                    driver.FindElement(cmbTipoRelacionamento).SendKeys("AVO" + Keys.Tab);
                }
                driver.FindElement(txtCidRef).SendKeys("PORTO ALEGRE/R");
                driver.FindElement(txtCidRef).SendKeys("S");
                driver.FindElement(selecCidRef).Click();
                driver.FindElement(txtDDDFone1).SendKeys("51");

                string numeroRandomico = gerador.NumeroRandomico(9);
                driver.FindElement(txtTelefoneReferencia).SendKeys(numeroRandomico);

                driver.FindElement(btnAddReferencia).Click();
            }

            driver.FindElement(abaDadosPessoais).Click();
            driver.FindElement(txtNome).SendKeys("Teste Nome da Silva");
            driver.FindElement(txtNat).SendKeys("PORTO ALEGRE/RS");
            driver.FindElement(selecNat).Click();
            driver.FindElement(txtNascimento).SendKeys("18/03/1993" + Keys.Tab);
            driver.FindElement(cmbSexo).SendKeys("Mas" + Keys.Tab);
            driver.FindElement(txtPai).SendKeys("Teste PAI da Silva");
            driver.FindElement(txtMae).SendKeys("Teste MAE da Silva");

            driver.FindElement(txtLogradouro).SendKeys("RUA JULIA DIB");
            driver.FindElement(txtNumero).SendKeys("1598");
            driver.FindElement(txtBairro).SendKeys("SANTA ROSA");
            driver.FindElement(txtCidade).SendKeys("PORTO ALEGRE/RS");
            driver.FindElement(selecCidadeEndereco).Click();
            driver.FindElement(txtDDDFixo).SendKeys("51");
            driver.FindElement(txtTelefone).SendKeys("33672524");

            driver.FindElement(btnSalvar).Click();

            var btnEnviarPesquisaLocaliza = new WebDriverWait(driver, TimeSpan.FromSeconds(10)).Until(ExpectedConditions.ElementToBeClickable(btnEnviarPesquisa));

            btnEnviarPesquisaLocaliza.Click();

            var btnFecharAlertaLocaliza = new WebDriverWait(driver, TimeSpan.FromSeconds(10)).Until(ExpectedConditions.ElementToBeClickable(By.XPath("/html/body/div[3]/div[3]/div/button/span")));

            btnFecharAlertaLocaliza.Click();
        }
Beispiel #12
0
        public Location GetLocation(string urlRe, string province, string district, string pacelNo)
        {
            var result = new Location();
            var parcel = 0;

            if (string.IsNullOrEmpty(province) || string.IsNullOrEmpty(district) || string.IsNullOrEmpty(pacelNo))
            {
                return result;
            }

            if (pacelNo.Contains("-"))
            {
                var stat = int.TryParse(pacelNo.Split('-')[0], out parcel);
                if (!stat)
                    return result;
            }
            else
            {
                var stat = int.TryParse(pacelNo, out parcel);
                if (!stat)
                    return result;
            }

            var loc = DataHelper.GetLocation(province, district, parcel);
            if (loc != null)
            {
                return loc;
            }

            string driverPath = @"D:\MyProjects\FRES\src\FRES.Source.Map\Drivers\";
            IWebDriver driver = new OpenQA.Selenium.PhantomJS.PhantomJSDriver(driverPath);
            //IWebDriver driver = new OpenQA.Selenium.Chrome.ChromeDriver(driverPath);
            try
            {
                var url = "http://dolwms.dol.go.th/tvwebp/";
                driver.Navigate().GoToUrl(url);
                var wait = new WebDriverWait(driver, TimeSpan.FromSeconds(TIMEOUT));

                Thread.Sleep(DELAY);

                var ddlProvince = driver.FindSelectElementWhenPopulated(By.Name("ddlProvince"), TIMEOUT);
                ddlProvince.SelectBySubText(province);

                Thread.Sleep(DELAY);

                var ddlAmphur = driver.FindSelectElementWhenPopulated(By.Name("ddlAmphur"), TIMEOUT);
                ddlAmphur.SelectBySubText(district);

                Thread.Sleep(DELAY);

                var txtPacelNo = new WebDriverWait(driver, TimeSpan.FromSeconds(TIMEOUT)).Until(ExpectedConditions.ElementExists(By.Name("txtPacelNo")));
                txtPacelNo.SendKeys(pacelNo);

                Thread.Sleep(DELAY);

                var btnFind = driver.FindElement(By.Name("btnFind"));
                IJavaScriptExecutor js = driver as IJavaScriptExecutor;
                js.ExecuteScript("arguments[0].click();", btnFind);

                Thread.Sleep(DELAY);
                //var element = new WebDriverWait(driver, TimeSpan.FromSeconds(3)).Until(ExpectedConditions.TextToBePresentInElement(driver.FindElement(By.Id("ddlAmphur")), "01"));
                //wait.Until(ExpectedConditions.ElementExists(By.CssSelector("div[style=\"transform: translateZ(0px); position: absolute; left: 0px; top: 0px; z-index: 107; width: 100%;\"]")));

                var isExist = wait.Until((d) => { return driver.PageSource.Contains("createMarker( new Array("); });

                if (isExist)
                {
                    var html = driver.PageSource;
                    html = GetStrBtw(html, "createMarker( new Array(", "));");//.Replace("'", string.Empty);
                    var dtls = html.Split(',').Select(x => x.Replace("'", "")).ToArray();
                    result = new Location
                    {
                        Amphur = district,
                        Province = province,
                        ParcelCode = parcel,
                        Lat = double.Parse(dtls[7]),
                        Lon = double.Parse(dtls[8])
                    };

                    DataHelper.InsertLocation(result);
                }
                else
                {
                    throw new Exception("Can't find location");
                }
            }
            catch (Exception ex)
            {
                lock (sync)
                    File.AppendAllText("D:/RE/M.log", DateTime.Now.ToString("yyyyMMdd HH:mm") + "," + province + "," + district + "," + parcel + "," + urlRe + "," + ex.GetBaseException().Message + "\r\n");
            }
            finally
            {
                //Thread.Sleep(3000);
                driver.Close();
                driver.Quit();
                driver.Dispose();
            }
            return result;
        }