Monday, June 16, 2014

Print the name of the people in the gmail chatbox list and number of people in the gmail chat box in lefthand side. Realtime scenario.

import java.util.List;
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.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;

public class GmailChatBox {
  
WebDriver driver;

@BeforeTest
public void openurl()throws InterruptedException
{
    Scanner in = new Scanner(System.in);
    System.out.println("Enter the gmail id: ");
    String emailId = in.next();
    System.out.println("Enter the pass: ");
    String pass = in.next();
  
    driver = new FirefoxDriver(); //open firefox browser
  
    //login to gmail
    driver.get("http://www.gmail.com");
    driver.manage().window().maximize();
    driver.manage().timeouts().implicitlyWait(40,TimeUnit.SECONDS);
    driver.findElement(By.name("Email")).sendKeys(emailId);
    driver.findElement(By.name("Passwd")).sendKeys(pass);
    driver.findElement(By.name("signIn")).click();
}
@Test
public void chatlist() throws InterruptedException
{
    List<WebElement> chatboxsize = driver.findElements(By.xpath("//table[@class='vH']/tbody"));
    System.out.println("number of people in the gmail chat: "+chatboxsize.size());
    String name="";
    for (int i=1; i <=chatboxsize.size(); i++)
    {
        name = driver.findElement(By.xpath("//table[@class='vH']/tbody["+i+"]/tr[1]//span[1]")).getAttribute("textContent");
        System.out.println(name);
    }
}
@AfterTest
public void closeBrowser(){
    driver.close();
}
}

Saturday, June 14, 2014

Use of getAttribute() method.

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

public class Google {
    public static void main(String[] args) {
        WebDriver driver = new FirefoxDriver();
        driver.get("https://www.google.co.in/");
        String title = driver.findElement(By.xpath("//div[@id='hplogo']/a/img")).getAttribute("title");
        System.out.println(title);
        driver.close();
    }
}

Use of Actions class

public class ClickCnChildMenu{
    public static void main(String[] args) {
        WebDriver driver=new FirefoxDriver();
        driver.get("http://new.mypomanager.com/Account/Login");
        driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
        driver.manage().window().maximize();
        driver.findElement(By.id("UserName")).sendKeys("retaileradmin");
        driver.findElement(By.id("Password")).sendKeys("password");
        driver.findElement(By.cssSelector("input[type='submit']")).click();
        WebElement parentmenu=driver.findElement(By.linkText("RETAILER"));
        Actions act=new Actions(driver);
        act.moveToElement(parentmenu).perform();
        WebElement createPO = driver.findElement(By.xpath("//a[contains(text(),'Create PO')]"));
        act.moveToElement(createPO).click().perform();
       
        }
}

Friday, June 13, 2014

Manual Test cases for Pen.

Manual Test cases for Pen.

Manual Test cases for Pen.

Write Test Cases of Pen
Start from here- 1st we need to understand the requirement against which pen was created. Our test scenarios should be based on these factors like – type of pen (ball point, ink or felt tip), functionality of the pen, Compatibility, installation and un-installation, performance and usability. Since I don't have requirement for pen to be tested, I presume the pen being tested is used by normal people and it would be used for their day to day writing needs and not somebody like an astronaut in space with 0 gravity or a deep sea diver who wants to write underwater.
Test cases of pen are given below: -

But keep one thing in mind that test cases for pen may vary if you have different requirements or set of requirements.

Below is given different test cases of pen which does not contain any requirements or specifications?

Test cases of pen are like that:

1. Verify the color of the pen.
2. Check GUI testing means logo of the pen maker.
3. Check Usability testing means grip of the pen.
4. Verify whether the pen is ballpoint pen or ink pen.
5. Check Integration testing means cap of the pen should easily fit beside the body of the pen.
6. Check pen should be continuously in writing mode.

Some Functional test cases for pen:

1. Check whether it writes on paper or not.

2. Verify whether the ink on the paper is belongs with the similar color as what we see in the refill.

Performance and load test cases for pen:

1. Verify how it performs when writing on wet paper.

2. Verify how it performs when writing on rough paper.

3. Verify how it performs when writing on hand because we occasionally do that

4. Check load test means when pen is pressed very hard against the tough surface then pen refill should not come out of the pen.

Negative test cases about pen:

1. Verify whether ink is available or not.

2. Check if ink is available, than the pen does not write on the paper.

3. Verify by bend the refill at multiple ends and then try to write with it.

4. Verify by dip the pen always in to the water and then write it again.

5. Check whether it write on leaves or not.

Additional test cases for pen:

1. Check usability testing means test by writing on a section of paper, Examine if you can write smoothly. It should not be writing and stopping among (with) breaks.

2. Check capability or reliability testing means Test the writing capacity (the amount of writing that is possible from a single refill) of the pen.

3. Check Robustness testing means Test wherever you can carry the pen in to your shirt and pent pocket using its cap. The cap distension should be solid enough to grip your pocket.

4. Check Compatibility testing means Test by writing on distinct types of surfaces like: rough paper, packing material, glass, leather, cotton, wood, plastic, metals like aluminum or iron, polythene sheet etc.

How to check String array is sorted or not ?

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class SortString {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        System.out.println("Enter the inputs name and when you want to check then enter 'check' : ");
        List<String> input = new ArrayList<String>();
       
        int i =0, j=0;
        while(true){
            String name = in.next();
            if(name.equals("check")){
                break;
            }
            input.add(name);
        }
        for(; i<input.size()-1; i++){
            if(input.get(i).compareToIgnoreCase(input.get(i+1))>0){
                System.out.println("string arrary is not sorted in ascending order.");
                for(; j<input.size()-1; j++){
                    if(input.get(j).compareToIgnoreCase(input.get(j+1))<0){
                        System.out.println("string arrary is not sorted in descending order.");
                        break;
                    }
                }
                if(j==input.size()-1){
                    System.out.println("String array is sroted in descending order");
                }
                break;
            }
        }
        if(i==input.size()-1){
            System.out.println("String array is in ascending order");
        }
    }
}


Output
Enter the inputs name and when you want to check then enter 'check' :
abc
dfs
def
check
string arrary is not sorted in ascending order.
string arrary is not sorted in descending order.

OutputEnter the inputs name and when you want to check then enter 'check' :
abc
bbc
cbc
check
String array is in ascending order

OutputEnter the inputs name and when you want to check then enter 'check' :
Cbc
bBc
Abc
check
string arrary is not sorted in ascending order.
String array is sroted in descending order

Identify a number is well ordered or not ?

Note- A number is well ordered if all digits are in ascending order ex- 123456789.
Not well ordered number - ex- 2341 (because here 1 is coming after 4 so it is not well ordered.)


Code-

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

public class NumWellOrbered {
    public static void main(String[] args) {
        System.out.print("Enter a number: ");
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int r=0, s=n, j=0;
        List<Integer> num = new ArrayList<Integer>();
        while(s!=0){
            r = s%10;
            s = s/10;
            num.add(r);
        }
       
        for(j=(num.size()-1); j>0; j--){
            if(num.get(j)>num.get(j-1)){
                System.out.println("Number "+n+" is not well ordered");
                break;
            }
        }
        if(j==0){
            System.out.println("Number "+n+" is well ordered");
        }
    }
}


Output 1-
Enter a number: 5436
Number 5436 is not well ordered

Output 2-
Enter a number: 456789
Number 456789 is well ordered

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.