ASF Bugzilla – Attachment 31202 Details for
Bug 56001
Cannot open .xlsx data for use by selenium when selenium is started from the command line
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
Groovy script which is attempted to run
Sixth.groovy (text/plain), 10.05 KB, created by
autotest6564
on 2014-01-13 15:10:39 UTC
(
hide
)
Description:
Groovy script which is attempted to run
Filename:
MIME Type:
Creator:
autotest6564
Created:
2014-01-13 15:10:39 UTC
Size:
10.05 KB
patch
obsolete
>package Check > > > //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); > 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 cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Raw
Actions:
View
Attachments on
bug 56001
: 31202