使用 Java 和 sikuli 对 Excel 进行排序并粘贴到网页上
Sort Excel and paste it on webpage using Java and sikuli
我写了上面的代码,每次它都给我 "single" 作为输出。
import java.io.FileInputStream;
import java.io.IOException;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.xssf.usermodel.XSSFRow;
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.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.htmlunit.HtmlUnitDriver;
import org.sikuli.basics.Settings;
import org.sikuli.script.FindFailed;
import org.sikuli.script.Screen;
public class teste {
public static void main (String args[]) throws InterruptedException {
try {
// Open the Excel file
FileInputStream fis = new FileInputStream("C:\test.xls");
// Access the required test data sheet
HSSFWorkbook wb = new HSSFWorkbook(fis);
HSSFSheet sheet = wb.getSheetAt(3);
// Loop through all rows in the sheet
for(int count = 0;count<=sheet.getLastRowNum();count++) {
HSSFRow row = sheet.getRow(4);
HSSFCell cell = row.getCell(4);
System.out.println("Running test case " + cell.getStringCellValue().equalsIgnoreCase("uk"));
// Run the test for the current test data row
runTest(row.getCell(3).toString());
}
fis.close();
}
catch (IOException e) {
System.out.println("Test data file not found");
}
}
public static void runTest(String strSearchString) throws InterruptedException {
// Start a browser driver and navigate to Google
WebDriver driver = new FirefoxDriver();
//it will always open private profile
driver.get("http:\www.google.com");
//Using Sikuli
System.out.println("SCreeeeeen is apppearinggg...wait");
Thread.sleep(5000);
Screen s = new Screen();
Settings.OcrTextSearch = true;
try {
s.click("imgs/Search.png", 0);
System.out.println(strSearchString + " ppp ");
s.type(strSearchString);
s.doubleClick("imgs/GSearch.png", 0);
Thread.sleep(5000);
}
catch(FindFailed e){
e.printStackTrace();
}
Thread.sleep(1000);
driver.quit();
}
}
这是要排序的 Excel sheet,我卡在这里了,因为如果 excel 中的国家/地区列是英国,我需要搜索 "Type"或者我们。
在代码中,您似乎每次都使用同一行...
for(int count = 0;count<=sheet.getLastRowNum();count++){
HSSFRow row = sheet.getRow(4);
HSSFCell cell = row.getCell(4);
System.out.println("Running test case " + cell.getStringCellValue().equalsIgnoreCase("uk"));
对于每个循环,您将行值保持为 4 硬编码,它在整个循环中保持不变。
即对于 count = 0,
HSSFRow row = sheet.getRow(4);
和 count =1
又是HSSFRow row = sheet.getRow(4);
相反,您需要像
那样做
HSSFRow row = sheet.getRow(count);
试试这个...
我写了上面的代码,每次它都给我 "single" 作为输出。
import java.io.FileInputStream;
import java.io.IOException;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.xssf.usermodel.XSSFRow;
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.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.htmlunit.HtmlUnitDriver;
import org.sikuli.basics.Settings;
import org.sikuli.script.FindFailed;
import org.sikuli.script.Screen;
public class teste {
public static void main (String args[]) throws InterruptedException {
try {
// Open the Excel file
FileInputStream fis = new FileInputStream("C:\test.xls");
// Access the required test data sheet
HSSFWorkbook wb = new HSSFWorkbook(fis);
HSSFSheet sheet = wb.getSheetAt(3);
// Loop through all rows in the sheet
for(int count = 0;count<=sheet.getLastRowNum();count++) {
HSSFRow row = sheet.getRow(4);
HSSFCell cell = row.getCell(4);
System.out.println("Running test case " + cell.getStringCellValue().equalsIgnoreCase("uk"));
// Run the test for the current test data row
runTest(row.getCell(3).toString());
}
fis.close();
}
catch (IOException e) {
System.out.println("Test data file not found");
}
}
public static void runTest(String strSearchString) throws InterruptedException {
// Start a browser driver and navigate to Google
WebDriver driver = new FirefoxDriver();
//it will always open private profile
driver.get("http:\www.google.com");
//Using Sikuli
System.out.println("SCreeeeeen is apppearinggg...wait");
Thread.sleep(5000);
Screen s = new Screen();
Settings.OcrTextSearch = true;
try {
s.click("imgs/Search.png", 0);
System.out.println(strSearchString + " ppp ");
s.type(strSearchString);
s.doubleClick("imgs/GSearch.png", 0);
Thread.sleep(5000);
}
catch(FindFailed e){
e.printStackTrace();
}
Thread.sleep(1000);
driver.quit();
}
}
这是要排序的 Excel sheet,我卡在这里了,因为如果 excel 中的国家/地区列是英国,我需要搜索 "Type"或者我们。
在代码中,您似乎每次都使用同一行...
for(int count = 0;count<=sheet.getLastRowNum();count++){
HSSFRow row = sheet.getRow(4);
HSSFCell cell = row.getCell(4);
System.out.println("Running test case " + cell.getStringCellValue().equalsIgnoreCase("uk"));
对于每个循环,您将行值保持为 4 硬编码,它在整个循环中保持不变。
即对于 count = 0,
HSSFRow row = sheet.getRow(4);
和 count =1
又是HSSFRow row = sheet.getRow(4);
相反,您需要像
那样做HSSFRow row = sheet.getRow(count);
试试这个...