Skip to main content

Selenium WebDriver : How to write test cases to search anything in Google (c#)



using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using OpenQA.Selenium.Support;
using OpenQA.Selenium.Support.UI;


namespace SeleniumWebDriverAutomation
{
    [TestClass]
    public class GoogleSearch
    {
        // webdriver dirver definition
        public IWebDriver driver = new ChromeDriver();

        [TestMethod]
        public void navigateToGoogleWebSite()
        {
            // Go to google web site
            driver.Navigate().GoToUrl("https://www.google.lk/");
            // Maximize the web browser
            driver.Manage().Window.Maximize();
            //call searchSomething method
            searchSomething("Selenium");
        }


        public void searchSomething(string searchString)
        {
            //find the google text searchbox by uisng html id and key in passed search string
            driver.FindElement(By.Id("lst-ib")).SendKeys(searchString);
            //find the google search button by uisng html name and click on it
            driver.FindElement(By.Name("btnG")).Click();
        }
    }
}


Demo run of above code 



Comments

Popular posts from this blog

Differences between Severity ,Priority and Status

In market there are many bug tracking and project management tools available. These tools allow us to keep essential information of a bug or task. You will see there are three places have to fill when key in a task. Those three places are Status, Priority and Status of a bug/task. Let's see what those stand for.  Severity Priority Status Connotation Severity of a bug means how much it affecting to functionality of the software. Total damage it can do. Priority means how fast a bug or task should be resolve. Status means the current position of the bug/task. Types            Critical            Major            Moderate            Minor           Cosmetic           Low           Medium       ...