Automation Using Selenium Webdriver

Friday, 21 October 2016

Compare Strings Examples in java


package com.methods;
public class String_Functions {
public static void main(String[] args) {
String Str1="iam learning selenium";
String str2="   iam lazy to practise";
//equals function
System.out.println("comapring two styrings::"+Str1.equals(str2));
//concat function
System.out.println("Concatenation two strings:::"+Str1.concat(str2));
//charAt function
String st1="iam so beautifull";
System.out.println("index of charaAT:::"+st1.charAt(5));
//length function
System.out.println("lenght of st1::"+st1.length());
//toLowerCase function
String s="sELeNIuM";
System.out.println("LOWERCASE::"+s.toLowerCase());
//toUpperCase function
String s1="SEleIuM";
System.out.println("LOWERCASE::"+s1.toUpperCase());
//indexOf function
String t="iam very happy";
System.out.println("index of:::"+t.indexOf("very"));
//valueOf function
int j=100;
System.out.println("convert int to string::"+String.valueOf(j));
//parseInt function
String i="200";
System.out.println("convert string to int::"+Integer.parseInt(i));
//substring function
String st="i want job without practise";
System.out.println("substring is:::"+st.substring(11, 18));
//substring function
String p="RS/-300/-";
System.out.println("price substring is:::"+p.substring(4,7));
//split function
String splt="HCL@INFOSYS@DELOITE@IBM@GOOGLE@TECH";
String arrayvar[]=splt.split("@");
for(String each:arrayvar){
System.out.println("each index::"+each);
}
//split function
String sn="i want job in top mnc but i will not be regualr to class";
String var[]=sn.split(" ");
for(String eachindex:var){
System.out.println("index is::"+eachindex);
}
//trim function
String tr="                    testing tools                ";
System.out.println("trim vallue is::"+tr.trim());

}

}

Comparing Strings:
In order to compare Strings for equality, you should use the String object's equals or equalsIgnoreCase
 methods.

For example, the following snippet will determine if the two instances of String are equal on all
 characters
String firstString = "Test123";
String secondString = "Test" + 123;
if (firstString.equals(secondString)) {
   // Both Strings have the same content.
}
This example will compare them, independent of their case


import java.util.*;
import java.lang.*;
import java.io.*;

class Ideone
{
            public static void main (String[] args) throws java.lang.Exception
            {
                        String firstString = "Test123";
                        String secondString = "TEST123";
                        if (firstString.equalsIgnoreCase(secondString)) {
                           System.out.print("Equal");
                        }
            }
}

Comparing Strings in switch statement

String stringToSwitch = "A";
switch (stringToSwitch) {
    case "a":
        System.out.println("a");
        break;
    case "A":
        System.out.println("A"); //the code goes here
        break;
    case "B":
        System.out.println("B");
        break;
    default:
        break;
}

Changing the case of characters within a String


The String type provides two methods for converting strings between upper case and lower case:

toUpperCase to converts all characters to upper case
toLowerCase to convert all characters to lower case
These methods both return the converted strings as new String instances:
the original String objects are not modified.
String string = "This is a Random String";
String upper = string.toUpperCase();
String lower = string.toLowerCase();

System.out.println(string);   // prints "This is a Random String"
System.out.println(lower);    // prints "this is a random string"
System.out.println(upper);    // prints "THIS IS A RANDOM STRING"


Finding a String Within Another String

To check whether a particular String a is being contained in a String b or not, we can use the method
 String.contains() with the following syntax:

b.contains(a); // Return true if a is contained in b, false otherwise
The String.contains() method can be used to verify if a CharSequence can be found in the String.
The method looks for the String a in the String b in a case-sensitive way.

String str1 = "Hello World";
String str2 = "Hello";
String str3 = "helLO";

System.out.println(str1.contains(str2)); //prints true
System.out.println(str1.contains(str3)); //prints false


Reversing Strings

There are a couple ways you can reverse a string to make it backwards.

StringBuilder/StringBuffer:

String code = "code";
 System.out.println(code);

 StringBuilder sb = new StringBuilder(code);
 code = sb.reverse().toString();
Char array:
String code = "code";
System.out.println(code);

char[] array = code.toCharArray();
for (int index = 0, mirroredIndex = array.length - 1; index < mirroredIndex; index++, mirroredIndex--) {
    char temp = array[index];
    array[index] = array[mirroredIndex];
    array[mirroredIndex] = temp;
}

// print reversed
System.out.println(new String(array));

 System.out.println(code);

value labs testing interview questions 8th oct

value labs testing interview questions
1st technical
From Java
1.What is the Difference between final,finally,finalize
2.what is the difference between Call by value and call by referance
3.How to find out the length of the string without using length function
4.How to find out the part of the string from a string
5.difference between throw & throws
He give Programes
1.Reverse a number
2.1,2,3,4,5,65,76,5,,4,33,4,34,232,3,2323,
find the biggest number among these
simple string programe.
what is exception types of exception
From manual
what is the testcase technique
why we write test case.
bug life cycle
what are the different status of bug
what is the different between functional and smoke testing
what is STLC.
from Selenium
what is testng and its advantage
how to handle SSl/
how to handle alert
how to take screenshot
give the diagram write a scrpt..
tell me about Project .What are the challenge face during project
what is the difference between RC and webdriver
what is freamwork explain it.
why we use wait statement.

2nd technical
he gives a application & tell to write the scenario
some manual testing concepts.



Functional Testing Interview Questions


functional testing interview questions and answers

functionality is not working on What to do when most important the date of release?


If the release will be major, It should be rollback. Tester should create a bug for the issue.
If already fixed on previous release, we should reopen the bug. If the release is minor
It should be con...
or
As per my opinion, if the major functionality is not working then that build should be rejected and
 previous build should be deployed again (if in current build major fixes are not there) and then
we can send the build to client and later on we can perform hot fixes for other issues

Have you implemented Agile or Waterfall methodology in your project?

We have implemented using Agile. In Agile we have sprints, in which each sprint have 2 week duration oftime, within which a part of the deliverable have to be covered.
What is the need of testing functional part of an application when structural part is tested properly?
Functional testing means testing the every components and features and modules and also test
the data is transferred correctly between modules. Structural testing is on inside part of the software
             or
To see According to the requirement each and every components or fields are properly working or not for that purpose we need a functional testing.

What is the difference between V-model and Fish model?

In Fish model every stage is tested by other team for completeness and correctness.

In V model every stage same person reviews but in last stage software testing will be done by other testers.
V-model is methodology wherein testing and development goes paralley in iterative and incremental manner
What are the test cases for testing an "add to cart button"??

The fifth test case what have you mentioned that "When there is nothing in the cart click on add to cart button"
First think is that the add to cart button wont appear simply anywhere..
On selecting the particular product itself "Add to cart button" appears
1. Click on the Add to card Button without adding any item. 2. Click multiple times on Add to cart.
3. Add 10, 20, 30,...100 items and click on Add to cart, and at same time click multiple times.
4. S...
Are both 'Bakward Testing' & 'Regression Testing' one and the same? If Not, What is the difference between them?
Backward testing is retesting a specific module or area by seeing the defect or
bug which has raised in those perticular modules.
 or
I'm guessing you mean backward compatibility testing?? Given multiple version releases,
an application created on a new version should still work with the older versions making
it backwards compatibl...

What all do you report at the END of Testing?

Test Summary report is sent at the end of a project which consist of details like number of
test scripts executed , number of defects found and also the scope which was removed during testing

Functional and Functionality testing?

Functional testing focus on the output is as per the functioanlity or requirement.
 Functional and Functionality testing is same

Telecom - Equivalence class portioning?

There is a customer who has taken a service in which he is getting 300 free minutes.
So in this case make a call 1-300 , 300-10000(max limit) . So here we have 2 equivalent classes.
You can test 250 minutes and 400 minutes.. to test if both the classes data is working fine

Manual Test Case for Login page?

Here is the template below. I would like to see the detailed test cased for login page
column 1 is the "test case ID number"
column 2 is the "test case name"
column 3 is the "test objective"
column 4 is the "test conditions/setup"
column 5 is the "input data requirements/steps"
column 6 is the "expected results"
writing test case for login username (name must be 1-40 char,min-4 char) testcase id-tc1 testcase
name-username test objective-login username test condition -login page should be opened test data-fo.
..
Acceptance Testing?

The main focus of acceptance testing is:a) Finding faults in the systemb) Ensuring that
the system is acceptable to all usersc) Testing the system with other systemsd) Testing from
a business perspective.

or
Main focus of Acceptance testing to see whether all the given requirement is implemented in
application or not as well as to find the defect

How do you test when No time?

There is a new build and you have not much time left behind to test(manual test), what will you do?

It is too late but still we cant perform adhoc testing when time is less, as it requires different
approaches for testing the application to find bug, to increase the bug count. So for testing an appl..

If there no sufficient time to test the application then immediately we will go for exploratory testing...

Exploratory testing is dynamic testing type and it tests the entire application simultaneously
while creating test design and test execution is possible.

What is the difference between Agile methodology and Waterfall model?

In Agile methodologies accepts "Dynamic changes". Agile is modern methodology where a 5 to 10 people gathered at one place and to deliver a working software with in a given short span of time i.e, 2 ...

What is the difference between smoke and sanity testcase?

Smoke testing is a black box testing technique and it test after immediate the build release.

Smoke test touches all the areas of the application functionality with out going into deep.

Smoke test reveals that any simple failure in the application and application is ready for further testing.

or

Smoke testing is a shallow and wide approach whereby all areas of the application without getting into too deep, is tested.

A sanity test is a narrow regression test that focuses on one or a few areas of functionality. Sanity testing is usually narrow and deep.

What type of Testing you will do once the FRD is in place and approved?

FRD stands for functional Requirement Document. The first type of testing you would do when
the FRD is ready and approved is STATIC TESTING. This involves studying the work documents
like the Requirem...

What do you mean by a dependent functionality in a build?

Functional testing: testing each and ever functionality in the application whether it is working
properly or not giving valid information to the implication,and invalid information to the application,functionality is a black box testing.

or
Functional testing is a type of black box testing that bases its test cases on the specifications of the software component under test. Functions are tested by feeding them input and examining the output, and internal program structure is rarely considered (Not like in white-box testing)








Thursday, 20 October 2016

Selenium Java Interview Questions

Selenium Java Interview Questions

Caught Exception and Uncaught exception

Caught Exception:
When the programmer is not liable for error, Error come in run time, after execution.
Ex: int i =5/0;

Uncaught Exception:
When programmer is liable for error. Error comes at the time of programming.
Ex:
Thread.sleep(5000L);
---------------------------------------------------------------------------------------------------------
Difference between "Add throws declaration" and Surround with Try/Catch

Add throws declaration: If we don't want to report the error than we use this function.

Surround with Try/Catch block: If we want to report the error in selenium report than we use this function.
---------------------------------------------------------------------------------------------------------

Difference between Throws and Throw

Throws: Throws come in front of function and it tells Java that this function is capable of throwing an exception.
Ex: Add throws declaration" or Surround with Try/Catch

Throw: Throw clause is used to deliberately through an exception.
---------------------------------------------------------------------------------------------------------

Difference between final and finally

final: Stats that you cannot change the value of variable.
Ex: final int s=100; // Cannot change the value
        //s =101;  //it will give error

finally: finally is used with try/catch block. Finally stats that (finally is a block) it will executed for sure weather try block or catch block is executed or not.
Ex: try{
    //establish DB connection
    //fire query
    //get results
    //close connection
    }catch{Exception e}
    {
    //error
    System.out.println("error");
    }finally{
    //close the connection if established
    System.out.println("is finally");
    }
---------------------------------------------------------------------------------------------------------
Difference between Error and Exception:
Error: Out of memory error, ex: Assertion error thrown, when running the eclipse sometimes when run big program when error comes eclipse gone out of memory error.
Exception: run time exception, null pointer exception; divide by zero exception, array index out of bond etc.
---------------------------------------------------------------------------------------------------------
String to Integer Conversion:
String x = 100;
int 1 = Integer.parseInt (x);

int is the primitive data type but Integer is an in build  class just like a String class which represent int.
---------------------------------------------------------------------------------------------------------
Integer to String Conversion:
String z = String.valueof(i);
---------------------------------------------------------------------------------------------------------
String to Boolean conversion:
boolean b = Boolean.valueof("true");
https://mail.google.com/mail/u/0/images/cleardot.gif
---------------------------------------------------------------------------------------------------------
Collection API: Array List and Hash table are collection API.

ArrayList is similar to Array but it is not an array, it is inbuilt class and it is dynamically growing in size.

Ex: It is used where we need to read/get bulk data from site, get data from popup etc.
ArrayList <String> list = new ArrayList <String>();
        list.add("A");
        list.add("B");
        list.add("C");
        System.out.println(list.size());
for(int i =0;i<list.size();i++)
        {
            System.out.println(list.get(i));
        }

---------------------------------------------------------------------------------------------------------
Hah table and array list both are dynamically growing data structure. whereas Array List grow with index and Hash table grows with Kay and Value pair.
---------------------------------------------------------------------------------------------------------
HashTable: Hashtable is inbuilt class we can create object of the class. Hashtable contains key value pair (key and value). Key should be unique and corresponding to each key there should be a value.
Ex: We used Hash table to store test data.

Hashtable <String, String> table = new Hashtable <String, String>();
        table.put("Name", "Sunil");
        table.put("Company", "InfoBeans");
        table.put("Place","Indore");
        System.out.println("------------ Hash Table ----------");
        System.out.println(table.get("Name"));

Verify Image Presence in Web Page using Selenium WebDriver


JavaScript executor is one of themost useful features of Selenium WebDriver. It allows Selenium user to perform many complex scenarioseasily. This post covers one such important scenario.Selenium verify image present example using WebDriver. We have used JavaScript executor in WebDriver Java code hereto verify if image is present in a web page.


@Test
public void CheckImage() throws Exception {
driver.get(baseUrl);
WebElement ImageFile = driver.findElement(By.xpath("//img[contains(@id,'Test Image')]"));
        
        Boolean ImagePresent = (Boolean) ((JavascriptExecutor)driver).executeScript("return arguments[0].complete && typeof arguments[0].naturalWidth != \"undefined\" && arguments[0].naturalWidth > 0", ImageFile);
        if (!ImagePresent)
        {
             System.out.println("Image not displayed.");
        }
        else
        {
            System.out.println("Image displayed.");
        }
}
Run your test. It should identify if image is displayed in web page and will print appropriate result in console

Page Object Model(SingIn-Page)Exp

By Using Page Object Model SignInPage  Store Locaters and Test  Best Example for (Singin-Page)

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.PageFactory;

/**
 * Class which models the view of Sign-In page
 */
public class SignInPage {
 
    @FindBy(id="username")
    private usernameInput;

    @FindBy(id="password")
    private passwordInput;

    @FindBy(id="signin")
    private signInButton;

    private WebDriver driver;

    public SignInPage(WebDriver driver) {
        this.driver = driver;
    }
 
    /**
     * Method to perform login
     */
    public HomePage performLogin(String username, String password) {
        usernameInput.sendKeys(username);
        passwordInput.sendKeys(password);
        signInButton.click();
        wait.ForPageToLoad();
        return PageFactory.initElements(driver, HomePage.class);
    }
}


import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.PageFactory;
/**
 * Class which models the view of home page
 */
public class HomePage {
    @FindBy(id="logout")
    private logoutLink;

    private WebDriver driver;

    public HomePage(WebDriver driver) {
        this.driver = driver;
    }
 
    /**
     * Method to log out
     */
    public SignInPage logout() {
        logoutLink.click();
        wait.ForPageToLoad();
        return PageFactory.initElements(driver, SignInPage.class);
    }
}

/**
 * Login test class
 */
public class LoginTest {
    public void testLogin() {
        SignInPage signInPage = new SignInPage(driver);
        HomePage homePage = signInPage.login(username, password);
        signInPage = homePage.logout();
    }
}

Challenges faced while working on Selenium

Challenges faced while working on Selenium

There are many challenges we face while working on selenium. Some of the challenges are:

Challenges faced that are as follows:
·         Frequently changing UI. It always need to make changes in code most of the time.
·         Stuck somewhere while running automation scripts in chrome browser getting error that element is not visible, element not found.
·         New kind of element like ck-editor, bootstrap calendar and dynamic web tables. But get the solution always.
·         Reused of test scripts.
·         To be continued

1. configuration challenges on different machines
2. selenium's compatibility with browser versions like with FF20 is not supported with some web-driverversions.
3. handling IE/chrome etc.
4. popup handling
5. Ajax handling
6. security certificate handling
7. iframes
8. date pick from calender.
9. identifying locators
10. Upload and download file
11. Maintain the scripts to work properly irrespective of new build
12. Diff to identify script has failed may be unable to locate the element
or config issue(Browser updated) if your framework is not able to catch issue.
13. If you are using xpath as a locator. writing xpath without using dynamic changing data.
i.e., xpath generated dynamically.