Selenium
What is Selenium ?
Selenium is suite of software tool to automated web browser. it is open source suite of tools mainly used for Functional and Regression Test automation.
Selenium supports the following types of testing
1-Functional Testing.
2-Regression Testing.
Selenium support various operating environment.
MS Windows
Linux
Macintosh etc
Selenium Supports various Browsers.
Google Chrome
Mozilla Firefox
Internet Explorer
Safari
Opera etc.
Selenium Supports various Programming Environment to write programs Test Scripts
Java
C#
Python
Perl
Ruby
PHP
Benefits of Automation testing are:
1-Supports execution of repeated test cases.
2-Aids in testing a large test matrix.
3-Enables parallel execution.
4-Encourages unattended execution.
5-Improves accuracy thereby reducing human generated errors.
6-Saves time and money.
History of The Selenium Project-:
- Selenium First Come to Life in 2004.
- In 2006, Selenium Web driver was launched at google.
- In 2008, the whole selenium team decided to merge selenium web driver with selenium RC in order to from more power tool selenium 2.0.
Selenium 1-:
Selenium IDE + Selenium RC + Selenium Grid
Selenium 2-:
Selenium IDE + Selenium RC + Selenium web driver + Selenium Grid
Selenium IDE-:
Selenium IDE it is a Firefox Browser Plugin, Used to create and execute test cases. and Play and Record Feature.
Selenium IDE Features:-
- Create Test Cases, Test Suits. We can record Test Case or Type Test Step using Element Locators and Selenese commands.
- Play and Record Feature.
- Edit Test Cases.
- Execute Test Cases, Test Suites.
- Debug Test Cases.
- Enhance Test Cases.
- Export Test Cases to the format.(Java, Ruby etc.)
NOTE-:
Selenium IDE Test Case default Format is HTML.
Drawbacks of Selenium IDE-:
- It Support Mozilla Firefox Browser only.
- It does not Support Programming logic/feature to enhance Test cases.
- It does not Support data driven Testing.
- It is not Suitable for Complex Test Case design.
- No Centralized maintenance of object/Elements.
Selenium Remote Control (RC)-:
Selenium RC is a server that allow user to create test scripts is a desired programming language. it also allows executing test scripts.within the large spectrum browser.
Selenium Web Driver-:
Selenium web driver is a programming interface to create and execute Test Case. Selenium web driver has programming interface but does not have IDE.
Selenium web driver Supports Java, C#, Perl, Python, Ruby, PHP Programming Language Environments to write Programs.
Selenium driver using Element, Object Locators, Properties, Web driver Method. We can create and Execute Test Cases.
Selenium Web driver Supports various browser to create and Execute Test Cases, Test Script Test.
Selenium Web driver Support various operating environment.
MS Windows.
Linux.
Mac etc.
Drawback of Selenium Web Driver-:
Selenium Web driver Support various operating environment.
MS Windows.
Linux.
Mac etc.
Drawback of Selenium Web Driver-:
- It does not generate detailed Test Reports.
- No Centralized maintenance of Object/Element.
Selenium Grid-:
Selenium Grid is used to execute tests across multiple browser, operating environments and machines in parallel.
Selenium Grid 2 Support Selenium RC Tests as well as Selenium web driver Tests.
Selenium Supporting Environment:-
- Operating Environment.
- Application Environment.
- Programming Environment.
- Browser Environment.
Selenium License-:
- All Selenium Project released under Apache 2.0 Licence.
- Any body can download and use all selenium project with free of cast.
- Any body can modify the source code and distribute the source code.
- Selling Modified code is not allowed.
Selenium Download Here Please Click Link http://www.seleniumhq.org/download/
Eclipse IDE-:
WebElement Email = driver.FindElement(By.id("Email");
Email.SendKey("India");
Email.Clear();
NOTE-:
There are many difference between Manual Testing and Automation Testing.
Implicit waits are used to Selenium WebDriver provide a default waiting time (say 30 seconds) between each consecutive test step/command across the entire test script. Thus, subsequent test step would only execute when the 30 seconds have elapsed after executing the previous test step/command. it is known as Implicit Wait.
Explicit waits are used to Selenium WebDriver provide a halt the execution till the time a particular condition is met or the maximum time has elapsed. Unlike Implicit waits, explicit waits are applied for a particular instance only. it is known as Explicit Wait.
Eclipse IDE-:
- To Create and Execute Java Programs.
- Add Selenium Web driver .jar Files to Java Project and Use web Driver Features.
- Install TestNG/Junit Testing Testing Frameworks.
Selenium Environment Setup-:
- Choose Selenium Tools.
- Selenium web driver to create Test Cases java as programming language.
- TestNG Framework as Test Runner.
- Firebug and Fire Path Plug in for Mozilla browser to inspect Elements. and browser drivers etc.
- Download Eclipse IDE and Extract.
- Download Java Software and Install.
- Set Environment Variable(Path Variable).
- Download Selenium Web Driver Java Language binding and Add web driver Jar File to Java Project in Eclipse IDE.
- Download and install Firebug and Fire Path from Mozilla Browser To Inspect Elements.
- Download IE, Chrome etc browser Drivers.
- Download and Install TestNG From Eclipse IDE.
Advantages of Selenium-:
- It is Open Source Software Testing Tool.
- It Supports Various Operating Environments(Windows, Linux, Mac etc).
- It Support Various Programming Environment.(Java, Perl, Python, Ruby and PHP).
- It Support Various Browser(IE, Mozilla, Google Chrome, Safari, Opera).
- It Supports Various Parallel Test Execution.
- It Uses Less Hardware Resources.
Disadvantage of Selenium-:
- It Supports Web Based Application only.
- No Reliable Supports from anybody.
- No Centralized Maintenance of Elements/Objects.
- Difficult to Setup Environment.
- Difficult to used.
- Limited Support for Image Based Testing.
- New Features May Not Work Properly.
- No Other Tool Integration for Test Management.
- No Built In Reporting facility.
What is Locator?
Locator is an address that identifies a web element uniquely within the web page. it is known as locator.
What is Element Locator?
Element Locator in Selenium Support 8 Element Locators to recognize Element.
- ID
- Name
- Class Name
- Tag Name
- Link Text
- Partial Link Text.
- CSS Selector
- X Path.
To Find Element on Web Pages.
NOTE-:
Element Locators are Common for all Browser.(Mozilla Firefox, Google Chrome, IE, Opera).
1-ID-: Syntax-: By.id("id Value")
Example-: driver.get("URL Gmail")
driver.FindElement(By.id("Email").Send Key("India");
What is driver?
driver is a Object.
What is FindElement?
FindElement is a web driver method or command.
What is By?
By is a Class.
What is ID?
ID is Locator.
What Is Email?
Email Is a Value.
Second Method-:
Second Method-:
WebElement Email = driver.FindElement(By.id("Email");
Email.SendKey("India");
Email.Clear();
NOTE-:
- Whenever we want to perform multiple operations on any element then choose second method.
2- Name-: Syntax:- By.Name("Value")
Example - driver.FindElement(By.Name("Email"));
3- Class Name-: Syntax:- By.Class Name("Value")
Example - driver.FindElement(By.Class Name("Text Box Color")).Send Key("India");
4- Tag Name-: Syntax:- By.tagname("value");
Example- driver.FindElement(By.tagname("input")).Sendkey("India");
5- Link Text-: Syntax:- By.linktext("value")
Example-: driver.FindElement(By.linktext("Gmail")).Click();
6-Partial Link Text-: Syntax-: By.partiallinktext("Value");
Example-: driver.FindElement(By.partiallinktext("Gma").Click();
7- CSS Locator-: Syntax:- By.css Selector("value");
Example-: driver.FindElement(By.css Selector(".gb-p")).Click();
8- X Path-:
X Path in XML (extensible markup language) Document Shows The direction of web application element location.
Syntax-: By.X Path("value");
Example-: driver.findElement(By.xpath(".//*[@id='identifierNext']/div[2]")).click();
4- Tag Name-: Syntax:- By.tagname("value");
Example- driver.FindElement(By.tagname("input")).Sendkey("India");
5- Link Text-: Syntax:- By.linktext("value")
Example-: driver.FindElement(By.linktext("Gmail")).Click();
6-Partial Link Text-: Syntax-: By.partiallinktext("Value");
Example-: driver.FindElement(By.partiallinktext("Gma").Click();
7- CSS Locator-: Syntax:- By.css Selector("value");
Example-: driver.FindElement(By.css Selector(".gb-p")).Click();
8- X Path-:
X Path in XML (extensible markup language) Document Shows The direction of web application element location.
Syntax-: By.X Path("value");
Example-: driver.findElement(By.xpath(".//*[@id='identifierNext']/div[2]")).click();
What is get() Method?
Open a specified URL in the browser windows.
Syntax-: driver.get("URL");
Example-: driver.get("https://www.google.co.in");
What is getTitle()?
Return Title of the Browser.
Syntax-: String Variable = driver.getTitle();
Example-: WebDriver driver = new Firefox Driver();
driver.get("https://www.google.co.in");
driver.get("https://www.google.co.in");
String Title = driver.getTitle();
System.out.println(Title);
What is getpagesource()?
Return HTML Page Source.
Syntax-: String StringName = driver.getpagesource();
Example-: WebDriver driver = new Firefox Driver();
driver.get("https://www.google.co.in");
driver.get("https://www.google.co.in");
String PageSource = driver.getpagesource();
System.out.println(PageSource);
What is getcurrenturl()?
Return Current URL of the Browser.
Syntax-: String StringName = driver.getcurrenturl();
Example-: WebDriver driver = new Firefox Driver();
driver.get("https://www.google.co.in");
driver.get("https://www.google.co.in");
String URL = driver.getcurrenturl();
System.out.println(URL);
What is Browser Navigation Method?
Loads a New webpage in the Current Browser Window.
Syntax-: driver.Navigate().to("Value");
Example-: WebDriver driver = new Firefox Driver();
driver.get("https://www.google.co.in");
driver.get("https://www.google.co.in");
String URL = driver.getcurrenturl();
System.out.println(URL);
driver.navigate().to("https://login.yahoo.com/");
URL = driver.getcurrenturl();
System.out.println(URL);
driver.navigate().to("https://login.yahoo.com/");
URL = driver.getcurrenturl();
System.out.println(URL);
What is Navigate().back()?
It move a single item back in the browser history.
Syntax:- driver.navigate().back();
Example-: WebDriver driver = new Firefox Driver();
driver.get("https://www.google.co.in");
Example-: WebDriver driver = new Firefox Driver();
driver.get("https://www.google.co.in");
String URL = driver.getcurrenturl();
System.out.println(URL);
driver.navigate().to("https://login.yahoo.com/");
URL = driver.getcurrenturl();
System.out.println(URL);
driver.navigate().back();
URL = driver.getcurrenturl();
System.out.println(URL);
driver.navigate().to("https://login.yahoo.com/");
URL = driver.getcurrenturl();
System.out.println(URL);
driver.navigate().back();
URL = driver.getcurrenturl();
System.out.println(URL);
What is Navigate().forward()?
It move single item forward in the browser history.
Syntax:- driver.navigate().forward();
Example-: WebDriver driver = new Firefox Driver();
driver.get("https://www.google.co.in");
String URL = driver.getcurrenturl();
System.out.println(URL);
driver.navigate().to("https://login.yahoo.com/");
URL = driver.getcurrenturl();
System.out.println(URL);
driver.navigate().back();
URL = driver.getcurrenturl();
System.out.println(URL);
driver.navigate().forward();
URL = driver.getcurrenturl();
System.out.println(URL);
driver.navigate().to("https://login.yahoo.com/");
URL = driver.getcurrenturl();
System.out.println(URL);
driver.navigate().back();
URL = driver.getcurrenturl();
System.out.println(URL);
driver.navigate().forward();
URL = driver.getcurrenturl();
System.out.println(URL);
What is Navigate().refresh()?
Refresh is the current webpage.
Syntax-: driver.navigate().refresh();
Example-: WebDriver driver = new Firefox Driver();
driver.get("https://www.google.co.in");
String URL = driver.getcurrenturl();
System.out.println(URL);
driver.navigate().refresh();
String URL = driver.getcurrenturl();
driver.navigate().refresh();
String URL = driver.getcurrenturl();
System.out.println(URL);
What is Close() Method?
It is Close the Focused browser or Current Browser.
Syntax-: driver.Close();
Example-: WebDriver driver = new Firefox Driver();
driver.get("https://www.google.co.in");
String Title = driver.getTitle();
System.out.println(Title);
driver.Close();
driver.Close();
What is quit() Method?
It Closes all Browser that opened by web driver during execution.
Syntax-: driver.quit();
Example-: WebDriver driver = new Firefox Driver();
driver.get("https://www.google.co.in");
String URL = driver.getcurrenturl();
System.out.println(URL);
driver.navigate().to("https://login.yahoo.com/");
URL = driver.getcurrenturl();
System.out.println(URL);
driver.quit();
driver.navigate().to("https://login.yahoo.com/");
URL = driver.getcurrenturl();
System.out.println(URL);
driver.quit();
NOTE-: How to used Selenium in google Chrome Browser?
If we are used google chrome browser in selenium, So download Chrome driver.and extract file.
and write the code in selenium class file.
System.setProperty("webdriver.chrome.driver", "E:\\Selenium\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
NOTE-:
- E:\\Selenium is the set of path where keep the Chrome driver folder.
- chromedriver.exe is same name write the Chrome driver Name, other wise Showing Error.
Example-:
System.setProperty("webdriver.chrome.driver", "E:\\Selenium\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.get("https://www.google.co.in");
String Title = driver.getTitle();
System.out.println(Title);
driver.Close();
driver.Close();
Why We Need to use different Locators?
Developer May Not Provide all Locators for all Element. Some Locators May be Duplicated. Hence need to use the different Locators.
How To Use Inspect Element?
Using Firebug and Fire Path Plugin, we can Inspect Elements in Mozilla Firefox.
If it is Google Chrome or IE, NO Need To Install any Plugin, They have build to developer.
What is difference between Manual Testing and Automation Testing?
There are many difference between Manual Testing and Automation Testing.
Manual Testing-:
- Manual Testing is a process which is done by Manually Testing.
- No need of programming in Manual Testing.
- Regression Testing process is tough in Manual Testing.
- More testers are required in Manual Testing because in this testing test cases need to be Executed manually and it gives low accuracy result.
- Manual Testing testers are allowed to do Random Testing to find the Bugs by the tester.
- Manual Testing,No Need of any Tools.
Automation Testing-:
- Automation Testing is a process which is done by the Used of automated tools.
- Need of programming is must in Automation Testing.
- Regression Testing process is easy in Automation Testing by The Tools.
- Few testers are required in Automation Testing because in this testing test cases need to be Executed by using Automation Tools.
- Automation Testing are allowed to do Running Scripts to find the bugs by the automation tester.
- Automation Testing, Always need of using tools.
What are wait condition available in Selenium webDriver?
There are two types of waits available in Selenium WebDriver.
- Implicit Wait.
- Explicit Wait.
Implicit Wait-:
Implicit waits are used to Selenium WebDriver provide a default waiting time (say 30 seconds) between each consecutive test step/command across the entire test script. Thus, subsequent test step would only execute when the 30 seconds have elapsed after executing the previous test step/command. it is known as Implicit Wait.
Implicit Wait Used The Code in Selenium WebDriver.
driver.Manage().Timeouts().implicitly wait(30, Timeunit.Secounds);
Explicit Wait-:
Explicit waits are used to Selenium WebDriver provide a halt the execution till the time a particular condition is met or the maximum time has elapsed. Unlike Implicit waits, explicit waits are applied for a particular instance only. it is known as Explicit Wait.
Explicit Wait Used the code in selenium WebDriver.
Wait Driverwait wait = new WebDriverwait(driver,30);
wait.unitile(Expected conditions.visibility of Element located(By.X path("value")));
great
ReplyDeleteThanks bhaiya
Delete