Comment définir des variables sur les valeurs de données itératives ApachePOI

J'ai deux scripts; un avec POI d'Apache pour lire des données à partir d'une feuille Excel et une autre pour le selenium pour prendre datatables reçues à partir du script apache et utiliser datatables pour les champs de saisie.

voici mon script apache excel reader:

public class readExcelFinal{ static ArrayList<Double> priceList; static ArrayList<Ssortingng> titleList; static ArrayList<Ssortingng> descriptionList; static ArrayList<Ssortingng> imageLocationList; public static void processExcelFile(Ssortingng fileName) throws IOException{ priceList = new ArrayList<Double>(); titleList = new ArrayList<Ssortingng>(); descriptionList = new ArrayList<Ssortingng>(); imageLocationList = new ArrayList<Ssortingng>(); try{ FileInputStream myInput = new FileInputStream(fileName); POIFSFileSystem myFileSystem = new POIFSFileSystem(myInput); HSSFWorkbook myWorkBook = new HSSFWorkbook(myFileSystem); HSSFSheet mySheet = myWorkBook.getSheetAt(2); Iterator rowIter = mySheet.rowIterator(); // For each row, while(rowIter.hasNext()){ HSSFRow row = (HSSFRow) rowIter.next(); // If there's a cell at index 0, it's a price if(row.getCell(0) != null) priceList.add(row.getCell(0).getNumericCellValue()); // If there's a cell at index 1, it's a title if(row.getCell(1) != null) titleList.add(row.getCell(1).getSsortingngCellValue()); // If there's a cell at index 2, it's a description if(row.getCell(2) != null) descriptionList.add(row.getCell(2).getSsortingngCellValue()); // If there's a cell at index 3, it's an image location if(row.getCell(3) != null) imageLocationList.add(row.getCell(3).getSsortingngCellValue()); } }catch(Exception e){ e.printStackTrace(); } } public static void createTests(){ // Create an RNG to re-use Random randomGenerator = new Random(); // Iterate through the price list and create tests for (Double price : priceList){ // For each of title, description, and image location, get a random index into the list and pull the value int titleIndex = randomGenerator.nextInt(titleList.size()); Ssortingng title = titleList.get(titleIndex); int descriptionIndex = randomGenerator.nextInt(descriptionList.size()); Ssortingng description = descriptionList.get(descriptionIndex); int imageLocationListIndex = randomGenerator.nextInt(imageLocationList.size()); Ssortingng imageLocation = imageLocationList.get(imageLocationListIndex); System.out.println("Creating test for Price " + price + "\n\tTitle:\t" + title + "\n\tDesc:\t" + description + "\n\tImg:\t" + imageLocation); } } public static Ssortingng price; public static Ssortingng title; public static Ssortingng description; public static Ssortingng imageLocation; public void setName(Ssortingng price) { this.price = price; } public static Ssortingng getPrice() { return price; } public void setDescription(Ssortingng description) { this.description = description; } public static Ssortingng getDescription() { return description; } public void setTitle(Ssortingng title) { this.title = title; } public static Ssortingng getTitle() { return title; } public void setImageLocation(Ssortingng imageLocation) { this.imageLocation = imageLocation; } public static Ssortingng getImageLocation() { return imageLocation; } } 

et voici mon (partie) de mon scénario de selenium:

 public class webDriver { public static void main(Ssortingng[] args) throws Exception { //THIS IS WHERE IM PULLING THE METHOD INTO MY SELENIUM SCRIPT readExcelFinal.main(args); //EXCELL DATA Ssortingng price = readExcelFinal.getPrice(); Ssortingng title = readExcelFinal.getTitle(); Ssortingng description = readExcelFinal.getDescription(); Ssortingng imageLocation = readExcelFinal.getTitle(); System.out.println("Creating test for Price " + price + "\n\tTitle:\t" + title + "\n\tDesc:\t" + description + "\n\tImg:\t" + imageLocation); // The Firefox driver supports javascript WebDriver driver = new FirefoxDriver(); 

Comme vous pouvez le voir dans mon script Selenium, j'utilise:

  System.out.println("Creating test for Price " + price + "\n\tTitle:\t" + title + "\n\tDesc:\t" + description + "\n\tImg:\t" + imageLocation); 

pour visualiser rapidement datatables dans ma console, donc je n'ai pas à attendre que le script entier s'exécute pour voir si les variables obtiennent ou non des valeurs. Je récupère ceci dans la console:

 Creating test for Price null Title: null Desc: null Img: null 

Je ne reçois aucune des données de cas de test de mon script.

La raison derrière null valeurs null est que vous essayez d'imprimer le price variables, le title , la description en appelant les methods getXXX , mais elles ne sont pas définies / atsortingbuées dans n'importe quel code (par exemple, je ne vois pas que setXXX() soit appelé n'importe où ) et par conséquent, les valeurs par défaut sont atsortingbuées et imprimées.

En passant, je vous conseillerais de lire les bases de programmation Java et la différence entre les variables / membres statiques et non statiques .