About Me

Page views

Powered by Blogger.

Followers

Friday 26 June 2015


How to launch chrome browser using selenium webdriver 

package DayFour;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.annotations.Test;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.AfterTest;
import com.thoughtworks.selenium.Selenium;
public class Chrome_Test {
    public WebDriver driver;
    public Selenium selenium;
   
    @Test
        public void LaunchChromeBrowser()
        {
        driver.get("http://manualtestinglearn.blogspot.in/");
        }
   
    @BeforeTest
        public void beforeTest()
        {
         //---> for Windows machine
        System.setProperty("webdriver.chrome.driver", "D:\\Library\\chromedriver.exe");  // Your chromedriver path.
        driver=new ChromeDriver();
       
        //---> for Linux machine
        System.setProperty("webdriver.chrome.driver",  "/home/Seleniumyourself/lib/chromedriver");   // Your chromedriver path.
        driver = new ChromeDriver();
        driver.manage().window().maximize();
        }
    @AfterTest
        public void afterTest() {
    }
}

Thursday 25 June 2015



So How to click on web link, image and tab on webpage using Selenium WebDriver.

Steps :
·         Define Firefox Browser and open the Firefox Browser
·         Open the URL (Website)
·         Get on IMAGE LINK like button using By.xpath
·         Get on WEBLINK using By.linktext  
·         Get on TAB LINK using By.cssSelector
·         Verify Correct Webpage is opened using click on TAB LINK and print on console
·         Verify Correct Webpage is not opened using click on TAB LINK and print on console.

Source Code : 

Image_Link_using_XPATH -           driver.findElement(By.xpath(".//*@id='choice']/tbody/tr/td[2]/center/a[1]/img")).click();
WebLink using Linktext -                   
     driver.findElement(By.linkText("the documentation")).click();
TAB Link using cssSelector -                                     
     driver.findElement(By.cssSelector("#header ul a")).click();

Practice Yourself :


package WebDriver;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import static org.junit.Assert.assertTrue;

public class Click_on_Link_Image_Tab {
          public static void main(String[] args) throws InterruptedException {
                  
                   //Define Firefox Browser as webdriver and open the Firefox Browser
                   WebDriver driver = new FirefoxDriver();
                  
                   //Open the website (URL)
                   driver.get("http://seleniumhq.org");
                  
                   //Click on IMAGE LINK using cssselector
             driver.findElement(By.xpath(".//*@id='choice']/tbody/tr/td[2]/center/a[1]/img")).click();
                  
                   //Click on WEBLINK using linkText
                   driver.findElement(By.linkText("the documentation")).click();
                  
                   //Click on TAB LINK using ID
                   driver.findElement(By.cssSelector("#header ul a")).click();
                  
                   try {
                             // Verify Correct Webpage is opened using click on TAB LINK
                             assertTrue(driver.getPageSource().contains("About Selenium"));
                             //Message is printed when webpage is opened using click on TAB LINK
                             System.out.println("Webpages are correctly opened");
                   }
                   catch (Throwable e)
                   {
                             //Message is printed when webpage is opened using click on TAB LINK
                             System.out.println("Webpages are NOT correctly opened");
                   }
                  
                   // Close the Firefox Browser
                   driver.close();
                  
          }

}

Sunday 21 June 2015



How to count the number of items in the drop down field using size() using Selenium WebDriver.



Steps:

      1.  Define Firefox Browser and open the Firefox Browser
       2.  Open the URL (Website)
       3.  Assign and Select the drop-down list element
    4.  Get all the option from drop-down list and assign into List
      5.  Count the item drop-down list and assign into integer variable


package dayOne;


import java.util.List;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.Select;

public class Count_Item_Dropdown {
       public static void main(String[] args) {
             
              //Define the Webdriver for Browser i.e. Firefox
              WebDriver driver = new FirefoxDriver();
               
              //Open the URL (Website)
        driver.get("http://housejoy.in/");
       
        //Assign and Select the dropdown list element
        Select selectDropdown = new Select(driver.findElement(By.id("cityName")));
       
        //Get all the option from dropdown list and assign into List
        List<WebElement> listOptionDropdown = selectDropdown.getOptions();
       
        // Count the item dropdown list and assign into integer variable
        int dropdownCount = listOptionDropdown.size();
       
        //Print the total count of dropdown list using integer variable
        System.out.println("Total Number of item count in dropdown list = "  + dropdownCount);      
       
       }
}


Popular Posts

Copyright © Learn Selenium Yourself | Powered by Blogger
Design by Duan Zhiyan | Blogger Theme by NewBloggerThemes.com