Selenium

*Points To Remember

Developed by Selenium :- Jason Huggins in 2004 as an internal tool at ThoughtWorks.

Flavour of selenium
*SeleniumIDE
*SeleniumRC (Remote Control)
*Selenium webdriver Or Selenium2   
*SeleniumGrid
                                                          Stable release : 2.52.
                                                          Written in : Java
                                                          Operating system :Cross-platform
                                                          Type:  framework for web applications
                                                          Introduced By : Apache License 2.0
                                                          Website www.seleniumhq.org (Official site)


1.What is automation testing?
*It is systemic way to convert manual test case to automation test.
Automation testing involves use to a separate testing tool and doesn’t require any manual intervention.

2.What is selenium webdriver?
*Selenium webdriver is a collections of jar file.

3.What is jar file?
*Jar file is a collections of .class file.

4.What is webdriver?
*Webdriver is an interface.

5.Why we go for automation?

*For long term project having more regression cycle and application is stable, that's the reason behind we go for automation.

6.In interview, interviewer will ask to all of you, Draw selenium webdriver architecture?

*Architecture of selenium webdriver

Supported all programming language
                                                             
                                                             Supported all browsers

                                     

Supported almost all OS
 Show this types of eg, its more impressive

7.What are the different types of locators in Selenium?

*Xpath
*CSS Selector
*DOM
*TagName
*LinkText
*PartialLinkText
*ID
*ClassName
*Name

8.What is an Xpath?

XML stands for Extensible Markup Language and is used to store & organize  arbitrary data.Xpath is used to locate a web element based on its XML path.There are two types of xpath
*Absolute-path
*Relative-path

9.Which is the latest selenium tool?
*Webdriver 

10. why selenium?

*Selenium is free and open source

*Supported all browsers like, Firefox, chrome, Internet Explorer, Safari etc.
*Supports multiple programming languages like, Java, C#, Ruby, Python, Pearl etc.
*has fresh and regular repository developments & powerfull Xpath
*It have a great platform compatibility, Windows, Mac OS, Linux etc. 

11.Diffrence btw /- & //- ??

/- it is used to find immediate child with absolute path.

//- it is used to find the entire structure with relative path

12.How do we launch FireFox in selenium?


Before launching FF, we need to configure (selenium standalone jar file) and after that 

Syntax for launching FF
                                         FirefoxDRiver driver = new FirefoxDriver();

13.How do we launch Google Chrome in selenium?


Before Remember launching chrome browser we need to configure not only (selenium standalone jar file), We need to download .exe file.


Syntax for launching Chrome                                

                          System.setProperty("webdriver.chrome.driver","F:\\library\\chromedriver.exe");
              
 driver= new ChromeDriver();

14.How do we launch IE?


*Just like Chrome.Syntax for launching IE

                                           
System.setProperty("webdriver.ie.driver", "F:\\library\\chromedriver.exe");
               
driver= InternetExplorerDriver();
this program?

15.Launch FF browser 
 navigate gmail 
run this program?

*Solution 
 First go to file->new->javaProject->enterProjectName->ok
 in this project create a java class, write any name, i am given the name of 'navigate_url' and save it.
now configure (selenium standalone jar)
Just write click on your project->new->properties->javaBuildPath-

new.naj

properties.naj


jar.naj
>Libraries->addExternalJar->configure selenium standalone jar>ok

selenium.naj

*//Launch FF
FirefoxDriver driver = new FirefoxDriver
*//EnterGmail_Url // use driver.get(method)
driver.get("http://www.gmail.com/")


16.What is diffrence between assert and verify?

*Assert:- When we develope our selenium script & run this script.Once we run those script it 'll' verify the result.If the test case fail then it will stop the execution of the test case there & move the control to other test case.
*Verify:- now i am telling you verify, suppose we 'll' writing some script after that run this script once we run those script then it 'll' verify the result.If the test case fail then it will not stop the execution of those test case.

17.What is difference between find element & find elements?

*Find Element:- It is used to verify one web element.Its return type is also one element.

*Find Elements:- It is used to find one and more web elements.Its return type of One & more.

18.How do you use navigations in selenium webdriver?

//use for page back history
*driver.navigate().back();
//use for page refresh
*driver.navigate().refresh(); 
//page forward
*driver.navigate().forward();

 *Webdriver Commands

 *//Instance of Firefox
                                  Webdriver driver = new FirefoxDriver();

 *// Commands to open Url
                                          driver.get("http://www.google.com");

*//Commands to type text in textbox
driver.findElement(By.xpath("xpath of textbox").sendkeys("Naj");

*// Click on button on webpage
            driver.findElement(By.xpath("xpath of button").click();

 *// Page Tittle
                        driver.getTittle();

*// Window handle to switch from one window to another window
               driver.switchTo().window(parent)(windows2) (child)


*How to handle multiple windows in webdriver?

Suppose you are login monster.com  to editing your profile, so when you are login monster.On those time you got one more window popup.

* Syntax to handle multiple windows

  package linda;

import java.util.Set;

import org.openqa.selenium.firefox.FirefoxDriver;

public class HandlingMultiple_Window {

public static void main(String[]args) {
FirefoxDriver driver = new FirefoxDriver();
driver.get("http://www.monster.com");
Set<String> windows = driver.getWindowHandles();
       Object[]data = windows.toArray();                                            driver.switchTo().window((String)data[1]);
                       driver.close();
                       System.out.println("windows");
 
}
}

*Handling Dropdown value using with 'Select' class

package linda;

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

public class Dropdown {

public static void main(String[] args) {
FirefoxDriver driver = new FirefoxDriver();
driver.get("http://www.indianrail.gov.in/seat_Avail.html");
 Select select = new Select(driver.findElement(By.xpath("//*[@id='lccp_class1']")));
select.selectByIndex(3);
  }

}


*How to use of Locators in selenium?
*How to use of 'xpath'?
*How to automate or 'Login' Gmail using with 'xpath' in webdriver ?

Step1 :- Launch browser//Mozilla                
Step2 :- Navigate Url//Gmail
Step3 :- Activate Firebug
firebug.naj


Step4 :- Enter Email-id

email.naj

Step5 : Click next
testing.naj

Step6 : Enter Password
testing

Step7 :- Sign-In
testing



*Final Code of 'Gmail-Login'
// launch firefox browser
FirefoxDriver driver = new FirefoxDriver();
// maximize windows
driver.manage().window().maximize();
//navigate url
driver.get("http://www.gmail.com");
// it will stop current java thread for specified amount of time.
Thread.sleep(2000);
// find xpth of email field & enter your valid email
driver.findElementByXPath(".//*[@id='Email']").sendKeys("arhan@gmail.com");
// click on next before type password field & enter your valid passwrd

driver.findElementByXPath(".//*[@id='next']").click();
// again wait 1second
Thread.sleep(1000);
//enter your passwrd
driver.findElementByXPath(".//*[@id='Passwd']").sendKeys("hashmi");
// finally click on ok
driver.findElementByXPath(".//*[@id='signIn']").click();
//Result : Successfully enter Login page

Testing

===================
===================
*The last day I was telling you how to find of 'xpath' and using of 'XPath'.

*Now I am telling you how to finding and using of locator 'By. name'

I wanted to show you how to find a locator 'By.name' on the Facebook Sign_up page.


I am going to show you a real time example

System.setProperty("webdriver.chrome.driver", "E:\\Webdriver_Tool\\chromedriver.exe");
ChromeDriver driver = new ChromeDriver();

driver.findElementByName("firstname").sendKeys("shruti");


last.naj

     driver.findElementByName("lastname").sendKeys("lastname");


first.naj

now see the output, which name I have given their first name and last name so its showing the textbox

name.naj


in eclipse you can see the whole of the code



eclipse.naj



==================
*using of locator 'By.id'
Syntax:- driver.findelement(By.id("email").sendkeys("abc");
See in this Image



==========

handle dropdown in selenium webdriver with real time example




I want handle dropdown on fb signUp page

Naj.drp


code to select dropdown
Select mydropdown=new Select(driver.findElementById("day"));
mydropdown.selectByIndex(11);

code to select particaular option
Selectmydropdown1=new Select(driver.findElementById("month"));

mydropdown1.selectByVisibleText("Jan");





                    To b Continued..........


No comments:

Post a Comment