package com.sl;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
public class GetListOrArrayRepresentation {
public static List<String> getValuesAsListFromExcel() {
List<String> columnValues = new ArrayList<>();
try {
FileInputStream excellFile = new FileInputStream(new File("E:\\Pro\\ExcelWork1\\inputExcel.xlsx"));
XSSFWorkbook workbook1 = new XSSFWorkbook(excellFile);
XSSFSheet mainSheet = workbook1.getSheetAt(1);
Row row = mainSheet.getRow(0);
Iterator<Cell> cells = row.cellIterator();
while (cells.hasNext()) {
columnValues.add(cells.next().getStringCellValue());
}
for(String x:columnValues){
System.out.println(x);
}
} catch (IOException e) {
}
return columnValues;
}
----------------------------------------------------------------------------------------------------------------
public static String[] getValuesAsArrayFromExcel() {
String[] outColumns = null;
try {
FileInputStream excellFile = new FileInputStream(new File("E:\\Pro\\ExcelWork1\\inputExcel.xlsx"));
XSSFWorkbook workbook1 = new XSSFWorkbook(excellFile);
XSSFSheet mainSheet = workbook1.getSheetAt(1);
Row row = mainSheet.getRow(0);
Iterator<Cell> cells = row.cellIterator();
List<String> columnValues = new ArrayList<>();
while (cells.hasNext()) {
columnValues.add(cells.next().getStringCellValue());
}
outColumns = columnValues.toArray(new String[columnValues.size()]);
for(String x:outColumns){
System.out.println(x);
}
} catch (IOException e) {
}
return outColumns;
}
public static void main(String[] args) {
getValuesAsArrayFromExcel();
}
}
---------------------------------------------------------------------------------
public List<String> getList() {
List<String> element = new ArrayList<>();
element.add("1");
element.add("2");
return element;
}
public void verifyDropDownValues() throws Throwable {
driver.findElement(By.xpath("//select[@id='day']")).click();
for (String text : getList()) {
String xpath = "//select[@id='day']/option[text()='%s']";
xpath = xpath.replaceFirst("%s", text);
String text2 = driver.findElement(By.xpath(xpath)).getText();
if (text2.equalsIgnoreCase(text)) {
System.out.println("Element exists" + text2);
} else {
System.out.println("Element do not exist" + text2);
}
}
}
-------------------------------------------------------------------
package runner;
import java.util.ArrayList;
import java.util.List;
public class Test {
public static List<Object> getList(){
ArrayList<Object> al= new ArrayList<>();
al.add("1");
al.add("2");
return al;
}
public static List<String> getStringList(){
List<String> a2=new ArrayList<>();
a2.add("1");
a2.add("2");
return a2;
}
public static void compare(){
if(getList().equals(getStringList()))
System.out.println("Equal");
else
System.out.println("Not Equal");
}
public static void main(String[] args) {
compare();
}
}
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
public class GetListOrArrayRepresentation {
public static List<String> getValuesAsListFromExcel() {
List<String> columnValues = new ArrayList<>();
try {
FileInputStream excellFile = new FileInputStream(new File("E:\\Pro\\ExcelWork1\\inputExcel.xlsx"));
XSSFWorkbook workbook1 = new XSSFWorkbook(excellFile);
XSSFSheet mainSheet = workbook1.getSheetAt(1);
Row row = mainSheet.getRow(0);
Iterator<Cell> cells = row.cellIterator();
while (cells.hasNext()) {
columnValues.add(cells.next().getStringCellValue());
}
for(String x:columnValues){
System.out.println(x);
}
} catch (IOException e) {
}
return columnValues;
}
----------------------------------------------------------------------------------------------------------------
public static String[] getValuesAsArrayFromExcel() {
String[] outColumns = null;
try {
FileInputStream excellFile = new FileInputStream(new File("E:\\Pro\\ExcelWork1\\inputExcel.xlsx"));
XSSFWorkbook workbook1 = new XSSFWorkbook(excellFile);
XSSFSheet mainSheet = workbook1.getSheetAt(1);
Row row = mainSheet.getRow(0);
Iterator<Cell> cells = row.cellIterator();
List<String> columnValues = new ArrayList<>();
while (cells.hasNext()) {
columnValues.add(cells.next().getStringCellValue());
}
outColumns = columnValues.toArray(new String[columnValues.size()]);
for(String x:outColumns){
System.out.println(x);
}
} catch (IOException e) {
}
return outColumns;
}
public static void main(String[] args) {
getValuesAsArrayFromExcel();
}
}
---------------------------------------------------------------------------------
public List<String> getList() {
List<String> element = new ArrayList<>();
element.add("1");
element.add("2");
return element;
}
public void verifyDropDownValues() throws Throwable {
driver.findElement(By.xpath("//select[@id='day']")).click();
for (String text : getList()) {
String xpath = "//select[@id='day']/option[text()='%s']";
xpath = xpath.replaceFirst("%s", text);
String text2 = driver.findElement(By.xpath(xpath)).getText();
if (text2.equalsIgnoreCase(text)) {
System.out.println("Element exists" + text2);
} else {
System.out.println("Element do not exist" + text2);
}
}
}
-------------------------------------------------------------------
package runner;
import java.util.ArrayList;
import java.util.List;
public class Test {
public static List<Object> getList(){
ArrayList<Object> al= new ArrayList<>();
al.add("1");
al.add("2");
return al;
}
public static List<String> getStringList(){
List<String> a2=new ArrayList<>();
a2.add("1");
a2.add("2");
return a2;
}
public static void compare(){
if(getList().equals(getStringList()))
System.out.println("Equal");
else
System.out.println("Not Equal");
}
public static void main(String[] args) {
compare();
}
}
No comments:
Post a Comment