Beispiel #1
0
        /// <summary>
        /// stop the selenium thread
        /// </summary>
        private void StopThread(bool killAll = false)
        {
            updated        = false;
            canGetVoice    = false;
            refreshVoice   = false;
            refreshServers = false;
            threadEnabled  = false;
            seleniumOpen   = false;
            driver?.Close();
            driver?.Quit();
            driver = null;
            thread?.Abort();

            // this will kill all selenium processes //
            if (killAll)
            {
                Process[] chromeDriverProcesses = Process.GetProcessesByName("chromedriver");

                foreach (var chromeDriverProcess in chromeDriverProcesses)
                {
                    chromeDriverProcess.Kill();
                }

                // Process[] chromiumHosts =  Process.GetProcessesByName("Chromium host executable (32 bit)");

                // foreach(var chromeHost in chromiumHosts)
                // {
                //     chromeHost.Kill();
                // }
            }
        }
 public void Dispose()
 {
     _driver?.Close();
     _driver?.Dispose();
     _token?.Cancel();
     _task?.Wait();
     _task?.Dispose();
 }
Beispiel #3
0
        public void Dispose()
        {
            if (_driver != null)
            {
                var screenshot = _driver.GetScreenshot();
                screenshot.SaveAsFile("last-view.png");
                _logger.LogInformation($"Last page url: {_driver.Url}");
            }

            _driver?.Close();
            _driver?.Dispose();
        }
Beispiel #4
0
        private static void Main()
        {
            Logger.Info("> Main()");
            var appDomain = AppDomain.CurrentDomain;

            appDomain.UnhandledException += AppDomain_UnhandledException;

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            splashTimer = new Timer
            {
                Interval = 500
            };
            splashTimer.Tick += SplashTimer_TickAsync;
            splashTimer.Start();
            splash = new SplashScreen();
            splash.ShowDialog();
            Application.Run(container.GetInstance <FormMain>());

            driver?.Close();
            driver?.Quit();
            Logger.Info("< Main()");
        }
        public void CoreObject_Demo1()
        {
            _output.WriteLine("Step 01 : 启动浏览器并打开博客园首页。");
            IWebDriver driver = new ChromeDriver();

            driver.Url = "http://www.cnblogs.com";
            driver.Manage().Window.Maximize();

            _output.WriteLine("Step 02 : 获取并输出部分页面信息。");
            _output.WriteLine(string.Format("Current window handle: {0}", driver.CurrentWindowHandle));
            _output.WriteLine(string.Format("Window handle count: {0}", driver.WindowHandles.Count));
            _output.WriteLine(string.Format("Current window title: {0}", driver.Title));

            _output.WriteLine("Step 03 : 验证博客园站点的 Title 是否正确。");
            Assert.Equal <string>("博客园 - 开发者的网上家园", driver.Title);

            _output.WriteLine("Step 04 : 关闭当前页面。");
            driver.Close();
        }
Beispiel #6
0
        public void TestMethod5()
        {
            IWebDriver driver = new ChromeDriver();

            driver.Navigate().GoToUrl("http://automationpractice.com");
            driver.FindElement(By.XPath("//*[@id='homefeatured']/li[1]/div/div[2]/div[2]/a[1]/span")).Click(); //Adding first item into cart.
            driver.Navigate().GoToUrl("http://automationpractice.com");
            driver.FindElement(By.XPath("//*[@id='homefeatured']/li[2]/div/div[2]/div[2]/a[1]/span")).Click(); //Adding second item into cart.
            driver.Navigate().GoToUrl("http://automationpractice.com");
            driver.FindElement(By.XPath("//*[@id='homefeatured']/li[3]/div/div[2]/div[2]/a[1]/span")).Click(); //Adding third item into cart.
            driver.Navigate().GoToUrl("http://automationpractice.com/index.php?controller=order");

            IWebElement resultText = driver.FindElement(By.XPath("//*[@id='total_price_container']"));
            string      actual     = (resultText.Text);
            string      expected   = "$71.51";

            Assert.AreEqual(actual, expected, "Incorrect result for the Total for 3 items in cart");
            driver.Close();
        }
Beispiel #7
0
        static void Main(string[] args)
        {
            IWebDriver driver = new ChromeDriver();

            driver.Navigate().GoToUrl("https://www.google.com");
            driver.FindElement(By.Name("q")).SendKeys("Computer");
            driver.FindElement(By.Name("q")).SendKeys(Keys.Enter);
            bool isPresent = driver.PageSource.Contains("head");

            if (isPresent)
            {
                Console.WriteLine("TEST PASSED");
            }
            else
            {
                Console.WriteLine("TEST FAILED");
            }
            driver.Close();
        }
Beispiel #8
0
        public void entrarTemas()
        {
            var chromeDriver = new ChromeDriver();

            chromeDriver.Url = "http://localhost:58972/Usuario/Login";

            chromeDriver.FindElementById("btnIniciarSesion").Click();
            Thread.Sleep(TimeSpan.FromSeconds(2));

            chromeDriver.FindElementById("temaLink").Click();
            Thread.Sleep(TimeSpan.FromSeconds(2));

            var paginaSiguiente = chromeDriver.FindElementById("pagTemas");

            Assert.IsNotNull(paginaSiguiente);

            Thread.Sleep(TimeSpan.FromSeconds(2));
            chromeDriver.Close();
        }
Beispiel #9
0
        public void Execute(object parameter)
        {
            _driverService = ChromeDriverService.CreateDefaultService();
            _driverService.HideCommandPromptWindow = true;
            _options = new ChromeOptions();
            _options.AddArgument("headless");
            _options.AddArgument("disable-gpu");
            _driver = new ChromeDriver(_driverService, _options);

            _driver.Navigate().GoToUrl("https://ieilms.jbnu.ac.kr/");             // 웹 사이트에 접속합니다.

            _driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(10);

            var parameters = (object[])parameter;

            IWebElement element;

            try
            {
                element = _driver.FindElementByXPath("//*[@id='id']");
                element.SendKeys((string)parameters[0]);
                VM.LoginModel.LoginID = ((string)parameters[0]);

                element = _driver.FindElementByXPath("//*[@id='passwd']");
                element.SendKeys((string)parameters[1]);
                VM.LoginModel.LoginPasswd = ((string)parameters[1]);

                element = _driver.FindElementByXPath("//*[@id='loginform']/table/tbody/tr[1]/td[2]/input");
                element.Click();

                element = _driver.FindElementByXPath("//*[@id='nav']/li[10]/a");
                element.Click();

                MessageBox.Show("로그인 성공! 원하는 메뉴를 클릭해주세요");

                _driver.Close();
            }
            catch (Exception)
            {
                MessageBox.Show("ID,PW를 확인해주세요.");
                return;
            }
        }
        public void errorPagination()
        {
            IWebDriver driver = new ChromeDriver();

            driver.Navigate().GoToUrl("http://localhost:54467/#/home");
            driver.Manage().Window.Maximize();
            driver.FindElement(By.Id("paginationId")).Clear();
            driver.FindElement(By.Id("paginationId")).SendKeys("-1");
            driver.FindElement(By.Id("SearchTextBox")).Click();
            Thread.Sleep(3000);
            Thread.Sleep(3000);
            var info = driver.FindElement(By.Id("info")).Text;

            Thread.Sleep(3000);
            Assert.IsTrue(info.Contains("All\r\nElectronic\r\nFashion\r\nSports\r\nAccessories\r\nOffice\r\nMusic, Movies and Series\r\nSearch\r\nProduct amount per page\r\n\r\nMSI Gaming ProductModified 8RE-021XES Raider RGB Negro Portátil 39.6 cm (15.6 ) 1920 x 1080 Pixeles 2.20 GHz 8ª generación de procesadores Intel® Core™ i7 i7-8750H - Ordenador portátil(8ª generación de procesadores Intel® Core™ i7, 2.20 GHz, 39.6 cm 15.6 , 1920 x 1080 Pixeles, 16 GB, 1256 GB)\r\naJonathan Rdodríguez\r\nElectronic1\r\nDetails\r\nOrder Now\r\nCost: 33\r\nOld Cost:33\r\nMSI Gaming ProductModified 8RE-021XES Raider RGB Negro Portátil 39.6 cm (15.6 ) 1920 x 1080 Pixeles 2.20 GHz 8ª generación de procesadores Intel® Core™ i7 i7-8750H - Ordenador portátil(8ª generación de procesadores Intel® Core™ i7, 2.20 GHz, 39.6 cm 15.6 , 1920 x 1080 Pixeles, 16 GB, 1256 GB)\r\naJonathan Rdodríguez\r\nElectronic1\r\nDetails\r\nOrder Now\r\nCost: 33\r\nOld Cost:33\r\nMSI Gaming ProductModified 8RE-021XES Raider RGB Negro Portátil 39.6 cm (15.6 ) 1920 x 1080 Pixeles 2.20 GHz 8ª generación de procesadores Intel® Core™ i7 i7-8750H - Ordenador portátil(8ª generación de procesadores Intel® Core™ i7, 2.20 GHz, 39.6 cm 15.6 , 1920 x 1080 Pixeles, 16 GB, 1256 GB)\r\naJonathan Rdodríguez\r\nElectronic1\r\nDetails\r\nOrder Now\r\nCost: 33\r\nOld Cost:33\r\nhi\r\naJonathan Rodríguez\r\nElectronic1\r\nDetails\r\nOrder Now\r\nCost: 33\r\nOld Cost:33"));
            driver.Navigate().GoToUrl("http://localhost:54467/#/home");
            driver.Close();
            driver.Quit();
        }
        public void UseCasesTopButton()
        {
            IWebDriver driver;

            driver = new ChromeDriver(@"C:\Users\bogda\source\repos\SeleniumTests\SeleniumTests\Resurse\");

            driver.Navigate().GoToUrl(@"https://betatesting.com/");

            //Marim fereastra
            driver.Manage().Window.Maximize();
            IWebElement UseCasesButton = driver.FindElement(By.CssSelector("#useCasesMenu > a"));

            UseCasesButton.Click();
            Thread.Sleep(2000);
            string totTextulDePePagina = driver.PageSource;

            Assert.IsTrue(totTextulDePePagina.Contains("Explore how you can use BetaTesting to improve your product"));
            driver.Close();
        }
Beispiel #12
0
        [TestCaseSource("Environment")] //Recibe la lista de abajo
        public void TestCheckboxes(string url)
        {
            IWebDriver Driver = new ChromeDriver();

            Driver.Url = url;
            IWebElement checkbox1 = Driver.FindElement(By.XPath("//input[@id='checkBoxOption1']"));

            checkbox1.Click();
            IWebElement checkbox2 = Driver.FindElement(By.XPath("//input[@id='checkBoxOption2']"));

            checkbox2.Click();
            IWebElement checkbox3 = Driver.FindElement(By.XPath("//input[@id='checkBoxOption3']"));

            checkbox3.Click();
            Assert.IsTrue(checkbox1.Selected);
            Assert.IsTrue(checkbox2.Selected);
            Assert.IsTrue(checkbox3.Selected);
            Driver.Close();
        }
Beispiel #13
0
        static void Main(string[] args)
        {
            //Creating instance of chrome driver
            IWebDriver driver = new ChromeDriver();

            driver.Navigate().GoToUrl("http://horse-dev.azurewebsites.net/Account/Login");

            // login page :: Identifying and sending valid inputs
            LoginPage loginPage = new LoginPage(driver);

            loginPage.LoginSuccess();

            // Home Page - clicking on adminsitration and time n materials
            HomePage instanceName = new HomePage(driver);

            instanceName.clickAdminstration();
            instanceName.clickTimenMaterial();

            // Time & Material Page - Click on Create New record and Submit Time and Material Value.
            TimeandMaterialPage instanceNameTandM = new TimeandMaterialPage(driver);

            instanceNameTandM.Clickcreate();
            instanceNameTandM.Savebutton1();
            instanceNameTandM.Editbutoon();



            //Time and Material Page - create new and adding valid details

            //Time and Material Page  - validating the record created

            //Closing driver instance
            driver.Close();


            //IWebDriver driver1 = new ChromeDriver();
            //driver1.Navigate().GoToUrl("http://www.industryconnect.io");

            //driver1.FindElement(By.Id("Email")).SendKeys("*****@*****.**");
            //driver1.FindElement(By.Id("Password")).SendKeys("Test@123");

            //driver1.FindElement(By.XPath("//input[@class='btn btn-xl  signinbtn']")).Click();
        }
Beispiel #14
0
        public void fast_website_price_mount()
        {
            String price_main_int = "4";
            String price_main_dec = ".97";

            IWebDriver driver = new ChromeDriver();

            driver.Navigate().GoToUrl("https://fozzy.com/ua-ru/shared-hosting.shtml");

            //System.Threading.Thread.Sleep(1000);

            IWebElement element_price_main_int = driver.FindElement(By.XPath("/html/body/div[1]/div/section/div[2]/div[3]/div[1]/div/div[3]/div[1]/div/div[2]/div/div[2]/span[1]/div/span"));
            IWebElement element_price_main_dec = driver.FindElement(By.XPath("/html/body/div[1]/div/section/div[2]/div[3]/div[1]/div/div[3]/div[1]/div/div[2]/div/div[2]/span[1]/div/span/span[1]"));

            Assert.IsTrue(element_price_main_int.Text.Contains(price_main_int));
            Assert.IsTrue(element_price_main_dec.Text.Contains(price_main_dec));

            driver.Close();
        }
        public void SeleniumAPI_Demo1()
        {
            _output.WriteLine("Step 01 : 启动浏览器并打开博客园首页。");
            IWebDriver driver = new ChromeDriver();

            driver.Url = "http://www.cnblogs.com";

            _output.WriteLine("Step 02 : 寻找需要检查的页面元素。");
            var lnkHome = driver.FindElement(By.XPath(".//ul[@class='post_nav_block']/li[1]/a"));
            var value   = lnkHome.GetAttribute("class");

            lnkHome.GetCssValue("font-family");
            lnkHome.GetCssValue("color");

            _output.WriteLine(string.Format("导航内栏内容:{0}", lnkHome.Text));

            _output.WriteLine("Step 04 : 关闭浏览器。");
            driver.Close();
        }
Beispiel #16
0
        protected string GetPageSourceUsingDriver(string baseURL, string Phrase)
        {
            var chromeOptions = new ChromeOptions();

            chromeOptions.AddArguments("headless");                           // no UI
            chromeOptions.AddArguments("blink-settings=imagesEnabled=false"); // disable images download

            var browser = new ChromeDriver(chromeOptions);

            browser.Navigate().GoToUrl(string.Format(baseURL, HttpUtility.UrlEncode(Phrase)));
            var content = browser.PageSource;

            Thread.Sleep(1000); // TODO ->> replace with waitHandler

            browser.Close();
            browser.Dispose();

            return(content);
        }
Beispiel #17
0
        public void Test1()
        {
            IWebDriver driver = new ChromeDriver(@"D:\03.PROYECTOS\01.BNBPUNTOS\PROYECTO REST\DesarrolloBNB");


            driver.Navigate().GoToUrl("http://apps.supernet.bo/ic/Autentication.aspx");
            Thread.Sleep(500);
            driver.FindElement(By.Id("IFMainContent_txtLogin")).Click();
            driver.FindElement(By.Id("IFMainContent_txtLogin")).Clear();
            driver.FindElement(By.Id("IFMainContent_txtLogin")).SendKeys("*****@*****.**");
            driver.FindElement(By.Id("IFMainContent_txtPasswd")).Click();
            driver.FindElement(By.Id("IFMainContent_txtPasswd")).Clear();
            driver.FindElement(By.Id("IFMainContent_txtPasswd")).SendKeys("Daniela123*");
            driver.FindElement(By.Id("IFMainContent_btnEntrar")).Click();
            Thread.Sleep(1000);

            driver.Close();
            Assert.Pass();
        }
Beispiel #18
0
        public void VerifyValidLogin()
        {
            _testOutputHelper.WriteLine(Directory.GetCurrentDirectory());
            var driver = new ChromeDriver(Directory.GetCurrentDirectory() + "/lib");

            // Navigate to login page
            driver.Navigate().GoToUrl("http://0.0.0.0:3000");
            driver.FindElementById("link-to-login").Click();

            // Enter username & password
            driver.FindElementById("spree_user_email").SendKeys("*****@*****.**");
            driver.FindElementById("spree_user_password").SendKeys("password");
            // Click login
            driver.FindElementByName("commit").Click();
            string loginText = driver.FindElementByLinkText("My Account").GetAttribute("text");

            driver.Close();
            Assert.Equal(loginText, "My Account");
        }
Beispiel #19
0
        public void Test_Page_FindElement()
        {
            // Arrange
            ChromeDriver driver = new ChromeDriver();

            driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(5);
            Page page = new Page(driver);

            // Action
            driver.Url = "https://www.naver.com";
            var elements = driver.FindElements(By.CssSelector("input"));
            var element  = page.Find_Element(elements, "name", "query");
            var expected = "검색어 입력";
            var actual   = element.GetAttribute("title");

            // Assert
            Assert.AreEqual(expected, actual);
            driver.Close();
        }
Beispiel #20
0
        public void TestMethod9()
        {
            IWebDriver driver = new ChromeDriver();

            driver.Navigate().GoToUrl("http://172.16.51.152/ReachAcs/index");
            Task.Delay(2000).Wait();
            driver.FindElement(By.XPath("//a[contains(text(),'About Us')]"));
            Task.Delay(2000).Wait();
            driver.FindElement(By.XPath("//a[contains(text(),'Contact Us')]")).Click();
            Task.Delay(2000).Wait();
            driver.FindElement(By.XPath("//a[contains(text(),'Feedback')]")).Click();
            Task.Delay(2000).Wait();
            driver.FindElement(By.Id("btnDonate")).Click();
            Task.Delay(2000).Wait();
            driver.FindElement(By.XPath("//ul[@class='info']//a[contains(text(),'Privacy Policy')]")).Click();
            Task.Delay(2000).Wait();
            driver.Close();
            // i am not able to acess the footer items through my test case ....
        }
        public void TestMethod1()
        {
            ChromeOptions option = new ChromeOptions();

            option.AddArgument("test-type");
            string     drivePath = (@"C:\testing\chrome\");
            IWebDriver driver    = new ChromeDriver(drivePath, option);

            driver.Navigate().GoToUrl("http://www.google.com");

            var searchBox = driver.FindElement(By.Id("lst-ib"));

            searchBox.SendKeys("rick and morty");

            var searchButton = driver.FindElement(By.Name("btnG"));

            searchButton.Click();

            //if it cant find the element - wait for 10 seconds - then try again
            driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(5));

            //grabs all of the items classes with "q", selects the 1st one, then clicks it
            var imagesLink = driver.FindElements(By.ClassName("q"))[0];

            imagesLink.Click();

            var div       = driver.FindElement(By.ClassName("rg_di"));
            var photoLink = div.FindElements(By.TagName("a"))[0];

            photoLink.Click();

            //not the best way to assert whether something is present
            var text = driver.PageSource.Contains("rick");

            if (text)
            {
                driver.Close();
            }
            else
            {
                Console.WriteLine("not on page");
            }
        }
Beispiel #22
0
        public void Execute_Crawler()
        {
            Logger.Log("---CRAWLER STARTED---");

            // Initialize Chrome driver
            ChromeOptions options = new ChromeOptions();

            #if !DEBUG
            options.AddArgument("--headless");      // run Chrome in the background
            options.AddArgument("--disable-translate");
            options.AddArgument("--disable-extensions");
            options.AddArgument("--disable-gpu");
            #endif
            var driver = new ChromeDriver(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), options);

            // Initialize MongoDB driver
            var            client = new MongoClient("mongodb://localhost:27017");
            IMongoDatabase db     = client.GetDatabase("heapjob");

            // Collect the latest jobs from the site
            var listOfElements = Crawler.GetLatestJobs(driver);
            if (listOfElements.Count < 1)
            {
                Logger.Log("No Jobs were found");
                Logger.Log("---CRAWLER FINISHED---");
                return; // Exit method
            }

            // Identify new jobs
            var listOfNewJobs = Crawler.IdentifyNewJobs(listOfElements, db);

            // Retrieve the details of the new jobs
            var newJobsWithDetails = Crawler.RetrieveTheDetailsOfTheJobs(listOfNewJobs, driver);

            // Persist to MongonDB
            Crawler.PersistNewJobsToMongo(newJobsWithDetails, db);

            // Close Chrome browser and driver
            driver.Close();
            driver.Dispose();

            Logger.Log("---CRAWLER FINISHED---");
        }
Beispiel #23
0
        public void VerifySaveNavigator()
        {
            ChromeDriver driver = GetDriverConnection();
            string       url    = driver.Url;

            string folderPath = Path.GetFullPath("C:\\tmp-selenium");

            Directory.CreateDirectory(folderPath);

            ChromeOptions options = new ChromeOptions();

            options.AddUserProfilePreference("download.default_directory", folderPath);
            options.AddUserProfilePreference("disable-popup-blocking", "true");
            ChromeDriver navigator = GetNavigatorConnection(url, options);

            string      expected     = "this_is_a_save_test_navigator";
            IWebElement driverEditor = driver.FindElementById("code-editor");
            Actions     actions      = new Actions(driver);

            actions.MoveToElement(driverEditor);
            actions.Click();
            actions.SendKeys(expected);
            actions.Build().Perform();
            Task.Delay(5000).Wait();

            IWebElement navigatorDownload = navigator.FindElementByClassName("download");

            navigatorDownload.Click();
            Task.Delay(5000).Wait();

            IWebElement group    = driver.FindElementByClassName("group");
            string      groupId  = group.Text.Split(null)[2];
            string      fileName = "code-" + groupId + ".txt";

            string actual = File.ReadAllText(Path.Combine(folderPath, fileName));

            Assert.Equal(expected, actual);

            Directory.Delete(folderPath, true);

            driver.Close();
            navigator.Close();
        }
Beispiel #24
0
        public void AddCuentaCreditoIsOk()
        {
            ChromeDriver navegador = new ChromeDriver();

            navegador.Url = RutaGlobal;
            navegador.FindElementById("btnAddCuenta").Click();
            navegador.FindElementById("Nombre").SendKeys("TestCredito");
            navegador.FindElementByName("Categoria").Click();
            navegador.FindElementByName("credito").Click();
            navegador.FindElementById("SaldoInicial").SendKeys("1000");

            navegador.FindElementById("btnAddCuenta").Click();

            var pageId = navegador.FindElementById("ViewIndex");

            Assert.IsNotNull(pageId);

            navegador.Close();
        }
Beispiel #25
0
        static void GetDataFromMSN()
        {
            Console.WriteLine("*****Started MSN ......");
            IWebDriver driver = new ChromeDriver();

            using (var dbContext = new MagicDbContext())
            {
                MagicRepository repository = new MagicRepository(dbContext);
                var             stocks     = repository.GetMsnStocks();
                foreach (Stock stock in stocks)
                {
                    MsnMoney.Start(driver, stock);
                    repository.Save();
                }
            }

            driver.Close();
            driver.Quit();
        }
Beispiel #26
0
        public string Login(string email, string password)
        {
            _testOutputHelper.WriteLine(Directory.GetCurrentDirectory());
            var driver = new ChromeDriver(Directory.GetCurrentDirectory() + "/lib");

            // Navigate to login page
            driver.Navigate().GoToUrl("http://0.0.0.0:3000");
            driver.FindElementById("link-to-login").Click();

            // Enter username & password
            driver.FindElementById("spree_user_email").SendKeys(email);
            driver.FindElementById("spree_user_password").SendKeys(password);
            // Click login
            driver.FindElementByName("commit").Click();
            var text = driver.FindElementByLinkText("My Account").GetAttribute("text");

            driver.Close();
            return(text);
        }
        public void TemaCrearFormCancelarTest()
        {
            ChromeDriver navegador = new ChromeDriver();

            navegador.Url = RutaGlobal;
            navegador.FindElementById("IngresarSistemaLink").Click();
            navegador.FindElementById("temaLink").Click();
            navegador.FindElementById("creartemaLink").Click();

            navegador.FindElementById("CrearNombreTema").SendKeys("Prueba");
            navegador.FindElementById("CrearCategoriaTema").SendKeys("Historia");
            navegador.FindElementById("CrearDescripcionTema").SendKeys("Probando");
            navegador.FindElementById("CancelarCrearTemaLink").Click();

            var pageId = navegador.FindElementById("IndexTemasLink");

            Assert.IsNotNull(pageId);
            navegador.Close();
        }
Beispiel #28
0
        static void Main(string[] args)
        {
            IWebDriver driver = new ChromeDriver();

            driver.Navigate().GoToUrl("https://www.instagram.com/accounts/login/");
            driver.Manage().Window.Maximize();

            try //caso ocorra um erro
            {
                //Thread.Sleep(TimeSpan.FromSeconds(5)); // ira literalmente esperar todos esse tempo
                driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(10); //espera no max 10s pra buscar o elemento
                driver.FindElement(By.Name("username")).SendKeys(ConfigurationManager.AppSettings["username"]);
                driver.FindElement(By.Name("password")).SendKeys(ConfigurationManager.AppSettings["password"]);
                driver.FindElement(By.XPath("//*[@id='loginForm']/div/div[3]/button/div")).Click();

                Thread.Sleep(TimeSpan.FromSeconds(5));
                driver.Navigate().GoToUrl(@"https://www.instagram.com/portalg1/");
                driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(10);

                //driver.FindElement(By.XPath("//*[@id='react-root']/section/main/div/header/section/div[1]/div[2]/div/div/div/span/span[1]/button")).Click();
                //driver.FindElement(By.XPath("//button[contains(text(),'Seguir')]")).Click(); // outra alternativa de XPath

                IWebElement button = null;
                try
                {
                    button = driver.FindElement(By.XPath("//button[contains(text(),'Seguir')]"));
                    button.Click();
                }
                catch (NoSuchElementException ex)
                {
                    Console.WriteLine("Ja esta seguindo o perfil");
                }
            }
            catch (Exception ex) //imprime o erro
            {
                Console.WriteLine(ex.ToString());
            }
            finally
            {
                driver.Close();   // fecha browser
                driver.Dispose(); //libera memoria, etc
            }
        }
Beispiel #29
0
        public void CheckHeadlineName()
        {
            IWebDriver driver = new ChromeDriver();

            driver.Navigate().GoToUrl("https://www.bbc.com");

            IWebElement NewsButton = driver.FindElement(By.XPath("//div[@id='orb-nav-links']//li[@class = 'orb-nav-newsdotcom']"));

            NewsButton.Click();

            string expectedResult = "World's most profitable company to go public";

            IWebElement Title = driver.FindElement(By.XPath(".//*[contains(@class,'promo-heading__title')]"));

            string elementText = Title.Text;

            NUnit.Framework.Assert.AreEqual(expectedResult, elementText, $"The headline article is {elementText}, but expected is {expectedResult}");
            driver.Close();
        }
        public void TestMethod1()
        {
            IWebDriver driver = new ChromeDriver();

            driver.Navigate().GoToUrl("https://techblog.polteq.com/testshop/index.php");

            driver.FindElement(By.ClassName("login")).Click();
            driver.FindElement(By.Id("email")).SendKeys("*****@*****.**");
            driver.FindElement(By.Id("passwd")).SendKeys("Welkom01!");
            driver.FindElement(By.Id("SubmitLogin")).Click();

            //Console.WriteLine("SetUp is Run");

            IWebElement pageHeader = driver.FindElement(By.ClassName("page-heading"));

            Assert.AreEqual(pageHeader.Text, "MY ACCOUNT");

            driver.Close();
        }