Tuesday, August 17, 2021

                                                                              click here for Manual Testing Interview Questions

What is method overload and method override?

Method Overload: Method overload means methods contain with same name and difference in the parameters

This difference may be in the 

-> sequence of the parameters

-> number of the parameters

-> type of the parameters

Method overload is an example of Dynamic Polymorphism/runtime polymorphism

Method Override: Method Override means methods with same name and same parameters. This override performs in parent and child classes

Method override is an example of Static Polymorphism/Compile time Polymorphism


What is a static keyword in Java?

If applies static to the member of a class. You can directly access that with the classname without creating any object.

  • The value of the  static variable is shared by all objects of a class means same set of copy available to all the objects.


What is final keyword in Java?

Final means fixed. No changes can be happened on it. If applies final

    -> to a variable then, that variable value can not be changed.

    -> to a method then, that method can not be override

    -> to a class then that class can not be inherited.


What are the Access Modifiers?

Access Modifiers are:

1. public

2. private

3. default

4. protected

-> public means that member of a class can be visible and accessed anywhere in the project.

-> private means that member can be visible and accessed with in a method or class.

-> default means that member can be visible and accessed with in a package. If no access modifier is used, it considers as default

-> protected means that member can be visible and accessed with in a package and in child classes of another package.


What is Selenium?

Selenium is a automation tool which is used to automate the web applications.

Advantages of Selenium?

1. Selenium is an Open-Source

2. Selenium supports multiple languages like Java, c#, Python, Ruby, Perl etc.,

3. We can write the automation scripts in multiple browsers like chrome, firefox, IE, Microsoft Edge etc.,

4. Selenium supports multiple Operating Systems Windows, Linux, Mac etc.,

5. Supports Android and iOS


What is a WebDriver?

WebDriver is an Interface, it is implemented by respective Browser Drivers like ChromeDriver, FirefoxDriver etc.,


Write a simple Selenium Script or Code?

System.setProperties("webdriver.chrome.driver","Path of the Driver File");

WebDriver driver=new ChromeDriver();

driver.get("URL");


What are different Locators in Selenium?

Locator: Locator means an address of an WebElement. We have Locators in Selenium like

1. id

2. name

3. className

4. tagName

5. linkText

6. partialLinkText

7. xpath

8. cssSelector


What is absolute xpath and relative xpath?

absolute xpath starts with '/' and it identifies the element from route node to child node.

relative xpath starts with '//' and it identifies the element directly where it present in the HTML DOM.

Note: / -> single forward slash, // -> double forward slashes


How to write relative xpath?

We can write the relative xpath in multiple ways one the way is by using tagName, attribute and values like

//tagName(@attribute='value')

Also we can write this  with

1. text() method

2. contains() method

3. xpath axes like parent, ancestor, preceding-sibling and forwarding-sibling etc.,


What is the difference between xpath and css selector?

XPath and CSS Selectors are both used to locate elements on a web page. Some common differences are:

1. Xpaths are expressive. CSS selectors are generally shorter and often easier to read.

2. XPath can traverse up, down, and sideways in the DOM. CSS Selectors can only go down (from parent to child), not backwards.

3. XPath can traverse through siblings. Css Selector can not support siblings.

4. XPath supports text-based functions like text(), contains() and startsWith() etc., CSS Selector doesn't support these text-based functions.

5. Use XPath if you need complex logic. Use Css if you need basic stuff.

6. XPath is slower, CSS Selector is faster.

What is a Page Object?

A Page Object is class which is created for each and every page of an application.

This class contains all the WebElements of the page and getter methods for respective webElements.


What is the PageFacory?

PageFacory is a class which is used to initialize the PageObject.


Diference between findElement and findElements()?

findElement() is used for Single element and return type is WebElement. If no element is found then findElement() returns NoSuchElementFoundException.

findElements() is used for List of WebElements and return type is List<WebElement>. If no element is found then findElements() returns empty list.


What are the waits in Selenium?

Selenium provides waits like

1. implicitwait

2. explicitwait

3. fluentwait


What is the difference between implicit wait and explicit wait?

implicit wait is used to provide waiting time for all the WebElements

explicit wait is used to provide the waiting time for a specific condition or WebElement.


Write a code for implicit wait?

driver.manage().timeouts().implicitlyWait(10,TimeUnit.SECONDS) ;


Write a code for explicit wait?

WebDriverWait wait = new WebDriverWait(driver,30);

wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("locator")));


How to enter the data into the textbox?

We can enter the data into any textbox using 3ways:

1. sendKeys() method from WebElement

2. JavaScriptExecuter

3. Actions class


How to click on a button?

We can click any button using 3ways:

1. click() method from WebElement

2. JavaScriptExecuter

3. Actions class

If a button has submit as attribute-value then we can use directly submit().


How to get the text of a WebElement?

using getText(), we can get the Text.


How to initialize the webdriver?

WebDriver driver =new FirefoxDriver();

Here, we create the object for the class 'FirefoxDriver' and store it in reference variable of the Webdriver Interface.


How to launch a browser and pass the URL?

    1. First, we need to set the property for the driver like

    System.setProperty("webdriver.gecho.driver", "path of the driver file");

    2. Intialize the driver like

    WebDriver driver =new FirefoxDriver();

    3. Use the get() method to pass the URL like

    driver.get("URL");


what is the difference between quit() and close()?

quit() method closes all the window instances opened by the driver

close() method closes only current window instance.


How to handle/select dropdown element in the selenium?

We can handle dropdown element using Select class. The class contains the methods like

selectByIndex()

selectByValue()

selecByVisibleText()

Example: 

Select select=new Select(driver.findElement(By.xpath("locator")));

select.selectByVisibleText();


How to do mouse over action and click()?

We can take the help of Actions class to this. 
1st create an object for actions class
2nd Perform the mouse hover action using moveToElement method.
3rd click on the link using click method and apply build().perform() operation.

Example:
Actions action = new Actions(driver);
action.moveToElement(driver.findElement(By.xpath("<xpath>"))).perform();
action.click().build().perform()

How to Handle multiple Windows in Selenium?

getWindowHandle(), getWindowHandles() and switchTo() methods help to work with multiple windows.

All Opened window Ids get and store in Set reference variable and switch them with switchTo() method.

How to take a screenshot in Selenium?

We can take the help of "TakesScreenshot" Interface. This interface has the method "getScreenshotAs()". Using this, we can  take the screenshot and save it in a file.

Code Snippet:

    TakesScreenshot scrShot =((TakesScreenshot)webdriver);
    File SrcFile=scrShot.getScreenshotAs(OutputType.FILE);
    FileUtils.copyFile(SrcFile, "C:/Test.png");

What is textng.xml file format?

<suite name="SuiteName">

  <test name="TestName ">

      <classes>

      <class name="packagename.classname"/>

      </classes>

  </test>

</suite>


What are different testng Annotations in Order?

@BeforeSuite

   @BeforeTest

      @BeforeClass

         @BeforeMethod

           @Test

         @AfterMethod

      @AfterClass

   @AfterTest

@AfterSuite


@beforesuite -> this annotation will call before executing all the tests

@beforetest -> this annotation will call before executing all test cases

@beforeclass -> this annotation will call before executing all test cases in a class

@beforemethod -> this annotation will call before executing each and every test case

@Test -> it represents a Test Case

@aftermethod -> this annotation will call after executing each and every test case

@afterclass -> this annotation will call after executing all test cases in a class

@aftertest -> this annotation will call after executing all test cases

@aftersuite -> this annotation will call after executing all the tests

What is an Assertion?

Assertion is used for validation. We use Assert class from testng library to this validations. It has methods like assertEquals(), assertTrue(), assertFalse()


How to run only smoke testcases?

We can set the tag in the feature file and it pass in the TestRunner file.


What are the dependecies required for Cucumber BDD Framework?

Along with selenium-java and testng, also require

cucumber-testng

cucumber-java


What are CucumberOptions in TestRunner File?

We have CucumberOptions like

1. features

2. glue

3. tags

4. plugin

5. dryRun

6. monochrome

7. strict

Explanation:

features option is for setting up the path of the feature files

glue option is for setting up the path of the stepDefinition files

tags is to instruct what tag from feature file to execute

plugin is to set which report format to be generate after execution like HTML, JSON, or plain text.

dryRun to check all feature steps has respective matched Step Definition. Default Value is False

monochrome to display console output in readable way. Default Value is False

strict is to fails the execution if there are undefined or pending steps. Default Value is False


What are the Hooks in Cucumber?

Hooks are special functions that run before or after certain event. They execute pre- and post-execution actions, like setting up prerequisites or cleaning up test data, without cluttering the main scenario definitions

Types of Hooks:

Before Hooks: executes before executing each scenario

After Hooks: executes after executing each scenario

Step Hooks: Step hooks are special methods or functions that execute before or after specific Gherkin steps within a scenario.

What are tagged Hooks in Cucumber?

Regular Hooks run before/after every scenario.

Tagged Hooks run only for scenarios with a specific tag.

Ex: 

@Before("@smoke")     // runs only before scenarios tagged with @smoke

public void setupForSmokeTests() {

}

What is the framework you are using and Can you explain briefly?

I am working on BDD Framework with cucumber. It contains the components like

1. feature files

2. stepdefinition files

3. pageobjects

4. testrunner

5. WebDriverManager

6. utility

7. testdata

8. target

9. config folder

10. pom.xml

Can you please explain about each component in the Framework?

feature files -> feature contains scenarios. each scenario is a testcase. 

stepdefinition  file -> 

What is the feature file?

feature file contains all the scenarios to be execute. 

One feature file contains multiple scenarios

One scenario contains multiple steps

We write scenarios and steps in Gherkin Language


What are the Keywords use in feature file?

We use Gherkin Keywords like:

feature at feature level

scenario and scenario outline at scenario level

Given, When, Then, And, But at step level


What is deference between scenario and scenario outline?

we do not pass the testdata in scenario but we can pass testdata in "scenario outline" using "Example" keyword.

Can you write BDD steps for Gmail login Functionality in the feature file?

Yes I write.

with Scenario:

Feature: Application Login

Scenario: Verify Login Functionality

Given I Open The Gmail

When I Entered The Username "abc@gmail.com" and password "12345"

And I Click On Login Button

Then I See Gmail Home Page

or 

with Scenario Outline:

Feature: Application Login

Scenario Outline: Verify Login Functionality

Given I Open The Gmail

When I Entered The <username> and <password>

And I Click On Login Button

Then I See Gmail Home Page

Examples:

      | username | password |

      | abc@gmail.com | 12345 |


What are selenium 4 features?

key features of Selenium 4 are:

1. Selenium 4 introduces relative locators like: above(), below(), toLeftOf(), toRightOf(), and near().

2. W3C WebDriver Protocol Standardization

3. Enhanced Selenium Grid


What is the meaning of build().perform() in Actions class?

When using mouse movements and clicks, build().perform() chains multiple actions together and executes them in sequence.

ex: actions.moveToElement(element1).moveToElement(element2).click().build().perform();









Related Posts:

  • Static Keyword Static is a keyword in Java, which is used for static blocks variables methods and  inner classes or nested classes A static member can be accessed directly with the class name with out creating an object.  Th… Read More
  • TestNG Annotations What is TesNG and What are the annotations in the TestNG?      Ans: TestNG is testing framework to run the test cases. TestNG supports annotations like:       @BeforeSuite       &… Read More
  • Hashmap vs Hashtable Difference between Hashmap and Hashtable? HashMap is non-synchronized. Hashtable is synchronized.  HashMap allows multiple threads where as hashtable doesn't HashMap is not thread-safe where as hashtable is. HashMap … Read More
  • String Reverse Example public class StringReverse { public static void main(String[] args) { String str="selenium",reverse=""; for(int i=str.length()-1;i>=0;i--) { reverse=reverse+str.charAt(i… Read More
  • Java Database Connectivity(JDBC) JDBC: is an acronym for 'Java Data Base Connectivity'. It is used for accessing the databases from Java Applications. JDBC API allows to do CRUD operations on Database. Steps to connectivity between Java program and Dat… Read More

0 comments:

Post a Comment

Selenium Training in Realtime

Blog helps to a student or IT employee to develop or improve skills in Software Testing.

Followers

About Me

My photo
Hyderabad, Andhra Pradesh, India
I am Automation Testing Professional. I have completed my graduation in B.Tech (Computers) from JNTU Hyderabad and started my career in Software Testing accidentally since then, I passionate on learning new technologies

Contact Form

Name

Email *

Message *

Popular Posts