0% found this document useful (0 votes)
24 views

selenium fastrack

Uploaded by

kasithangamcse92
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views

selenium fastrack

Uploaded by

kasithangamcse92
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 18

What is software testing?

The process of testing application with the intent to test the application is called as Software
testing

What is Manual testing


The process of testing the application without tool is called as manual testing.

What is automation testing?


The process of testing the application using tool is called as Automation testing

Advantages of Automation testing


1. Time and cost reduction
2. Accuracy
3. Reusability or Repeatability
4. Consistency
5. Quality

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.

Selenium WebDriver architecture

WHAT IS WebDriver or explain WebDriver methods


WebDriver is an Interface present in selenium to handle browser window

1. get(String url)  To enter URL or to navigate to webpage


2. getTitle()  To get the title
3. getCurrentUrl()  To get the URL
4. getPageSource()  To get the source code
5. getWindowHandle()  To get the id / name of current window. Returns String
6. getWindowHandles()  To get the id / name of all the windows. Returns Set<String>
7. manage()  Used to call maximize, minimize the fullScreen() methods
8. navigate()  Used to navigate to URL, navigate back(), navigate forward() and
refresh()
9. switchTo()  To switch the driver control to alert, window, frame or active element
10. close()  To close only the current window
11. quit()  To close all the windows and to close driver session
Explain Locators
Locators are used to find the location web element in the webpage.

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.

* XPath is slow compared to all other locators.

* There are two types of XPath:

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.

* It is the direct way to find the element.

* 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

* First forward slash (/) represents root tag

* Forward slash after tagname (/html/) represents all immediate tags

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

Types of relative XPath

 xpath by attribute
 xpath by text function
 xpath by contains function
 xpath by traversing
 forwarding xpath
 backward traversing
 xpath by index

Diff b/w cssSelector and xpath


cssSelector() Xpath()
Faster Slower
Can’t use text() text() can be used
Can’t use contains() contains() can be used
Backward traversing not possible Backward traversing is possible
Explain WebElement methods
Anything which is present in the webpage is called as WebElement. To perform action on
the web element WebElement interface methods are used.

There are 14 methods in WebElement

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()

Difference between findElement() and findElements()


findElement() findElements()
Used to handle single web element Used to handle multiple webelements
Return type is WebElement Return type is List<WebElement>
If multiple matching found it returns first matching If multiple matching found it returns all the matching
element element
If no matching found findElement() will throw If no matching found findElements() will return
NoSuchElementException Empty List<WebElement>
Explain how to handle list box/dropdown
If dropdown is created using select tag, then it can be handled using the methods of Select
class.

Select select =new Select(WebElement dropdown);

There are 12 methods in select class

1. selectByIndex()
2. selectByValue()
3. selectByVisibleText()
4. deselectByIndex()
5. deselectByValue()
6. deselectByVisibleText()
7. deselectAll()
8. isMultiple()
9. getOptions()
10. getAllSelectedOptions()
11. getFirstSelectedOption()
12. getWrappedElement()

Mention the different types of pop ups.


Popup is a window that displays or pops up on the screen due to some activity.

Pop up types

 Alert or Javascript
o Simple
o Confirm
o Prompt
 Child window
 File upload
 File download
 Notification
 Authentication
 Calendar

How to handle Alert pop up


Alert pop up can be handle by using:

driver.switchTo().alert().accept()

driver.switchTo().alert().dismiss()

driver.switchTo().alert().getText()

driver.switchTo().alert().sendKeys()

Explain how to handle child window pop up


Child window pop up can be handled by using “
driver.switchTo().window(windowId);”

getWindowHandle() and getWindowHandles();


Explain synchronization
Synchronization is the process of matching the speed of selenium with speed of
webapplication.

There are three types waits in selenium to achieve synchronization.

1. Implicit wait

Syntax :

2. Explicit wait or WebDriverWait

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

How to handle mouse and Keyboard actions?


In Selenium mouse and keyboard actions can be handled using Actions Click

Actions action=new Actions(driver);

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()

Explain about Robot class


Robot class is used to handle actual mouse and keyboard actions

Robot robo=new Robot();

1. mouseMove()
2. mousePress()
3. mouseRelease()
4. keyPress(KeyEvent.VK_SHIFT);
5. keyRelease(KeyEvent.VK_SHIFT);

How to handle elements present in frame?


Frame is used to embed one html page inside another html page.

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()

How to take screenshot in Selenium?


Screenshot can be taken by using “ getScreenshotAs()” method of TakesScreenshot
interface.

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

Explain all different types of annotation.


@BeforeSuite

@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

Hard Assert: Used to validate mandatory checkpoints.

 Hard assert methods are static methods present in Assert class


 Syntax:

o
 If actual and expected are not matching, then Hard Asser will stop the execution.

SoftAssert : Used to validate non mandatory check points

 SoftAssert methods are non static methods present in SoftAssert class


 Syntax:
o
 If actual and expected are not matching, then Soft Asser will stop the execution. It
will complete the execution and fail the test script in the last.
 assertAll() method is mandatory in SoftAssert

Difference between Hard assert and soft assert or explain diff


between Assert and Verify
Hard Assert SoftAssert
Static methods present in Assert class Non static methods present in SoftAssert
class
In case of failure test case will be terminated In case of failure test case will be terminated
abruptly abruptly
No need to call any method to show We need to call assertAll() method to show
assertion failure. assertion failure.
What is POM

 It is a design pattern which is used in automation to write test scripts independent of


the web element identification.
 We write a separate java class for each and every page of web application.
 It is also called as Object repository

How to create POM class


Advantages of POM

 To handle stale element reference exception


 Maintenance of web element is easy
 Reusability of code
 Readability of code is easy.

Explain where you have used OOPs in your framework.


1. Inheritance  BaseClass to all Test class and BasePage to all Page class
2.

What is Framework and what are the different types of framework


Framework:

- Framework is a set of rules and guidelines or best practices to be followed while

automating any application.

Or

- Framework is a collection of reusable components that makes automation test

script development, execution and modification to be easier and faster.

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

Different types of frameworks available

1. Keyword driven framework


2. Data Driven framework
3. Modular driver framework
4. Behaviour driven framework
5. Hybrid Framework

Explain your frame work


Framework is a set of rules and guidelines or best practices to be followed while
automating any application.
- Inorder to execute the test script with multiple inputs or test data, we use an excel and property
file, so we call our framework a Data driven framework.
- Inorder to avoid writing repetitive steps again and again we use lots of reusable methods, so we
call our framework a method driven framework.
- Since we maintain our framework module wise, we also call our framework a Modular driven
framework.
- Since it is a combination of 2-3 frameworks hence it is called a Hybrid driven framework.
- In the beginning of the execution first it executes the BaseClass which is present in the Generic
package which contains all the configuration methods like @BeforeClass, @BeforeMethod,
@AfterMethod and @AfterClass.
First it executes the @BeforeClass which contains the code for opening the browser, then it will
execute the Login code which is present in @Beforemethod.
- Then it will executes the @Test method where actual test scripts are written in test script package,
while executing the test scripts it will take the test data from the excel file with the help of Apache
POI jars and performs action on the GUi
application by calling necessary methods present in the POM class.
- Once it executes the test method it will execute the Logout code which is
present in @AfterMethod.
- Like this it will execute all the test cases one after the other with help of Batch
runner(testng.xml).
- After the execution of all the test cases it will close the browser which is present
in @AfterClass.
Explain framework components

What is the advantage of maven project

What is method overloading?

What is method overriding?

What is class?

What is Object? And how to create object in java?

What is OOPs? Explain OOPs

Explain Inheritance

Explain Polymorphism

Explain Abstraction

Explain Polymorphism

Explain typecasting (upcasting, downcasting and explicit


typecasting)

Explain Exception handling

Explain List and Set

Explain Arrays

Explain String
Write a program to reverse given String

WAJP to reverse array

WAJP to check palindrome

WAJP to find prime number

WAJP to find the frequency of the character

WAJP to find the duplicate array elements

WAJP to remove duplicates

WAJP to find factorial of a number

Replace String EX: “I love Biriyani” Result=”I hate Biriyani”

Collection framework programs

You might also like