Thursday, 26 November 2015

Read test data from xl sheet for gmail login

package interview;

import java.io.Console;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.util.concurrent.TimeUnit;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.ss.usermodel.WorkbookFactory;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.Assert;

import com.google.common.base.Verify;

public class Read_data_from_xl_POI
{
     static WebDriver d;
public static void main(String[] args) throws Exception {
   
    d=new FirefoxDriver();
    d.get("http://gmail.com");
   
    File src=new File("D:\\selenium_NEW_PRACTICE\\test_data\\read_excel_data_test.xls");
    FileInputStream fis=new FileInputStream(src);
    HSSFWorkbook wb= new HSSFWorkbook(fis);
    HSSFSheet sheet1=wb.getSheetAt(0);



//imp note: For xl file use : HSSF
//for .xlsx file use: XSSF
   
    int totalRowCount=sheet1.getLastRowNum();
    System.out.println("total rows is:" + totalRowCount);
   
    String firstRowName=sheet1.getRow(0).getCell(0).getStringCellValue();
    System.out.println("first row first column name is: " + firstRowName);
   
    String secondColFirstName=sheet1.getRow(0).getCell(1).getStringCellValue();
    System.out.println("first row first column name is: " + secondColFirstName);
   
    //for print all the rows usng for loop
   
    for(int i=0;i<totalRowCount;i++)
    {
        String userName=sheet1.getRow(i).getCell(0).getStringCellValue();
        System.out.println("first row all names:" + userName);
       
        String passwordName=sheet1.getRow(i).getCell(1).getStringCellValue();
        System.out.println("first row all names:" + passwordName);
       

/*d=new FirefoxDriver();
d.get("http://gmail.com");*/
d.manage().window().maximize();
d.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);
d.findElement(By.xpath("//*[@id='Email']")).sendKeys(userName);
d.findElement(By.xpath("//*[@id='next']")).click();

d.findElement(By.xpath("//*[@id='Passwd']")).sendKeys(passwordName);
d.findElement(By.xpath("//*[@id='signIn']")).click();
String actErrorMsg=d.findElement(By.xpath("//*[@id='errormsg_0_Passwd']")).getText();
String expErrorMsg="The email and password you entered don't match.";
System.out.println("actual message is: " +actErrorMsg);

//Assert.assertEquals("The email and password you entered don't match.", actErrorMsg);

if(expErrorMsg.contains(actErrorMsg))
        {
    System.out.println("sucess");
        }else
            System.out.println("not sucess");
d.navigate().back();

    }
}
}

Thursday, 19 November 2015

write code to select all the checkboxes

package interview;

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;
import org.testng.annotations.Test;

public class Writecodetoselectallthecheckboxes {
public static WebDriver d;
@Test
public static void checkallCheckBoxex()
{
    d=new FirefoxDriver();
    d.get("http://www.ironspider.ca/forms/checkradio.htm");
    d.manage().window().maximize();
    d.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);
   
    //Logic to print all checkboxes name and select all check boxes
    List<WebElement> checkBoxList =d.findElements(By.xpath("//*[@id='Content']/div[1]/blockquote[1]/form/input"));
    for(int i=0;i<checkBoxList.size();i++)
    {
        System.out.println(checkBoxList.get(i).getAttribute("value"));
        checkBoxList.get(i).click();
    }
   
   
}
}

Sunday, 1 November 2015

How to convert String to int

    String actUnioCount=compare.getUnionNodeCount();   
        int UnionCount=Integer.valueOf(actUnioCount);

Split the string between open bracket and close bracket () in java

Example string:
String text =Compare string (43)
Here, i want to print only 43.

Logic:
    String[] part1=text.split("\\(");
        String part2=part1[1];
        String count=part2.replace(")", "");
       
        return count;

How to compare string from arrayList to String in array


ArrayList<String> li=microRNA.getColumnName();
syso(li);

Here, my output:
"","ID","Symbol","Source","Confidence","Expression Pairing","Symbol","Entrez Gene Name","Disease","Location","Molecule Type","Pathway","Species","Tissue/Cell Line".

Want to compare above out put with
String[] headerList={"","ID","Symbol","Source","Confidence","Expression Pairing","Symbol","Entrez Gene Name","Disease","Location","Molecule Type","Pathway","Species","Tissue/Cell Line"};

Logic:
    for(int i=0;i<headerList.length;i++)
            {               
            System.out.println(headerList[i]);
            LoggingUtilities.verifyEquals("Verify Add to list for mRNA source types and verify the added molecules in List", headerList[i], li.get(i));
            }