Tuesday, January 28, 2020

Selenium Java Interview Ques & Ans Part-4


1) What is Cucumber?
Cucumber is a tool that supports Behaviour-Driven-Development(BDD) which is used to write acceptance tests for the web application. Cucumber can be used along with Selenium, Watir, and Capybara etc. Cucumber supports many other languages like Perl, PHP, Python, Net etc.
2) What are the advantages of Cucumber?
– Cucumber supports different languages like Java.net and Ruby.
– It acts as a bridge between the business requirements and development code.
– It allows the test script to be written without knowledge of any code, it allows the involvement of non-programmers as well.
– It serves the purpose of end-to-end test framework unlike other tools.
– Due to simple test script architecture, Cucumber provides code reusability.
3) What are the 2 files required to execute a Cucumber test scenario?
Step definition file and Test Runner file are the 2 files required to run a cucumber test scenario.
3) What language is used by Cucumber?
Cucumber uses Gherkin language. It is a domain specific language which helps you to describe business behavior without the need to go into detail of implementation. This text acts as documentation and skeleton of your automated tests.
4) What is meant by a feature file ?
The file, in which Cucumber tests are written, is known as feature files. The extension of the feature file needs to be “.feature”.
5) What does a feature file consists of?
Feature file consists of different test scenarios written using Gherkin language in Given/When/And/Then format.
6) What are the various keywords that are used in Cucumber for writing a scenario?
Most common keywords used in Cucumber are:
– Feature
– Background
– Scenario
– Given
– When
– Then
– And
– But
7) What is Scenario Outline in Cucumber and its purpose?
Same scenario can be executed for multiple sets of data using scenario outline. The data is provided by a tabular structure.
8) What programming language is used by Cucumber?
Cucumber supports a variety of different programming languages including Java, JavaScript, PHP, Net, Python, Perl, etc. with various implementations.
9) What is the purpose of Step Definition file in Cucumber?
A Step Definition is a Java method with an expression that links it to one or more Gherkin steps. When Cucumber executes a Gherkin step in a scenario, it will look for a matching step definition to execute.
To illustrate how this works, look at the following Gherkin Scenario:
Scenario: Login
Given user logins to the site
The user logins to the site part of the step (the text following the Given keyword) will match the following step definition:
public class StepDefinitions {
@Given("user logins to the site")
public void user_login_to_site () {
System.out.println("User is logged into the site")
   }
}


10) What are the major advantages of Cucumber framework?
– It is helpful to involve business stakeholders who can’t easily read code
– Cucumber Testing focuses on end-user experience
– Style of writing tests allow for easier reuse of code in the tests
– Quick and easy set up and execution
– Efficient tool for testing
11) Provide an example of a feature file using the Cucumber framework.
Feature: Login to site
Scenario: User login with valid credentials
Given user is on login page
When user enters valid username
And user enters valid password
Then login success message is displayed


12) Provide an example of Scenario Outline using Cucumber framework?
Feature − Scenario Outline
Scenario Outline − Login for facebook
Given user navigates to Facebook
When I enter Username as "<username>" and Password as "<password>"
Then login should be unsuccessful
Example:
| username  | password  |
| username1 | password1 |
| username2 | password2 |


13) What is the purpose of Behaviour Driven Development (BDD) methodology in the real world?
Behavior Driven Development is a software development approach that allows the tester/business analyst to create test cases in simple text language (English). The simple language used in the scenarios helps even non-technical team members to understand what is going on in the software project.
14) What is the limit for the maximum number of scenarios that can be included in the feature file?
You can have as many scenarios as you like, but it is recommended to keep the number at 3-5. Having too many steps in an example, will cause it to lose it’s expressive power as specification and documentation.
15) What is the use of Background keyword in Cucumber?
A Background allows you to add some context to the scenarios in the feature. It can contain one or more Given steps. It is run before each scenario, but after any Before hooks. In your feature file, put the Background before the first Scenario. You can only have one set of Background steps per feature. If you need different Background steps for different scenarios, you’ll need to split them into different feature files.
16) What symbol is used for parameterization in Cucumber?
The steps can use <> delimited parameters that reference headers in the examples table. Cucumber will replace these parameters with values from the table before it tries to match the step against a step definition.
17) What is the purpose of Examples keyword in Cucumber?
A Scenario Outline must contain an Examples (or Scenarios) section. Its steps are interpreted as a template which is never directly run. Instead, the Scenario Outline is run once for each row in the Examples section beneath it.
18) What is the file extension for a feature file?
Extension for a feature file is .feature
19) Provide an example of step definition file in Cucumber.
public class StepDefinitions {
@Given("user logins to the site")
public void user_login_to_site () {
System.out.println("User is logged into the site")
     }
}


20) What is the purpose of Cucumber Options tag?
@CucumberOptions annotation provides the same options as the cucumber jvm command line. For Example: we can specify the path to feature files, path to step definitions, if we want to run the execution in dry mode or not etc.
21) How can Cucumber be integrated with Selenium WebDriver?
We can integrate cucumber with selenium webdriver by adding all dependencies/jars related to selenium and cucumber in the project.
22) When is Cucumber used in real time?
Cucumber should be used for verifying the most important parts of the application using end-to-end tests. BDD should also be used to verify the wanted behaviour using integration tests. Importantly, the business should be able to understand these tests, so you can reduce uncertainty and build confidence in what you are building.
23) Provide an example of Background keyword in Cucumber?
Feature: Add items to shopping cart
Background: User is logged in
Given user navigate to login page
When user submits username and password
Then user should be logged in successfully

Scenario: Search a product and add it to shopping cart
Given user searches for dell laptop
When user adds the selected item to shopping cart
Then shopping cart should display the added item


24) What is the use of Behaviour Driven Development in Agile methodology?
The intent of BDD is to provide a single answer to what many Agile teams view as separate activities: the creation of unit tests and “technical” code on one hand, the creation of functional tests and “features” on the other hand.
25) Explain the purpose of keywords that are used for writing a scenario in Cucumber?
– Feature: The purpose of the Feature keyword is to provide a high-level description of a software feature, and to group related scenarios.
– Scenario: In addition to being a specification and documentation, a scenario is also a test. As a whole, your scenarios are an executable specification of the system.
– Given: steps are used to describe the initial context of the system – the scene of the scenario. It is typically something that happened in the past.
– When: steps are used to describe an event, or an action. This can be a person interacting with the system, or it can be an event triggered by another system.
– Then: steps are used to describe an expected outcome, or result.
– Scenario Outline: This keyword can be used to run the same Scenario multiple times, with different combinations of values.
– Background: It allows you to add some context to the scenarios in the feature. It can contain one or more Given steps.

Tuesday, January 21, 2020

Links

# CucumberTutorial #BDD #UpgradeFromCucumber1ToCucumber4

Cucumber 5 is about to release but many automation resters are still using Cucumber 1 and restricting themselves from using awesome features of Cucumber.

In this post, explain an end to end Cucumber 4 project setup in Eclipse with JUnit. Also given link to clone a git repo as well. 




# Handling multiple browsers in Selenium WebDriver

https://www.toolsqa.com/selenium-webdriver/handling-multiple-browsers-in-selenium-webdriver/

Java for Testers Interview Ques. & Ans. Part-2


1)  Write a Java program to print Floyd’s triangle?
public class FloydTriangle {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        System.out.println("Enter the number of rows");
        int rows = sc.nextInt();
        printFloydTriangle(rows);
    }
    public static void printFloydTriangle(int n){
        int number = 1;
        for(int i=0;i<n;i++){
            for(int j=0;j<=i;j++){
                System.out.print(number +" ");
                number++;
            }
            System.out.println();
        }
    }
}


2) Write a Java program to find all the sub-string of given string?
public class FindSubString {
    public static void main(String[] args) {
        String name = "Selenium And Java Interview Questions";
        System.out.println(name.contains("Java"));         // true
        System.out.println(name.contains("java"));         // false
        System.out.println(name.contains("Interview"));    // true
        System.out.println(name.contains("questions"));    // false 
    }
}


3) Write a Java program to print the given string in reverse?
public class ReverseString {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        System.out.println("Enter input string");
        String s1 = sc.next();
        String s2 = reverseString(s1);
        System.out.println("Reversed String is: "+s2);
    }
    public static String reverseString(String s){
        String rev="";
        char[] arr = s.toCharArray();
        for(int i=arr.length-1;i>=0;i--)
        rev = rev + arr[i];
        return rev;
    }
}


4) Write a Java program to check whether the given number is palindrome?
public class PalindromeNumber {
    public static void main(String[] args){
        int r,sum=0,temp;
        Scanner sc = new Scanner(System.in);
        System.out.println("Enter a number");
        int n = sc.nextInt();
        temp=n;
        while (n > 0) {
            r = n%10;
            sum = (sum*10) + r;
            n=n/10;
        }
        if(temp==sum)
            System.out.println("Number is palindrome");
        else
            System.out.println("Number is not palindrome");
    }
}


5) Write a Java program to add two matrix?
public class AddTwoMatrix {
    public static void main(String args[]) {
        //creating two matrices
        int a[][] = {{1, 3, 4}, {2, 4, 3}, {3, 4, 5}};
        int b[][] = {{1, 3, 4}, {2, 4, 3}, {1, 2, 4}};
        //creating another matrix to store the sum of two matrices
        int c[][] = new int[3][3];
        //adding and printing addition of 2 matrices
        for (int i = 0; i < 3; i++) {
            for (int j = 0; j < 3; j++) {
                c[i][j] = a[i][j] + b[i][j];
                System.out.print(c[i][j] + " ");
            }
            System.out.println();
        }
    }
}


6) Write a Java program to multiply two matrix?
public class MultiplyTwoMatrix {
    public static void main(String args[]) {
        //creating two matrices
        int a[][] = {{1, 1, 1}, {2, 2, 2}, {3, 3, 3}};
        int b[][] = {{1, 1, 1}, {2, 2, 2}, {3, 3, 3}};
        //creating another matrix to store the multiplication of two matrices
        int c[][] = new int[3][3];
        //multiplying and printing multiplication of 2 matrices
        for (int i = 0; i < 3; i++) {
            for (int j = 0; j < 3; j++) {
                c[i][j] = 0;
                for (int k = 0; k < 3; k++) {
                    c[i][j] += a[i][k] * b[k][j];
                }
                System.out.print(c[i][j] + " ");
            }
            System.out.println();
        }
    }


7) Write a Java program to get the transpose of matrix?
public class TransposeMatrix{
    public static void main(String args[]){
        //creating a matrix
        int original[][]={{1,3,4},{2,4,3},{3,4,5}};
        //creating another matrix to store transpose of a matrix
        int transpose[][]=new int[3][3];  //3 rows and 3 columns
        //Code to transpose a matrix
        for(int i=0;i<3;i++){
            for(int j=0;j<3;j++){
                transpose[i][j]=original[j][i];
            }
        }
        System.out.println("Printing Matrix without transpose:");
        for(int i=0;i<3;i++){
            for(int j=0;j<3;j++){
                System.out.print(original[i][j]+" ");
            }
            System.out.println();
        }
        System.out.println("Printing Matrix After Transpose:");
        for(int i=0;i<3;i++){
            for(int j=0;j<3;j++){
                System.out.print(transpose[i][j]+" ");
            }
            System.out.println();
        }
    }
}


8) Write a Java program to compare two strings?
public class CompareTwoStrings {
    public static void main(String[] args){

        Scanner sc = new Scanner(System.in);
        System.out.println("Enter first string");
        String first = sc.next();
        System.out.println("Enter second string");
        String second = sc.next();
        compare(first,second);
    }
    public static void compare(String s1, String s2){

        if(s1.compareTo(s2)==0) {
            System.out.println("Strings are equal");
        } else {
            System.out.println("Strings are not equal");
        }
    }
}


9) How to find whether a String ends with a specific character or text using Java program?
public class StringEndWith{
    public static void main(String args[]) {
        String s1 = "Java is a programming language";
        //Check if string ends with particular character
        boolean endsWithCharacter = s1.endsWith("e");
        System.out.println("String ends with character 'e': " + endsWithCharacter);
        //Check if string ends with particular text
        boolean endsWithText = s1.endsWith("java");
        System.out.println("String ends with String 'lang': " + endsWithText);
    }
}


10) Write a Java program to demonstrate indexOf()?
public class IndexOfExample{
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        System.out.println("Enter the input string:");
        String inputString = sc.nextLine();
        System.out.println("Enter the sub string:");
        String subString = sc.nextLine();
        int index = inputString.indexOf(subString);
        System.out.println("Index of sub string is: " + index);
    }
}

11) Write a Java program to demonstrate how to replace a string with another string?
public class ReplaceString{
    public static void main(String args[]) {
        String originalString = "Java for dummies";
        String newString = originalString.replace("dummies","experts");
        System.out.println("Original string is: " + originalString);
        System.out.println("New String is: " + newString);
    }
}
12) Write a Java program to split the given string?
class SplitString{
    public static void main(String []args){
        String strMain = "Java,C,Python,Perl";
        String[] arrSplit = strMain.split(",");
        for (int i=0; i < arrSplit.length; i++)
        {
            System.out.println(arrSplit[i]);
        }
    }
}


13) Write a Java program to remove the spaces before and after the given string?
class RemoveSpacesInString{
    public static void main(String []args){
        String s1 = "Interview Questions for Java";
        String newString = s1.replaceAll("\\s","");
        System.out.println("Old String: " + s1);
        System.out.println("New String: " + newString);
    }
}


14) Write a Java program to convert all the characters in given string to lower case?
class ConvertToLowerCase{
    public static void main(String []args){
        String s1 = "Interview QUESTIONS";
        String newString = s1.toLowerCase();
        System.out.println("Old String: " + s1);
        System.out.println("New String: " + newString);
    }
}


15) Write a Java program to demonstrate creating a method?
public class CreateMethodExample {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        System.out.println("Enter the number");
        int num = sc.nextInt();
        reverseNumber(num);
    }
    public static void reverseNumber(int number){
        int reverse = 0;
        while(number!=0){
            int digit = number % 10;
            reverse = reverse * 10 + digit;
            number = number/10;
        }
       System.out.println("Reversed number " + reverse);
    }
}


16) Write a Java program to find the length of the given string?
class FindLength{
    public static void main(String []args){
        String s1 = "Interview Questions In Java";
        int length = s1.length();
        System.out.println("Length of string is: " + length);
    }
}


17) Write a Java program to concatenate the given strings?
class StringConcatenation{
    public static void main(String []args){
        String s1 = "Interview Questions In Java";
        String s2 = " And Selenium";
        String s3 = s1.concat(s2);
        System.out.println("After concatenation: "+ s3);
    }
}


18) Write a Java program to replace a string?
class ReplaceString{
    public static void main(String []args){
        String s1 = "Interview Questions In Java";
        String s2 = "Answers";
        String s3 = s1.replace("Questions","Answers");
        System.out.println("Original String: "+ s1);
        System.out.println("New String: "+ s3);
    }
}


19) Write a Java program to demonstrate a Static block?
class StaticTest { 
    static int i; 
    int j; 
    // start of static block  
    static { 
        i = 10; 
        System.out.println("static block called "); 
    } 
    // end of static block  
}
class Main { 
    public static void main(String args[]) { 
        System.out.println(Test.i);  
    } 
}


20) Explain the difference between static and instance methods in Java?
Instance method are methods which require an object of its class to be created before it can be called. Static methods are the methods in Java that can be called without creating an object of class.
21) Write a Java program to demonstrate creating multiple classes?
public class A { 
    public static void print() { 
        System.out.println("This is a method");  
    } 
}
public class B { 
    public static void main(String args[]) { 
        print();  
    } 
}


22) Write a Java program to demonstrate creating a constructor?
class ConstructorTest { 
    ConstructorTest(){ 
        System.out.println("Constructor called"); 
    }    
} 
class Main 
{ 
    public static void main (String[] args) 
    { 
        ConstructorTest test = new ConstructorTest();
    } 
}


23) Write a Java program to demonstrate constructor overloading?
class Box 
{ 
    double width, height, depth; 
    int boxNo;  
    Box(double w, double h, double d, int num) 
    { 
        width = w; 
        height = h; 
        depth = d; 
        boxNo = num; 
    } 
    Box() 
    { 
        width = height = depth = 0; 
    } 
    Box(int num) 
    { 
        this(); 
        boxNo = num; 
    } 
    public static void main(String[] args) 
    { 
        Box box1 = new Box(1); 
        System.out.println(box1.width); 
    } 
}


24) Write a Java program to demonstrate Exception Handling?
public class ExceptionExample{  
  public static void main(String args[]){  
   try{  
      //code that may raise exception  
      int data=100/0;  
   }
   catch(ArithmeticException e)
   {System.out.println(e);}   
  }  
}


25) Write a Java program to demonstrate throwing an exception?
class ThrowExceptionExample  
{ 
    public static void main(String[] args)throws InterruptedException 
    { 
        Thread.sleep(10000); 
        System.out.println("Hello World"); 
    } 
}

Selenium Java Interview Ques. & Ans. Part-3


1) How to scroll web page up and down using Selenium WebDriver?
To scroll using Selenium, you can use JavaScriptExecutor interface that helps to execute JavaScript methods through Selenium Webdriver.
JavascriptExecutor js = (JavascriptExecutor) driver;
//This will scroll the page till the element is found
js.executeScript("arguments[0].scrollIntoView();", Element);


2) How to perform right click (Context Click) action in Selenium WebDriver?
We can use Action class to provide various important methods to simulate user actions
//Instantiate Action Class
Actions actions = new Actions(driver);
//Retrieve WebElement to perform right click
WebElement btnElement = driver.findElement(By.id("rightClickBtn"));
//Right Click the button to display Context Menu
actions.contextClick(btnElement).perform();


3) How to perform double click action in Selenium WebDriver?
Action class method doubleClick(WebElement) is required to be used to perform this user action.
//Instantiate Action Class
Actions actions = new Actions(driver);
//Retrieve WebElement to perform double click WebElement
btnElement = driver.findElement(By.id("doubleClickBtn"));
//Double Click the button
actions.doubleClick(btnElement).perform();


4) How to perform drag and drop action in Selenium WebDriver?
//Actions class method to drag and drop
Actions builder = new Actions(driver);
WebElement from = driver.findElement(By.id("draggable"));
WebElement to = driver.findElement(By.id("droppable"));
//Perform drag and drop
builder.dragAndDrop(from, to).perform();


5) How to highlight elements using Selenium WebDriver?
// Create the  JavascriptExecutor object
JavascriptExecutor js=(JavascriptExecutor)driver;
// find element using id attribute
WebElement username= driver.findElement(By.id("email"));
// call the executeScript method
js.executeScript("arguments[0].setAttribute('style,'border: solid 2px red'');", username);


6) Have you used any cross browser testing tool to run Selenium Scripts on cloud?
Below tools can be used to run selenium scripts on cloud:
-SauceLabs
-CrossBrowserTesting
7) What are the DesiredCapabitlies in Selenium WebDriver and their use?
The Desired Capabilities Class helps us to tell the webdriver, which environment we are going to use in our test script.
The setCapability method of the DesiredCapabilities Class, can be used in Selenium Grid. It is used to perform a parallel execution on different machine configurations. It is used to set the browser properties (Ex. Chrome, IE), Platform Name (Ex. Linux, Windows) that are used while executing the test cases.
8) What is Continuous Integration?
Continuous Integration (CI) is a development practice that requires developers to integrate code into a shared repository several times a day. Each check-in is then verified by an automated build, allowing teams to detect problems early.
9) How to achieve database testing in Selenium?
//Make a connection to the database
Connection con = DriverManager.getConnection(dbUrl,username,password);
//load the JDBC Driver using the code
Class.forName("com.mysql.jdbc.Driver");
//send queries to the database
Statement stmt = con.createStatement();
//Once the statement object is created use the executeQuery method to execute the SQL queries
stmt.executeQuery(select *  from employee;);
//Results from the executed query are stored in the ResultSet Object. While loop to iterate through all data
while (rs.next()){
String myName = rs.getString(1);}
//close the db connection
con.close();


10) What is TestNG?
TestNG is a testing framework inspired from JUnit and NUnit, but introducing some new functionalities that make it more powerful and easier to use. TestNG is an open source automated testing framework; where NG means NextGeneration.
11) What are Annotations and what are the different annotations available in TestNG?
Annotations in TestNG are lines of code that can control how the method below them will be executed. They are always preceded by the @ symbol.
Here is the list of annotations that TestNG supports −
-@BeforeSuite: The annotated method will be run only once before all tests in this suite have run.
-@AfterSuite: The annotated method will be run only once after all tests in this suite have run.
-@BeforeClass:  The annotated method will be run only once before the first test method in the current class is invoked.
-@AfterClass: The annotated method will be run only once after all the test methods in the current class have run.
-@BeforeTest: The annotated method will be run before any test method belonging to the classes inside the <test> tag is run.
-@AfterTest: The annotated method will be run after all the test methods belonging to the classes inside the <test> tag have run.
-@BeforeGroups: The list of groups that this configuration method will run before. This method is guaranteed to run shortly before the first test method that belongs to any of these groups is invoked.
-@AfterGroups: The list of groups that this configuration method will run after. This method is guaranteed to run shortly after the last test method that belongs to any of these groups is invoked.
-@BeforeMethod: The annotated method will be run before each test method.
-@AfterMethod: The annotated method will be run after each test method.
-@DataProvider: Marks a method as supplying data for a test method. The annotated method must return an Object[ ][ ], where each Object[ ] can be assigned the parameter list of the test method. The @Test method that wants to receive data from this DataProvider needs to use a dataProvider name equals to the name of this annotation.
-@Factory: Marks a method as a factory that returns objects that will be used by TestNG as Test classes. The method must return Object[ ].
-@Listeners: Defines listeners on a test class.
-@Parameters: Describes how to pass parameters to a @Test method.
-@Test: Marks a class or a method as a part of the test
12) What is TestNG Assert and list out some common assertions supported by TestNG?
Asserts helps us to verify the conditions of the test and decide whether test has failed or passed. A test is considered successful ONLY if it is completed without throwing any exception.
Some of the common assertions are:
-assertEqual
-assertTrue
-assertFalse
13) How to create and run TestNG.xml?
Step 1: Add a new file to the project with name as testng.xml
Step 2: Add below given code in testng.xml
<suite name=“TestSuite”>
<test name=“Test1”>
<classes>
<class name=“TestClass” />
</classes>
</test>
</suite>
Step 3: Run the test by right click on the testng xml file and select Run As > TestNG Suite
14) How to set test case priority in TestNG?
We need to use the ‘priority‘ parameter, if we want the methods to be executed in specific order. TestNG will execute the @Test annotation with the lowest priority value up to the largest.
@Test(priority = 0)
public void One() {
  System.out.println("This is the Test Case number One");
  }
@Test(priority = 1)
public void Two() {
System.out.println("This is the Test Case number Two");
}

15) What is parameterized testing in TestNG?
To pass multiple data to the application at runtime, we need to parameterize our test scripts.
There are two ways by which we can achieve parameterization in TestNG:
  • With the help of Parameters annotation and TestNG XML file.
@Parameters({“name”,”searchKey”})
  • With the help of DataProvider annotation.
@DataProvider(name=“SearchProvider”)


16) How to run a group of test cases using TestNG?
Groups is one more annotation of TestNG which can be used in the execution of multiple tests.
public class Grouping{
@Test (groups = { “g1” })
public void test1() {
System.out.println(“This is group 1”);
}
@Test (groups = { “g2” })
public void test2() {
System.out.println(“This is group 2“);
}}
Create a testing xml file like this:
<suite name =“Suite”>
<test name = “Grouping”>
<groups>
<run>
<include name=“g1”>
</run>
</groups>
<classes>
<class name=“Grouping”>
</classes>
</test>
</suite>


17) What is the use of @Listener annotation in TestNG?
Listener is defined as interface that modifies the default TestNG’s behaviour. As the name suggests Listeners “listen” to the event defined in the selenium script and behave accordingly. It is used in selenium by implementing Listeners Interface. It allows customizing TestNG reports or logs. There are many types of TestNG listeners available:
-IAnnotationTransformer
-IAnnotationTransformer2
-IConfigurable
-IConfigurationListener
-IExecutionListener
-IHookable
-IInvokedMethodListener
-IInvokedMethodListener2
-IMethodInterceptor
-IReporter
-ISuiteListener
-ITestListener
18) How can we create a data driven framework using TestNG?
We can create data driven tests by using the DataProvider feature.
public class DataProviderTest {
private static WebDriver driver;
@DataProvider(name = "Authentication")
public static Object[][] credentials() {
return new Object[][] { { "testuser_1", "Test@123" }, { "testuser_2”, "Test@123" }};
}
// Here we are calling the Data Provider object with its Name
@Test(dataProvider = "Authentication")
public void test(String sUsername, String sPassword) {
driver = new FirefoxDriver();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
driver.get("http://www.testqa.com");
driver.findElement(By.xpath(".//*[@id='account']/a")).click();
driver.findElement(By.id("log")).sendKeys(sUsername);
driver.findElement(By.id("pwd")).sendKeys(sPassword);
driver.findElement(By.id("login")).click();
driver.findElement(By.xpath(".//*[@id='account_logout']/a")).click();
driver.quit();
}
}


19) Where you have applied OOPS in Automation Framework?
Abstraction – In Page Object Model design pattern, we write locators (such as id, name, xpath etc.,) in a Page Class. We utilize these locators in tests but we can’t see these locators in the tests. Literally we hide the locators from the tests.
Interface – WebDriver itself is an Interface. So based on the above statement WebDriver driver = new FirefoxDriver(); we are initializing Firefox browser using Selenium WebDriver. It means we are creating a reference variable (driver) of the interface (WebDriver) and creating an Object.
Inheritance – We create a Base Class in the Framework to initialize WebDriver interface, WebDriver waits, Property files, Excels, etc. We extend the Base Class in other classes such as Tests and Utility Class. Extending one class into other class is known as Inheritance.
Polymorphism – We use implicit wait in Selenium. Implicit wait is an example of overloading. In Implicit wait we use different time stamps such as SECONDS, MINUTES, HOURS etc.
Encapsulation – All the classes in a framework are an example of Encapsulation. In POM classes, we declare the data members using @FindBy and initialization of data members will be done using Constructor to utilize those in methods.
20) How to handle Chrome Browser notifications in Selenium?
// Create object of HashMap Class
Map<String, Object> prefs = new HashMap<String, Object>();
// Set the notification setting it will override the default setting
prefs.put("profile.default_content_setting_values.notifications", 2);
// Create object of ChromeOption class
ChromeOptions options = new ChromeOptions();
// Set the experimental option
options.setExperimentalOption("prefs", prefs);
// pass the options object in Chrome driver
WebDriver driver = new ChromeDriver(options);


21) Explain any Test Automation Framework?
Testing frameworks are an essential part of any successful automated testing process. They can reduce maintenance costs and testing efforts and will provide a higher return on investment (ROI) for QA teams looking to optimize their agile processes. A testing framework is a set of guidelines or rules used for creating and designing test cases. A framework is comprised of a combination of practices and tools that are designed to help QA professionals test more efficiently. These guidelines could include coding standards, test-data handling methods, object repositories, processes for storing test results, or information on how to access external resources.
22) Tell some popular Test Automation Frameworks?
Some of the popular test automation frameworks are:
-DataDriven
-KeywordDriven
-Hybrid
-Page Object Model
23) Why Framework?
Below are advantages of using an automation framework:
-Ease of scripting: With multiple Testers in a team, having an automation framework in place ensures consistent coding and that best practices are followed to a certain level. Standard scripting will result in team consistency during test library design and prevent individuals from following their own coding standards, thus avoiding duplicate coding.
-Scalable: Whether multiple web pages are being added or Objects or data, a good automation framework design is scalable when the need arises. A framework should be much easier to extend to larger projects.
-Modularity: Modularity allows testers to re-use common modules in different scripts to avoid unnecessary & redundant tasks.
-Easy to understand: Having an automation framework in place it is quick to transition (or understand) the overall architecture & bring people up-to-speed.
-Reusability: Common library files can be reused when required, no need to develop them every time.
-Cost & Maintenance: A well designed automation framework helps in maintaining the code in light of common changes like Test data, Page Objects, Reporting structure, etc.
-Maximum Coverage: A framework allows us to maintain a good range of Test data, i.e. coverage in turn.
-Better error handling: A good automation framework helps us catch different recovery scenarios and handle them properly.
-Minimal manual intervention: You need not input test data or run test scripts manually and then keep monitoring the execution.
-Easy Reporting: The reporting module within framework can handle all the report requirements.
-Segregation: A framework helps segregate the test script logic and the corresponding test data. The Test data can be stored into an external database like property files, xml files, excel files, text files, CSV files, ODBC repositories etc.
-Test configuration: Test suites covering different application modules can be configured easily using an automation framework.
-Continuous integration: An automation framework helps in integration of automation code with different CI tools.
-Debugging: Easy to debug errors
24) Which Test Automation Framework you are using and why?
Cucumber Selenium Framework has now a days become very popular test automation framework in the industry and many companies are using it because its easy to involve business stakeholders and easy to maintain.
25) Mention the name of the Framework which you are using currently in your project, explain it in details along with its benefits?
Framework consists of the following tools:
Selenium, Eclipse IDE, Junit, Maven, Cucumber
File Formats Used in the Framework:
-Properties file: We use properties file to store and retrieve different application and framework related configuration
-Excel files: Excel files are used to pass multiple sets of data to the application.
Following are the key components of the framework:
-PageObject : It consists of all different page classes with their objects and methods
-TestData: It stores the data files, Script reads test data from external data sources and executes test based on it
-Features: It consists of functional test cases in the form of cucumber feature files written in gherkin format
-StepDefinitions: It consists of different methods to implement each step of your feature files
-TestRunner: It is the starting point for Junit to start executing your tests
-Utilities: It consists of different reusable framework methods to perform different operations
-Reports: It consists of different test reports in different formats along with screenshots
-Pom xml: It consists of all different project dependencies and plugins

String

  Java String  class provides a lot of methods to perform operations on strings such as compare(), concat(), equals(), split(), length(), re...