selenium fastrack
selenium fastrack
The process of testing application with the intent to test the application is called as Software
testing
What is selenium
Selenium is an open source web automation tool.
Components of selenium
1. Selenium IDE
2. Selenium GRID
3. Selenium Webdriver
Advantages Selenium
1. Open source
2. Multiple Browsers( Chrome, Safari, Edge, Firefox and Opera)
3. Multiple platforms (Windows, MAC, Linux)
4. Multiple programming languages ( Java, Python, JavaScript etc...)
5. Easy to integrate with other testing frameworks like TestNG, JUnit, JMeter etc…
6. Large community of people using selenium.
Dis-advantages of selenium
1. Can’t automate MP3, MP4 related test cases.
2. Can’t automate OTP & Captcha related test cases.
3. Can’t automate QR code bar code related test cases.
4. Only web applications can be automated.
5. Gaming applications can’t be automated.
6. Desktop and standalone applications can’t be automated.
Selenium architecture
Client (WebDriver client library & language binding) To send request to the server
W3C protocol To send request to driver
Driver executable files Mediator between Client and Browser
Browser Actual browser which responds to client request.
There are 8 types of locators, they are static methods present in By abstract class
1. id()
2. name()
3. className()
4. tagName()
5. linkText()
6. partialLinkText()
7. cssSelector()
8. xpath()
xpath()
* XPath stands for XML path. It is a syntax for finding any element on a web page using XML
path expression. XPath can be used in HTML documents to find the location of any element
on a webpage using HTML DOM structure.
* In Selenium automation, if the elements are not found by the general locators like id,
class, name, etc. then XPath is used to find an element on the web page.
1) Absolute XPath
2) Relative XPath
Absolute XPath:
* Specifying complete path of the element from the root, till the element is called as
absolute xpath.
* The disadvantage of the absolute XPath is that if there are any changes made in the path
of the element then that XPath gets failed.
* The key characteristic of Absolute XPath is that it begins with the single forward
slash(/) ,which means you can select the element from the root node.
Syntax:
/html/body/div[2]/div[1]/div/input
Relative xpath -
* Relative xpath can be written using "//" and "/". "//" represents all child tag. "/"
represents immediate child tag.
syntax: //tagName//child_tag_name
//tagname/child_tag_name
xpath by attribute
xpath by text function
xpath by contains function
xpath by traversing
forwarding xpath
backward traversing
xpath by index
1. click()
2. clear()
3. sendKeys()
4. submit()
5. isDisplayed()
6. isEnabled()
7. isSelected()
8. getText()
9. getCssValue()
10. getAttribute()
11. getTagName()
12. getSize()
13. getLocation()
14. getRect()
1. selectByIndex()
2. selectByValue()
3. selectByVisibleText()
4. deselectByIndex()
5. deselectByValue()
6. deselectByVisibleText()
7. deselectAll()
8. isMultiple()
9. getOptions()
10. getAllSelectedOptions()
11. getFirstSelectedOption()
12. getWrappedElement()
Pop up types
Alert or Javascript
o Simple
o Confirm
o Prompt
Child window
File upload
File download
Notification
Authentication
Calendar
driver.switchTo().alert().accept()
driver.switchTo().alert().dismiss()
driver.switchTo().alert().getText()
driver.switchTo().alert().sendKeys()
1. Implicit wait
Syntax :
Syntax:
3. FluentWait
FluentWait is used to change the polling time. (Default Polling time for all waits is
500ms)
diff b/w implicitlyWait and explicit wait
implicitlyWait() WebDriverWait
Write only once in a program Write whenever wait needed
Works only for findElement and Works for all the methods
findElements
If Timeout we get noSuchElementException If Timeout we get TimeOutException
1. moveToElement()
2. click()
3. contextClick()
4. doubleClick()
5. clickAndHold()
6. release()
7. dragAndDrop()
8. scrollByAmount()
9. scrollToElement()
10. scrollFromOrigin()
11. keyDown()
12. keyUp()
13. perform()
1. mouseMove()
2. mousePress()
3. mouseRelease()
4. keyPress(KeyEvent.VK_SHIFT);
5. keyRelease(KeyEvent.VK_SHIFT);
Driver focus should be switched to frame in order to handle the elements present inside
frame
1. driver.switchTo().frame(int index)
2. driver.switchTo().frame(String nameOrId)
3. driver.switchTo().frame(WebElement element)
4. driver.switchTo().parentFrame()
5. driver.switchTo().defaultContent()
Webpage screenshot:
WebElement Screenshot:
Mention some of the exceptions you know in selenium
1. WebDriverException
2. TimeoutException
3. NoSuchElementException
4. StaleElementReferenceException
5. InvalidSelectorException
6. NoSuchFrameException
7. NoAlertPresentException
8. UnhandledAlertException
9. SessionNotCreatedException
10. ElementNotInteractableException
11. ElementClickInterceptedException
Explain TestNG
TestNG is a testing framework, by using we can execute test scripts without main method.
And also we can perform:
Batch execution
Group execution
Parallel execution
Annotations
Skip test cases
Priority
Dependency
Listeners
Assertions
@BeforeTest
@BeforeClass
@BeforeMethod
@Test
@AfterMethod
@AfterClass
@AfterTest
@AfterSuite
Explain Assertion
Assertion is the feature in java to validate some critical checkpoints.
There are two types of assertions
1. Hard assert
2. Soft assert
o
If actual and expected are not matching, then Hard Asser will stop the execution.
Or
Or
- Framework is a well organized structure of reusable components where one
driver script (testng.xml) will take care of entire batch execution without any
manual intervention
What is class?
Explain Inheritance
Explain Polymorphism
Explain Abstraction
Explain Polymorphism
Explain Arrays
Explain String
Write a program to reverse given String