Saturday 28 September 2013

Selenium web driver click Google search & find Number Of href Links In That Page.

package learing;

import java.util.List;

import org.openqa.selenium.By;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;

import org.openqa.selenium.support.ui.ExpectedConditions;

import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.WebDriverWait;

public class Googlenth {


public static void main(String[] args) {

    WebDriver driver = new FirefoxDriver();
    driver.get("http://www.google.com");
    WebElement element = driver.findElement(By.name("q"));
    element.sendKeys("Cheese!\n"); // send also a "\n"
    element.submit();

    // wait until the google page shows the result
    WebElement myDynamicElement = (new WebDriverWait(driver, 10))
              .until(ExpectedConditions.presenceOfElementLocated(By.id("resultStats")));

    List<WebElement> findElements = driver.findElements(By.xpath("//*[@id='rso']//h3/a"));

    // this are all the links you like to visit
    for (WebElement webElement : findElements)
    {
        System.out.println(webElement.getAttribute("href"));
    }
}
}

How to click on elements in i frame using Selenium web driver?

package learing;

import java.util.List;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;


public class IframeTest {

  public static void main(String[] args) throws InterruptedException {

  WebDriver driver = new FirefoxDriver();
  driver.manage().window().maximize();

  driver.get("http://tinyurl.com/cb3lbho");
  Thread.sleep(5000L);

  try {

    List<WebElement> AlliFrameID = driver.findElements(By.tagName("iframe"));
   System.out.println(AlliFrameID.size());
   for(int i=0;i<=AlliFrameID.size();i++){
    System.out.println(AlliFrameID.get(i).getAttribute("id"));
   }
  } catch (Exception e) {

 driver.switchTo().frame("ifrm");

 driver.findElement(By.xpath("//*[@id='ifrmTest']/p[2]/input")).click();
   System.out.println(driver.findElement(By.xpath("//*[@id='ifrmTest']/p[1]/input")).getAttribute("value"));

   driver.findElement(By.xpath("//*[@id='ifrmTest']/p[3]/input")).click();
    System.out.println(driver.findElement(By.xpath("//*[@id='ifrmTest']/p[1]/input")).getAttribute("value"));


   driver.findElement(By.xpath("//*[@id='ifrmTest']/p[3]/input")).click();
   System.out.println(driver.findElement(By.xpath("//*[@id='ifrmTest']/p[1]/input")).getAttribute("value"));

   driver.findElement(By.xpath("//*[@id='ifrmTest']/p[3]/input")).click();
    System.out.println(driver.findElement(By.xpath("//*[@id='ifrmTest']/p[1]/input")).getAttribute("value"));


   driver.switchTo().defaultContent();
     driver.findElement(By.xpath("//*[@id='testForm']/p/input[1]")).sendKeys("Online selenium Training");

     driver.findElement(By.xpath("//*[@id='testForm']/p/input[2]")).click();

   }

  }

}

Capture Screenshot of Web Page In Selenium WebDriver

Most of the time we think to Capture Screenshot in WebDriver when some kind of error or exception surfaces while practicing testing, to resolve the same WebDriver has provided us one  interface TakesScreenshot  for capturing the screenshot of web application and This interface provides one method names as getScreenshotAs() to capture screenshot in instance of driver. This getScreenshotAs() method takes argument of type OutputType.File or OutputType.BASE64 or Output.BYTES. So that it could return captured  screenshot in File type, or Base 64 string type or in raw bytes.
So this would look like this
For File type
File scrnshot= ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
For Base64 string above code would be like
((TakesScreenshot)driver).getScreenshotAs(OutputType.BASE64);
For BYTES
((TakesScreenshot)driver).getScreenshotAs(OutputType.BYTES);
We have taken the screenshot with the help of getScreenshotsAs() method and  and now its time to copy this file somewhere in our file system or in our desktop. So for this purpose we further use copyFile() method of the FileUtils class from theorg.apache.commons.io.FileUtils class.
Placing file in file system by using this line
FileUtils.copyFile(scrFile, new File(“e:\\main_page.png”));
As I have told you that copyFile is a method of Class FileUtils and to call this method we need to write class.method() and in above code copyFile is taking argument from getScreenShotsAs() and new location where we want to save this captured Screenshot with name and with extension.
Now we would use write small running code that would open Google page and it would take a snap shot and that snap shot would be saved as google.png in my e:\ driver. One thing we need to remember whenever we work with File system or java.io then chances of exception is more so we would use try and catch in our code.

import java.io.File;
import org.apache.commons.io.FileUtils;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
public class Chrome {
WebDriver driver;
@BeforeMethod
public void launchChrome()
{

driver = new FirefoxDriver();
driver.get("http://google.co.in");
}
@Test
public void googleScreenshot()
{
try {
  File scrnsht =((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
  FileUtils.copyFile(scrnsht, new File("e:\\google_page.png"));
} catch (Exception e) {
e.printStackTrace();
}
}
@AfterTest
public void kill()
{
driver.close();
}
}

Tuesday 17 September 2013

OLD AND NEW SDLC MODELS

Old SDLC (Software Development Life Cycle) Models:

a) Waterfall model or Linear sequential model

b)Prototype model
c) Incremental model
d)Spiral model
e) Rapid application development (RAD) model 

Before learning the waterfall model let you know about:

Software bidding: A proposal to develop a new software is called as 'software bidding'
·         If a proposal came from the customer point of view then it is called as "software project bidding".
·         If a company will study the needs of the market and develop the software then that type of proposal is called as "software product bidding"
a) Waterfall Model:
                                       
waterfall model
                                          
                                              Fig: Waterfall Model

Note: The above waterfall model is also called as the "Linear Sequential Model"

Explanation of above diagram:
1.    From the above diagram at first software bidding will be done between the CEO of company and customer or client. Then after bidding, the CEO will conduct the meeting with all the project managers(PM) in the company called as "kick of meeting"(KIM). 
2.    In that meeting  CEO will make an announcement about that new project to handle that project any one of the project manager will be selected.Then that project manager will give an project initiation note(PIN) to CEO.
3.     Then PM will assign the work to the business analyst(BA) to gather all the requirements from the customer.
4.    Then BA will submit all the gathered requirements to the system analyst(SA) to design inorder to do the analysis or detailed planning which is going to submit it to the PM.Then PM will approve that planning done by SA. 
5.    Then SA will submit that document to the technical architect(TA). 
6.    Then designers will do the design which consists of HLD and LLD's.
7.    Based on that design programmers will do the coding and that corresponding programmers will test the developed code. 
8.    Then after testing that  s/w few programmers will be selected for onsite and release the s/w. 
9.    Then change for control board(CCB) people will do the maintenance/support of that s/w.                 
b) Prototype Model: 
Whenever the customer requirements are not clear, organizations can goto develop a model software to show to customers and to get clear requirements.This sample software is called as "prototype".
                                                     
prototype model
                                         
                                           
                                           Fig: Prototype model
Explanation of above diagram:
1.    From the above diagram at first software bidding will be done between the CEO of company and customer or client. Then after bidding, the CEO will conduct the meeting with all the project managers(PM) in the company called as "kick of meeting"(KIM).
2.     In that meeting  CEO will make an announcement about that new project, to handle that project any one of the project manager will be selected.Then that project manager will give an project initiation note(PIN) to CEO. 
3.    Then PM will assign the work to the business analyst(BA) to gather all the requirements from the customer.If customer requirements are not clear then company will develop a model s/w and show to the customer. At that time customer will identify the new requirements and those requirements will be gathered by BA.
4.    Then BA will submit all the gathered requirements to the system analyst (SA) inorder to do the analysis or detailed planning which is going to submit it to the PM.Then PM will approve that planning done by SA. 
5.    Then SA will submit that document to the technical architect(TA). 
6.    Then designers will do the design which consists of HLD and LLD's.
7.    Based on that design, programmers will do the coding and that corresponding programmers will test the developed code. 
8.    Then after testing that  s/w, few programmers will be selected for onsite and release the s/w. Then change for control board(CCB) people will do the maintenance/support of that s/w.
c) Incremental Model: 
When customer requirements are clear but, huge.Then the organizations can follow the incremental model to release the  software installment by installment.
incremental model
Fig: Incremental model

1.    From the above diagram in the first installment (i #1) all the process from the software requirement gathering(SRG) to maintenance will be done and this will be proceeded  upto last installment (i # N). 
2.    Thus finally all the huge requirement software will be developed and released to the customer installment by installment.
d) Spiral Model:
When the requirements are clear and enhancing regularly, organizations can follow spiral model to release the software version by version.
spiral model
                                                                Fig: Spiral Model
1.    From the above diagram requirement gathering will be done at first and later design this will be continued till the maintenance stage.
2.    If customer will need any enhancements, those enhancements will be gathered by them and again with the new requirements, analysis will be done. This cycle will be repeated for every new version of the software.
e) Rapid Application Development (RAD) Model:

1.    Organizations are following this Model, when Customer Requirements are known.
  
2.    When customer requirements are similar to old projects, then organizations can follow this model to develop a new software by copying coding from old projects and they will r
 elease new Software using existing Software Coding.
3.     Here, New Software will be integrated by using Existing Components of Old Projects

5.What  are Advanced SDLC Models?
(ANS):

Advanced SDLC (Software Development Life Cycle) Models:

Before going to learn the Advanced SDLC models, let you know the reasons for 

outdating the old SDLC models in the organizations.They are:
1. In all the Old SDLC Models, Testing Stage comes after Coding only.
2. This Single Stage of Testing is conducted by the Same Programmers / Developers who perform Coding.
3. Due to this, Organizations are not able to release Quality Software to Customer or to Market.
4. To Develop and Release Quality Software, Organizations are following New SDLC Models.
5. In New SDLC Models, Organizations conduct Multiple Stages of Testing and maintain Separate Testing Teams. The new SDLC models are as follows:

a) Fish Model

b) V-Model
c) Agile Model(XP,SPRINT,SCRUM)

a)
 Fish Model:

To develop a quality s/w w.r.t to customer requirements and expectations,organizations  are following fish model.But, this model is costly to follow

and time consuming model.

Explanation of above diagram:
fish model
                                                                     Fig: Fish Model
1.    At first project initiation note(PIN) will be given to the CEO,from there the work is going to begin.
2.    The business analyst(BA) will gather all the requirements from the customer and for that gathered requirements testing purpose a 'seperate testing team' will be assigned.
3.    Then system analyst(SA) will do the analysis of that requirements and for the review of those analysed requirements a 'seperate testing team' will be assigned.
4.    Technical architect (s.r programmer) will do the design of those analysed requirements in the form of HLD and LLD's after that a 'seperate testing team' will be assigned for the review of those design. 
5.    All the above conducted testing or reviewing is called as 'documents testing' or 'verification' or 'static testing'.
6.    Unit testing: unit testing means that conducting testing on a single programme in java, .NET,oracle,SAP,C,C++ and etc.
7.    Integration testing: Integration testing means conducting testing on the interconnection of two or more programmes.The below diagram depicts the integration testing: 
http://2.bp.blogspot.com/-6gCPjruApyM/UOx8Ozh-SgI/AAAAAAAAAA0/f0tX8Sosg4s/s1600/Integration+Testing+www.softwaretestinghome.com.jpg

8.       Software testing: software testing means conducting the testing on a complete   
          software w.r.t to the customer requirements and expectations.
9.      Acceptance testing: Acceptance testing means that collecting the feedback on 
         s/w from the real customers(Clients) or model customers(Public).
10.     Release testing: Release testing means that the whether s/w was completely and          
           correctly ported into customer site or not. It is also called as onsite testing/
           delivery testing/port testing.
11.    Maintenance testing: During the maintenance testing, CCB people can modify 
         and test s/w w.r.t to customer change request.        



b) V-Model: 
·         This model was introduced by "William evans ferrie".
·         'V' stands for verification and validation.
·         This model is also defining mapping in between development stages and testing stages.
·         This model is not taking more time to develop a quality s/w unlike  Fish model.
v model
                                                                 Fig: V-Model
Explanation of above diagram:
1.    From the above model BA can prepare and review BRS.
2.    SA can prepare and review SRS.
3.    TA can prepare and review HLD and LLD's.
4.    Programmer can write programmes and conduct unit testing and integration testing w.r.t  LLD's and integration testing w.r.t HLD.
5.    A seperate testing team can test s/w (system testing) w.r.t SRS.
6.    Customer site people can provide feedback on s/w w.r.t BRS.
7.    Release team will take care of s/w release and port testing and CCB people can take care of maintenance/support.
Note: From the V-model, a separate test engineers will be needed for s/w testing stage.Those test engineers also responsible for involve in the acceptance testing and release testing.
Note: Small and medium scale companies prefer V-model to follow because this model is inexpensive and not taking more time.

c)
 Agile Model: In large scale companies,this model is followable.Because, client is able to maintain stakeholder team to approve deliverables of each stage in development.
http://2.bp.blogspot.com/-jecNYe1mW8k/UOyAgQANkCI/AAAAAAAAABE/xDfSGwrIenc/s1600/agile+model+www.softwaretestinghome.com.jpg

After completion of software testing and approval from the stakeholders, real customers are involving to give the feedback on that software.

Under the guidence of stakeholders,release  team can release software and CCB can maintain software.
In agile model development stages will be called with different names:
http://1.bp.blogspot.com/-EB7Zmocg7Gw/UOyAo6ymI6I/AAAAAAAAABM/7q0uvp0UoyU/s1600/agaile+model+1+www.softwaretestinghome.com.jpg

Note: In old SDLC models, testing will come after coding only. But, in advanced SDLC models testing will come in every stage of development by same developer or separate tester.

Old SDLC models with V-Model: 
 Prototype V-Model:
·         When customer requirements are clear, organizations are following v-model by conducting testing in every stage of development and separate testing team for software testing stage.
·         When customer requirements are not clear, organizations will follow prototype   V-model.
http://3.bp.blogspot.com/-VDMg-nRDENc/UOyA-mAZo3I/AAAAAAAAABU/7GnhBYpo9Nc/s1600/prototype+v+model+www.softwaretestinghome.com.jpg

·         Once requirements are finalized, again same V-model will proceeds.  
Incremental V-Model:
When customer requirements are clear and huge, organizations’ can follow Incremental V-model.
http://2.bp.blogspot.com/-e5wXzgz7mds/UOyBHn8HlLI/AAAAAAAAABc/YxCO6XAQVos/s1600/incremental+v+model+www.softwaretestinghome.com.jpg

Spiral V-Model: 
When customer requirements are enhancing regularly, organizations’ can follow Spiral V-model.
http://2.bp.blogspot.com/-B5AG0zxTsQ8/UOyBRLSHtvI/AAAAAAAAABk/Gnpq7we0UtY/s1600/spiral+v+model+www.softwaretestinghome.com.jpg


Case Study:(Old SDLC under along with Agile Model)
When customer requirements are clear and customers are ready to provide stakeholders then organizations can follow the 'Agile model'.
1.    When customer requirements are not clear and customer is ready to provide stakeholders, organizations can follow prototype based agile model called as 'XP' (Extreme Programming).
2.    When customer requirements are huge and customer is ready to provide stakeholders, organizations can follow in based incremental based agile model called as 'SPRINT'.

3.    When customer requirements are enhancing regularly and customer is ready to provide stakeholders, organizations can follow spiral based agile model called as 'SCRUM'.

Angular JS Protractor Installation process - Tutorial Part 1

                     Protractor, formally known as E2E testing framework, is an open source functional automation framework designed spe...