Ok, I'm going crazy on this one. I've written a unit test to test out our web site (in Play and Scala). The test should submit a file via the file input on the form.
I'm using WebDriver to run the test.
It seems to be instrumented just fine... but, whenever I submit the form, the logs show:
[debug] application - Uploading ... Abundance_800.png
[debug] application - /Users/zbeckman/Projects/Server/project/server/public/images/bundled_sentiments/Abundance_800.png
[error] application - /var/folders/fr/f2_wx1316h3f80cdvtcwq6c00000gn/T/Users/zbeckman/Projects/Server/project/server/public/images/bundled_sentiments/Abundance_800.png (No such file or directory)
java.io.FileNotFoundException: /var/folders/fr/f2_wx1316h3f80cdvtcwq6c00000gn/T/Users/zbeckman/Projects/Server/project/server/public/images/bundled_sentiments/Abundance_800.png (No such file or directory)
Obviously, my attempt to directly access the file in the public folder isn't allowed, but I can't figure out how to get around this.
Here's the code:
"upload a number of sentiments to the server" in new WithBrowser {
browser.goTo("/index")
val pathname: String = "./public/images/bundled_sentiments/"
val images = new java.io.File(pathname).listFiles.filter(_.getName.endsWith(".png"))
var imageName = ""
Logger.debug(s"Found $images. in " + pathname + " for sentiment image sources...")
for (file <- images) {
imageName = file.getName.replace("_800", "").replace(".png", "").replace("_", " ")
Logger.debug("Uploading ... " + file.toString.split("/").last)
webDriver.findElement(By.id("image")).sendKeys(file.getCanonicalPath)
browser.fill("#nametx").`with`(imageName)
browser.submit("#submit")
browser.await().atMost(10, TimeUnit.SECONDS).untilPage().isLoaded
assert(browser.find("alert").contains("Image uploaded successfully"))
}
}
So, the question is: Is there any way to achieve this using WebDriver, or am I just not going to be able to pass a reference to these files? (How about copying the files to a location that the WebDriver would have access to them?)
Aucun commentaire:
Enregistrer un commentaire