poi-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bugzi...@apache.org
Subject [Bug 56002] New: Cannot open .xlsx data for use by selenium when selenium is started from the command line
Date Mon, 13 Jan 2014 15:32:50 GMT
https://issues.apache.org/bugzilla/show_bug.cgi?id=56002

            Bug ID: 56002
           Summary: Cannot open .xlsx data for use by selenium when
                    selenium is started from the command line
           Product: POI
           Version: 3.10-dev
          Hardware: PC
            Status: NEW
          Severity: major
          Priority: P2
         Component: XSSF
          Assignee: dev@poi.apache.org
          Reporter: isstar3465@gmail.com

I attempt to run a selenium based test script from the command line but I am
unable to do so. This despite the fact that I am able to run the EXACT same
script from Eclipse with the EXACT same classpath declaration. I need to be
able to trigger from the command line to properly integrate my automation
suite. I have shown the command prompt used and the errors generated below. I
have attached the java test script.


Command prompts sent to trigger test script which includes setting the
classpath

set
CLASSPATH=Q:\Automation\Eclipse\workspace\Resources\ooxml-lib\dom4j-1.6.1.jar;Q:\Automation\Eclipse\workspace\Resources\ooxml-lib\xmlbeans-2.3.0.jar;Q:\Automation\Eclipse\workspace\Resources\ooxml-lib\stax-api-1.0.1.jar;Q:\Automation\Eclipse\workspace\Resources\selenium-server-standalone-2.39.0.jar;Q:\Automation\Eclipse\workspace\Resources\testng-6.8.7.jar;Q:\Automation\Eclipse\workspace\Resources\poi-scratchpad-3.10-beta2-20130904.jar;Q:\Automation\Eclipse\workspace\Resources\poi-ooxml-schemas-3.10-beta2-20130904.jar;Q:\Automation\Eclipse\workspace\Resources\poi-ooxml-3.10-beta2-20130904.jar;Q:\Automation\Eclipse\workspace\Resources\poi-excelant-3.10-beta2-20121203.jar;Q:\Automation\Eclipse\workspace\Resources\poi-3.10-beta2-20130904.jar;Q:\Automation\Eclipse\workspace\Resources\poi-examples-3.10-beta2-20121203.jar;Q:\Automation\Eclipse\workspace\Resources\guice-2.0.jar;.
groovy Check\Eighth.groovy

Errors given from command prompt:

[TestNG] Running:
  Command line suite

Starting ChromeDriver (v2.8.241075) on port 41943

===============================================
Command line suite
Total tests run: 1, Failures: 1, Skips: 0
===============================================

Test Script:
package Check
Search for "//Error occurs on line below" to find where the error has been
shown to occur when started from the command line

    //import java.io.File;
    //import java.io.FileInputStream;
    //import java.util.Vector;





    import org.testng.annotations.Test;
    import javax.swing.text.html.HTMLEditorKit.HTMLFactory.BodyBlockView;

//import java.*;
    import org.apache.commons.io.FileUtils;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.xssf.usermodel.XSSFCell;
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.OutputType;
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.interactions.Action;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.testng.annotations.AfterSuite;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeSuite;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import org.testng.TestNG
import org.testng.TestListenerAdapter

class AbTest {

        ChromeDriver driver;
        WebElement elementwait;
        WebDriverWait wait;
        Binding binding;
        GroovyShell shell;
        Object value;

        @BeforeSuite
         public void start(){
             System.setProperty("webdriver.chrome.driver",
"C:\\Users\\redwoodi\\Downloads\\chromedriver.exe");
             driver = new ChromeDriver();
            wait = new WebDriverWait(driver, 40);
            //driver.manage().window().maximize();
             driver.get("http://523255-testapp1/Kalibrate_8/");
            //Thread.sleep(10000)
            elementwait =
wait.until(ExpectedConditions.elementToBeClickable(By.cssSelector("input[placeholder='Username']")));
            binding = new Binding()
            binding.setVariable("driver", driver)
            shell = new GroovyShell(binding)
            value=shell.evaluate("driver.manage().window().maximize();");
            //sleep(5000);
         }


        @Test(dataProvider = "Data-Provider-Function")
        public void parameterIntTest(String tesT, String eXecute) throws
Exception {
        System.out.println(tesT);
        eXecute = eXecute.substring(0,1).toLowerCase();
        if (eXecute.equals("y")){
            //def tryit = new String[0][0]
            def String[][] tryit = getTableArray(tesT);
            //return tryit;
        println "Parameterized Number is : " + tryit.size().toString();
    //if (tesT.equals("Login")){
    /*if (tryit.size() != 3){
        println "Chrome check"
       
driver.findElementByXPath("//div[@class='widget-head'][contains(.,'kIntel')]/a[@class='remove']").click();
        sleep(5000)
        driver.quit();
    }*/
    for (int i =0; i < tryit.size(); i++){
        System.out.println("experiment for loop " + i);
        if
(tryit[i][3].substring(0,1).toLowerCase().equals(tryit[i][3].substring(0,1))){

        def String stringEx;
        if (tryit[i][1].toLowerCase()=="contains") {
            stringEx = "//" + tryit[i][0] + "[contains(.,'"+tryit[i][2]+"')]"
            elementwait =
wait.until(ExpectedConditions.elementToBeClickable(By.xpath(stringEx)));
            stringEx = "ByXPath(\"" + stringEx +  "\")"
        } else if (tryit[i][1].toLowerCase()=="xpath") {
            stringEx = "ByXPath(\"" + tryit[i][2] +  "\")"
            println stringEx;
            elementwait =
wait.until(ExpectedConditions.elementToBeClickable(By.xpath(tryit[i][2])));
        } else {
            stringEx = tryit[i][0] + "[" + tryit[i][1] + "='" + tryit[i][2] +
"']"
            elementwait =
wait.until(ExpectedConditions.elementToBeClickable(By.cssSelector(stringEx)));
            stringEx = "ByCssSelector(\"" + stringEx + "\")"
        }
        stringEx = "driver.findElement" + stringEx
        println stringEx;
        stringEx = stringEx + "." + tryit[i][3]
        println stringEx;
        if (tryit[i][4]==null) {
            println "null"
            stringEx=stringEx+"();"
        }else{
            stringEx=stringEx+"(\""+tryit[i][4]+"\");"
        }
        /*if
(stringEx.equals("driver.findElementByXPath(\"//div[@class='widget-head'][contains(.,'kIntel')]/a[@class='remove']\").click();")){
            println "null2"
            sleep(250)
           
driver.findElementByXPath("//div[@class='widget-head'][contains(.,'kIntel')]/a[@class='remove']").click()
            sleep(2000)
        } else {*/
        if ((stringEx.indexOf(".click") > -1) &&
(stringEx.indexOf("/a[@class='remove']") > -1)) {
            sleep(300)
        }    
        value = shell.evaluate(stringEx)
        if ((stringEx.indexOf(".click") > -1) &&
(stringEx.indexOf("/a[@class='remove']") > -1)) {
            sleep(300)
        }    
        //}
        println stringEx
        //sleep(1000)
        //driver.findElementByXPath(stringEx)
    }else if (tryit[i][3].toUpperCase().equals("DRAG")){

    //Commands for the drag operation
   
//driver.findElementByXPath("//span[contains(.,'"+tryit[i][0]+"')]").click();
    Actions builder = new Actions(driver);
    System.out.println("Setting up the elements");
    WebElement initialitem =
driver.findElementByXPath("//span[contains(.,'"+tryit[i][0]+"')]");
      Action position = builder.moveToElement(initialitem)
              .build();
              position.perform();
    WebElement target = driver.findElementByCssSelector("div[id='container1']
div");
    WebElement element =
driver.findElementByCssSelector("div["+tryit[i][1]+"='"+tryit[i][2]+"']");
    println element.getSize().getWidth()
    //sleep(200)
    driver.findElementByXPath("//span[contains(.,'"+tryit[i][0]+"')]").click();
    sleep(400)
      Action selectMove = builder.moveToElement(target)
                .moveToElement(element)
              .clickAndHold(element)
              .moveByOffset(-490, 1)
              .release(element)
              .build();

    try{
          selectMove.perform();
    } catch (Exception e) {
          File scrsht =
((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
          FileUtils.copyFile(scrsht, new File("C:\\Temp\\screenshot.png"));
    }
    println driver.findElementById("container1").getSize().getWidth()
    //Thread.sleep(6500);

    //System.out.println("Logging into Kalibrate");
    Thread.sleep(1000);
        }else if (tryit[i][3].toUpperCase().equals("DRAG!")){

            //Commands for the drag operation
    elementwait =
wait.until(ExpectedConditions.elementToBeClickable(By.cssSelector("div[class='search-results
default-list'] > div > div + div > img")));
    //driver.findElementByCssSelector("div[class='search-results default-list']
> div > div + div > img").click();
        sleep(500);
        Actions builder = new Actions(driver);
        //System.out.println("Setting up the elements");
        WebElement initialitem =
driver.findElementByCssSelector("div[class='search-results default-list'] > div
> div + div > img");
        WebElement leftitem =
driver.findElementByCssSelector("div[class='search-results default-list'] > div
> div + div > img + div > img");
        WebElement target =
driver.findElementByCssSelector("div[id='container2'] div");
        WebElement element =
driver.findElementByCssSelector("div[class='search-results default-list'] > div
> div + div > img + div > img["+tryit[i][1]+"='"+tryit[i][2]+"']");
        //println element.getSize().getWidth()
          Action setUp = builder.moveToElement(initialitem)
          .moveToElement(leftitem)
          .build();
          setUp.perform();
        sleep(600);
          Action selectMove = builder.moveToElement(initialitem)
                  .moveToElement(element)
                  .clickAndHold(element)
                  .moveByOffset(190, 120)
                  .release(element)
                  .build();

        try{
              selectMove.perform();
        } catch (Exception e) {
              File scrsht =
((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
              FileUtils.copyFile(scrsht, new File("C:\\Temp\\screenshot.png"));
        }
        println driver.findElementById("container1").getSize().getWidth()
        //Thread.sleep(6500);

        System.out.println("Logging into Kalibrate");
        Thread.sleep(5000);

        }

    }
    }

    Thread.sleep(1000);


        }

             @DataProvider(name = "Data-Provider-Function")
        public Object[][] parameterIntTestProvider() throws Exception {
            Object[][] retobj = getTableArray("KSuite");
             return retobj;
        }

        @AfterSuite
         public void close(){
              //System.out.println("After Test");
            driver.quit();
         }

        public static String[][] getTableArray(String xlSheet) throws
Exception{
            //String[][] tabArray=null;

                                //System.out.println(xlSheet);

                    FileInputStream input = new FileInputStream(new
File("C:\\Temp\\KSuite.xlsx"));
                    //System.out.println(input.path);
//Error occurs on line below                    
XSSFWorkbook workbook = new XSSFWorkbook(input);
                                //System.out.println(xlSheet);
                        XSSFSheet sheet = workbook.getSheet(xlSheet);
                        int ci;//,cj;
                        //println "//ci = Math."
                        XSSFRow r = sheet.getRow(sheet.getFirstRowNum());
                        int
jMax=Math.max(r.getLastCellNum()-r.getFirstCellNum(),2);
                        int iMax=sheet.getLastRowNum()-sheet.getFirstRowNum();
                        def tabArray= new
String[sheet.getLastRowNum()-sheet.getFirstRowNum()][jMax];
                           
//System.out.println(sheet.getLastRowNum()-sheet.getFirstRowNum());
                            //System.out.println(jMax);

                        //ci=0;
                        for (int i = sheet.getFirstRowNum()+1; i <=
                                sheet.getLastRowNum(); i++) {
                           ci = i - 1;
                                r = sheet.getRow(i);

                           //int lastColumn = Math.max(r.getLastCellNum(),
MY_MINIMUM_COLUMN_COUNT);

                           //cj=0;
                           for (int j = 0; j < jMax; j++) {
                               //tabArray[1][1] = "rr";
                               //System.out.println(tabArray[1][1]);
                              XSSFCell c = r.getCell(j,
r.CREATE_NULL_AS_BLANK);
                              if(c.getCellType() == 1) {
                                //System.out.println(c.getStringCellValue());
                                  tabArray[ci][j]=c.getStringCellValue();
                                      //System.out.println(tabArray[ci][j]);
                                  } else if (c.getCellType() == 0) {
                                //println c.getCellType()
                                     
tabArray[ci][j]=(c.getNumericCellValue().toString());
                                  //tabArray[ci][j]=c.getStringCellValue();
                                      //System.out.println(tabArray[ci][j]);

                                  }
                           }
                       }
                        input.close();
                       // return(tabArray);
    //                    return(cj);
                        println "return(ci);"

                    return(tabArray);
                    println "return(cj);"
            }
    }

    def testng = new TestNG()
    testng.setTestClasses(AbTest)
    testng.addListener(new TestListenerAdapter())
    testng.run()

-- 
You are receiving this mail because:
You are the assignee for the bug.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org


Mime
View raw message