Showing posts with label Interview Ques-Ans for Automation Tester. Show all posts
Showing posts with label Interview Ques-Ans for Automation Tester. Show all posts

Saturday, July 5, 2014

How to verify the text present in my web page.

There could be two ways to verify text present in web page or not-
1) Find that element where that text is populating and use getText() method then verify.
2)1st Get the page source using getPageSource() method then verify.

Ex-

import java.util.concurrent.TimeUnit;

import junit.framework.Assert;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;

public class VerifyTextPresentInWebPage {
    public static void main(String[] args) {
        WebDriver driver = new FirefoxDriver();
        driver.get("http://www.goibibo.com/");
        driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
       
        //verify 'International Flights' text is there in the web page or not
        String expText = "International Flights";
       
        //first way to verify by using locator and getText() method
        String actText = driver.findElement(By.xpath("//a[@class='hm_inactive']")).getText();
        if(actText.contains(expText)){
            System.out.println("1) Expected text '"+expText+"' present in the web page.");
        }else{
            System.out.println("1) Expected text '"+expText+"' is not present in the web page.");
        }
       
        //second way to verify by using getPageSource method
        String pageSource = driver.getPageSource();
        if(pageSource.contains(expText)){
            System.out.println("2) Expected text '"+expText+"' present in the web page.");
        }else{
            System.out.println("2) Expected text '"+expText+"' is not present in the web page.");
        }
        driver.close();
    }
}


Wednesday, June 18, 2014

Using not() in XPath. (ex- you want to write the xpath for the element whose class is not equal to 'abc').

Requirement-
In the below html code, we have to write the xpath for the span (high lighted in green color) tags present inside td tags where td class="closeTrigger" and tr class is not "week-selected".

HTML code-

<tr>
<td class="weekend closeTrigger">
<span>5</span></td>
<td class="closeTrigger">
<span>6</span></td>
<td class="closeTrigger">
<span>7</span></td>
<td class="closeTrigger">
<span>8</span></td>
<td class="closeTrigger">
<span>9</span></td>
<td class="closeTrigger">
<span>10</span></td>
<td class="weekend closeTrigger">
</tr>
<tr class="week-selected">
<td class="weekend closeTrigger date-selected">
<span>11</span></td>
<td class="closeTrigger">
<span>12</span></td>
<td class="closeTrigger">
<span>13</span></td>
<td class="closeTrigger todays-date">
<span>14</span></td>
<td class="closeTrigger">
<span>15</span></td>
<td class="closeTrigger">
<span>16</span></td>
<td class="weekend closeTrigger">
</tr>
<tr>
<td class="weekend closeTrigger">
<span>17</span></td>
<td class="closeTrigger">
<span>18</span></td>
<td class="closeTrigger">
<span>19</span></td>
<td class="closeTrigger">
<span>20</span></td>
<td class="closeTrigger">
<span>21</span></td>
<td class="closeTrigger">
<span>22</span></td>
<td class="weekend closeTrigger">
</tr>


Correct xpath- //tr[not(@class='week-selected')]//td[@class='closeTrigger']//span

For reference, here is the verified snapshot from firepath.




webpage-

Thursday, June 12, 2014

How to Select Last value from the WebList without using getOptions() ?

WebElement dropDown = driver.findElement(By.xpath("//select")); //xpath of dropdown may be different, here just giving example

Select sel = new Select(dropDown);
List<WebElement> options = driver.findElements(By.xpath("//select//options"));
int numOfOptions = options.size();
sel.selectByIndex(numOfOptions-1); //this will select last value from the dropdown but this logic will work when html code has been developed with select tag

Wednesday, June 11, 2014

What do you mean by WebDriver driver = new FirefoxDriver();

What do you mean by
WebDriver driver = new FirefoxDriver();

Ans- Here in this, WebDriver driver = new FirefoxDriver();
An instance of FirefoxDriver class has been created and the address of that instance has been stored in the WebDriver type driver variable. As soon as 'new' keyword create the instance in the heap area while execution it will open the firefox browser with default setting.
As well as FirefoxDriver class will implement all the methods of WebDriver interface.

Why selenium is used in Firefox only ?

Ques- Why selenium is used in Firefox only ?
Ans- By asking this question, interviewer meant is that why selenium is not required .exe driver file while others browsers required .exe file.
So the answer what i suggest is 'Selenium has been developed in such a way(architecture) that by default it support firefox browser because all the versions of selenium are being updated by considering FF versions while for other browser we need to set the System property and need to use .exe driver file.'

Not sure, there could be better ans than this.

Monday, June 9, 2014

While Reviewing Automation Scripts what are the points which one should keep in mind ?

1. Scripts executing without any exception?
2. All steps are automated?
3. Coding standards are followed?

4. Methods are used instead of repeating steps?
5. Data is taken form excel instead of hardcoded values?
6. In line comments are provided ?

Sunday, June 8, 2014

What is the need of using STAF(Software Automation Test Framework) ?

Automation Framework is a set of guidelines like coding standards , test-data handling , object repository treatment  etc... which when followed during automation scripting produce beneficial outcomes like increase code re-usage ,  higher portability  , reduced script maintenance cost  etc. Mind you these are just guidelines and not rules; they are not mandatory and you can still script without following the guidelines. But you will miss out on the advantages of having a Framework. So its always best practice to have good framework.

Thursday, June 5, 2014

Tell me about yourself

Note- Here i am giving my introduction so you can change accordingly. Please don't tell mine. :P ;)

Tell me about yourself-
Ans- Hello Name/Sir/Mam, my name is Sanjay Kumar, I am from Mahoba Uttar Pradesh. I have completed B-tech from HBTI Kanpur with 76% in 2011. Then I joined IBM as campus hire in Noida in July 2011. there I got the training and then got the project in Bangalore and from then I am working in IBM..
Currently I am working in ABC(tell full Name of  the Project) which is an IBM internal project. And our client is ABCD(tell full name of the client).
(Then tell about your Project in brief)
ABC(Project Name), the world's largest IT financier, has an asset base of nearly $31 billion and delivers financial services to 125,000 customers in more than 40 countries.
ABC Project manages the financing contracts and financed assets of IBM. It enables customers of IBM machines to prepare financing proposals for all business transactions like New Lease, New Loan, Mid-Lease, End of Lease etc. This system has features for Contract management, Billing Invoice generation and Accounting.
The Custom Development Team adds new functionalities to the system on a regular basis and 1 major release is implemented every year. Also, the team sets up and installs the customized version of the system for new countries with which client wants to do business.
Currently I am working in the AB(name of your team or functionality) functionality. AB is a web interface, where entitled Customers can make or view Decisions on the End of Lease of their Assets which are on the verge of End of Lease with A(client Name). Besides, during the Lease period, Customer can view details of the Assets/Leases.

(Then tell)
Roles and Responsibilities:  
  1.     Identify Test cases for Automation.
  2.     Developing methods for repeating steps.
  3.     Writing scripts, executing test cases and debugging.
  4.     Prepare automation scripts in Selenium WebDriver.
  5.     Designing Automation Framework and Implementing Automation Framework.
  6.     Regression Testing, support and reviewing Test scripts.
  7.     Data driving Test script.
  8.     Defect reporting, Executing Framework and Analyzing Result.
  9.     Preparing script execution report.
  10.     Responsible for guiding juniors.
Note: Again requesting you please tell your Project description above is just for reference. This all info is just a thought which i made for reference for everyone so that one can understand how to tell in interview.

Roles and Responsibilities

Roles and Responsibilities: (Tell according to yours)
  • Identify Test cases for Automation.
  • Developing methods for repeating steps.
  • Writing scripts, executing test cases and debugging.
  • Prepare automation scripts in Selenium WebDriver.
  • Designing Automation Framework and Implementing Automation Framework.
  • Regression Testing, support and reviewing Test scripts.
  • Data driving Test script.
  • Defect reporting, Executing Framework and Analyzing Result.
  • Preparing script execution report.
  • Responsible for guiding juniors.

SDLC (Software development life cycle)

SDLC-(Software development life cycle)- SDLC are the different stages of developing a software or it is a step by step procedure to develop a s/w.
1-Requirement → 2-Feasibility study → 3-design (high level design, low level design) → 4-coding → 5-testing → 6-installation/deployment → 7-Maintenance.
1-Requirement- in this stage the complete needs of a customer will be collected in the form of requirement document.
2-Feasibility Study- in this phase based on requirement it is analysed whether the project is feasible or doable wrt time, cost, resources and technology. All imp people like finance dept, HR, architect, BA and PM will do the feasibility study.
3-Design- in this phase a blueprint of the requirement is developed in the form of HLD or LLD.
4-Coding- Once design is completed a set of people known as developers will start writing the code or programs according to requirements.
5-Testing- once coding is completed i.e. an application is developed it should be tested if it is working according to the requirements or not. This process of testing the application according to the requirement is called as testing and this task is performed by test engineer.
6-Installation- Once the application is tested, developed and stable it should be installed at customer place.
7-Maintenance- Once the application is installed at the customer place it is possible that they may face some issues and these issues may be fixed immediately by the company by giving them support for certain period of time. This phase is called as Maintenance.

What are the challenges you faced ?

What are the challenges you faced : 1- sometime developers were not accepting the bug then I have to show them in meeting and had to give them demo of bug.
2- sometime I got inconsistent bug, its changing everytime. Then it was very difficult me to show them then I have taken executed the same testcase many times and took the screenshot of all the scenarios and shown them to developers.
3- In the 1st release when I joined customer was asking very frequently changes.

STLC-(Software test life cycle)

STLC-(Software test life cycle)-
It is a step by step procedure to test a software. It consists of all the different phases or stages of testing the application and it is a part of SDLC. It consists of various phases-
System Study → Test Plan → Test Cases → RTM/CRM → Test Execution → Defect Tracking → Test Execution Report → Closure.
Test Cases → System Study → write the test scenario → write TC's → TC review → fix review comments → TC approval → store in TC repository.

Agile Methodolgy

Agile development model is also a type of Incremental model. Software is developed in incremental, rapid cycles. This results in small incremental releases with each release building on previous functionality.
Advantages- Customer satisfaction by rapid, continuous delivery of the useful softwares. People interact with each other much. Face-to-face conversation is the best form of communication. Continuous attention to technical excellence and good design.
Disadvantages- In case of some software deliverables, especially the large ones, it is difficult to assess the effort required at the beginning of the software development life cycle.
There is lack of emphasis on necessary designing and documentation.

Wednesday, June 4, 2014

How to clear the text from the text box without using clear() method.

There could be many ways to do this.

1) Use Control+a then backspace-

Example-

import java.util.Scanner;

import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;

public class Clear {
    public static void main(String[] args) throws InterruptedException {
        Scanner in = new Scanner(System.in);
        System.out.println("enter the string which you want to send and then clean");
        String input = in.next();
        WebDriver driver = new FirefoxDriver();
        driver.get("https://www.google.co.in/?gfe_rd=cr&ei=zQmQU9D3OoyK8QfpxoDQBA&gws_rd=ssl");
        WebElement box = driver.findElement(By.name("q"));
        box.sendKeys(input);
        Thread.sleep(5000); //simply wait to see that input string has been sent to box
       
        //this for block is used to clear the input from box
        //this we can do by using clear method but clear sometime won't work so use this way
        //box.clear();
        box.sendKeys(Keys.chord(Keys.CONTROL,"a"));
        box.sendKeys(Keys.BACK_SPACE);
    }
}   

2) Press the backspace key but here the number of times backspace key pressed should be equal to the number of character in the string because backspace will clear one character in one press.

import java.util.Scanner;

import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;

public class Clear {
    public static void main(String[] args) throws InterruptedException {
        Scanner in = new Scanner(System.in);
        System.out.println("enter the string which you want to send and then clean");
        String input = in.next();
        WebDriver driver = new FirefoxDriver();
        driver.get("https://www.google.co.in/?gfe_rd=cr&ei=zQmQU9D3OoyK8QfpxoDQBA&gws_rd=ssl");
        WebElement box = driver.findElement(By.name("q"));
        box.sendKeys(input);
        Thread.sleep(5000); //simply wait to see that input string has been sent to box
      
        //this for block is used to clear the input from box
        //this we can do by using clear method but clear sometime won't work so use this way
        //box.clear();
        for(int i=0; i<input.length();i++){
            box.sendKeys(Keys.BACK_SPACE);
        }
    }
}  


How to double click on a webelement and how to get the number of frames in a web page.

Ques1- How to find how many iframes are present in one page?
Ans-  List<WebElement> frames = driver.findElements(By.tagName("iframe"));
int numOfFrame = frames.size();

Ques2- How to handle double click on webdriver?
Ans-  use Actions class.
Actions act = new Actions(driver);
act.moveToElement(webElement).doubleClick().perform();

Sunday, May 25, 2014

write a program so that whenever you create a object, you will get to know how many object u have created.

public class ObjectCount {
    static int numOfObj;
    ObjectCount(){
        numOfObj = numOfObj+1;
        System.out.println("Total Number of object created: "+numOfObj);
    }
    public static void main(String[] args) {
        ObjectCount obj1 = new ObjectCount();
        ObjectCount obj2 = new ObjectCount();
        ObjectCount obj3 = new ObjectCount();
    }
}

Friday, May 23, 2014

How to login in linkedIn

Note- After login, 1st move cursor over Connections then click on Add Connections.

import java.util.Scanner;
import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.interactions.Actions;

public class LinkedIn {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        System.out.println("enter ur user id: ");
        String userId = in.nextLine();
        System.out.println("enter ur pass: ");
        String pass = in.nextLine();
     
        WebDriver driver = new FirefoxDriver();
        driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
        driver.get("http://www.linkedin.com/?trk=nav_logo");
        //login
        driver.findElement(By.id("session_key-login")).sendKeys(userId);
        driver.findElement(By.id("session_password-login")).sendKeys(pass);
        Actions act = new Actions(driver);
        WebElement sign = driver.findElement(By.id("signin"));
        act.moveToElement(sign).doubleClick().perform();
     
        //1st move cursor over Connections then click on Add Connections
      
        WebElement network = driver.findElement(By.xpath("//li[@class='nav-item']/a[contains(text(),'Connections')]"));
        act.moveToElement(network).perform();
        driver.findElement(By.xpath("//ul[@class='sub-nav']//a[contains(text(),'Add Connections')]")).click();
      
        //signout
        WebElement img = driver.findElement(By.xpath("//img[@class='img-defer nav-profile-photo']"));
        act.moveToElement(img).perform();
        WebElement signOut = driver.findElement(By.xpath("//a[contains(text(),'Sign Out')]"));
        act.moveToElement(signOut).click().perform();
      
        driver.quit();
    }
}

How do you handle https website in selenium ?

Ans- By changing the setting of FirefoxProfile.
 
ex-
public class HTTPSSecuredConnection {
            public static void main(String[] args){
                        FirefoxProfile profile = new FirefoxProfile();
                        profile.setAcceptUntrustedCertificates(false);
                        WebDriver driver = new FirefoxDriver(profile);
                        driver.get("https://184.106.253.74");
}
}

Automation Test Life Cycle (ATLC)


Following steps are followed in an Automation Process

Test Tool Selection
→ Define scope of automation
→ Planning, Design and development
→ Test Execution
→ Maintenance.

Test tool selection
Test Tool selection largely depends on the technology the Application Under Test is built on. For instance QTP does not support Informatica. So QTP cannot be used for testing Informatica applications. It's a good idea to conduct Proof of Concept of Tool on AUT.

Define the scope of Automation
Scope of automation is the area of your Application Under Test which will be automated. Following points help determine scope:
1. Feature that are important for the business
2. Scenarios which have large amount of data
3. Common functionalities across applications
4. Technical feasibility
5. Extent to which business components are reused
6. Complexity of test cases
7. Ability to use the same test cases for cross browser testing

Planning, Design and Development
During this phase you create Automation strategy & plan, which contains following details-
Automation tools selected
Framework design and its features
In-Scope and Out-of-scope items of automation
Automation test bed preparation
Schedule and Timeline of scripting and execution
Deliverables of automation testing

Test Execution
Automation Scripts are executed during this phase. The scripts need input test data before there are set to run. Once executed they provide detailed test reports.

Execution can be performed using the automation tool directly or through the Test Management tool which will invoke the automation tool.

Example: Quality center is the Test Management tool which in turn it will invoke QTP for execution of automation scripts. Scripts can be executed in a single machine or a group of machines. The execution can be done during night , to save time.

Maintenance

As new functionalities are added to the System Under Test with successive cycles, Automation Scripts need to be added, reviewed and maintained for each release cycle. Maintenance becomes necessary to improve effectiveness of Automation Scripts.


How to count the number of checkboxes checked in selenium webdriver ? or How to select multiple check box and verify ?

Note- Here 1st alternative checkbox has been selected, then it has been verified that which checkbox is selected and which is not selected.

import java.util.List;
import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;

public class MultipleCheckBox {
    public static void main(String[] args) {
        WebDriver driver = new FirefoxDriver();
        driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
        driver.get("http://www.gsmarena.com/samsung-phones-9.php");
        List<WebElement> checkBoxes = driver.findElements(By.xpath("//input[@type='Checkbox']"));
        for(int i=0; i<checkBoxes.size(); i=i+2){
            checkBoxes.get(i).click();
        }
        int checkedCount=0, uncheckedCount=0;
        for(int i=0; i<checkBoxes.size(); i++){
            System.out.println(i+" checkbox is selected "+checkBoxes.get(i).isSelected());
            if(checkBoxes.get(i).isSelected()){
                checkedCount++;
            }else{
                uncheckedCount++;
            }
        }
        System.out.println("number of selected checkbox: "+checkedCount);
        System.out.println("number of unselected checkbox: "+uncheckedCount);
    }
}



output-
0 checkbox is selected true
1 checkbox is selected false
2 checkbox is selected true
3 checkbox is selected false
4 checkbox is selected true
5 checkbox is selected false
6 checkbox is selected true
7 checkbox is selected false
8 checkbox is selected true
9 checkbox is selected false
number of selected checkbox: 5
number of unselected checkbox: 5