phantomJS crash when trying to test the upload feature

i tried with selenium (not testbench) to test the upload feature of my website.

See attached picture below of the website.
I then run following code:

package com.melexis.testdatawarehouse.tdwui;

import org.openqa.selenium.*;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxProfile;
import org.openqa.selenium.htmlunit.HtmlUnitDriver;
import org.openqa.selenium.phantomjs.PhantomJSDriver;
import org.openqa.selenium.remote.DesiredCapabilities;

import java.util.concurrent.TimeUnit;

public class UploadTrial {
public static void main(String args) throws Exception{
//to allow using of click on control keys:
FirefoxProfile profile=new FirefoxProfile();
profile.setEnableNativeEvents(false);
//WebDriver driver=new FirefoxDriver();

    DesiredCapabilities dCaps = new DesiredCapabilities();
    dCaps.setJavascriptEnabled(true);
    dCaps.setCapability("takesScreenshot", true);
    WebDriver driver=new PhantomJSDriver(dCaps);
    //WebDriver driver=new HtmlUnitDriver();

    driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
    driver.manage().window().setPosition(new Point(0, 0));
    driver.manage().window().setSize(new Dimension(1024,768));
    driver.get("http://localhost:9999/tdw-ui/");
    Thread.sleep(1000);


    driver.findElement(By.id("Upload Test Input")).click();

    WebElement element=driver.findElement(By.className("gwt-FileUpload"));
    element.sendKeys("/home/jem/Documents/Dropbox/Project/TestReportAutomation/CGMqualifs/TestInputDocExample.csv");
    //((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
    WebElement element1=driver.findElement(By.id("uploadTestInput"));
    WebElement element2=element1.findElement(By.className("v-button"));
    element2.click();
    driver.close();





}

}

And I get following error:
PhantomJS has crashed. Please read the crash reporting guide at https://github.com/ariya/phantomjs/wiki/Crash-Reporting and file a bug report at https://github.com/ariya/phantomjs/issues/new with the crash dump file attached: /tmp/08b2fcf2-e7fc-203b-033ddc33-77f0b7cf.dmp
Exception in thread “main” org.openqa.selenium.remote.UnreachableBrowserException: Error communicating with the remote browser. It may have died.
Build info: version: ‘2.41.0’, revision: ‘3192d8a6c4449dc285928ba024779344f5423c58’, time: ‘2014-03-27 11:29:39’
System info: host: ‘jem-laptop’, ip: ‘127.0.1.1’, os.name: ‘Linux’, os.arch: ‘amd64’, os.version: ‘3.8.0-44-generic’, java.version: ‘1.7.0_25’
Driver info: driver.version: RemoteWebDriver
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:548)
at org.openqa.selenium.remote.RemoteWebElement.execute(RemoteWebElement.java:268)
at org.openqa.selenium.remote.RemoteWebElement.click(RemoteWebElement.java:79)
at com.melexis.testdatawarehouse.tdwui.UploadTrial.main(UploadTrial.java:40)
Caused by: org.openqa.selenium.WebDriverException: The PhantomJS/GhostDriver server has unexpectedly died!
Build info: version: ‘2.41.0’, revision: ‘3192d8a6c4449dc285928ba024779344f5423c58’, time: ‘2014-03-27 11:29:39’
System info: host: ‘jem-laptop’, ip: ‘127.0.1.1’, os.name: ‘Linux’, os.arch: ‘amd64’, os.version: ‘3.8.0-44-generic’, java.version: ‘1.7.0_25’
Driver info: driver.version: RemoteWebDriver
at org.openqa.selenium.phantomjs.PhantomJSCommandExecutor.execute(PhantomJSCommandExecutor.java:88)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:527)
… 3 more
Caused by: java.net.ConnectException: Connection refused

If I use the firefox instead of phantomJS no issue. If I use phantomJS but do not put the sizing line for the window or change the 1024 to 500 by example:
driver.manage().window().setSize(new Dimension(1024,768));

I get then following error:
Exception in thread “main” org.openqa.selenium.ElementNotVisibleException: {“errorMessage”:“Element is not currently visible and may not be manipulated”,“request”:{“headers”:{“Accept”:“application/json, image/png”,“Connection”:“Keep-Alive”,“Content-Length”:“27”,“Content-Type”:“application/json; charset=utf-8”,“Host”:“localhost:25619”},“httpVersion”:“1.1”,“method”:“POST”,“post”:“{"id":":wdc:1413372792182"}”,“url”:“/click”,“urlParsed”:{“anchor”:“”,“query”:“”,“file”:“click”,“directory”:“/”,“path”:“/click”,“relative”:“/click”,“port”:“”,“host”:“”,“password”:“”,“user”:“”,“userInfo”:“”,“authority”:“”,“protocol”:“”,“source”:“/click”,“queryKey”:{},“chunks”:[“click”]
},“urlOriginal”:“/session/0ab1ac80-545f-11e4-9a1f-bf7a7f8f8322/element/%3Awdc%3A1413372792182/click”}}
Command duration or timeout: 111 milliseconds
Build info: version: ‘2.41.0’, revision: ‘3192d8a6c4449dc285928ba024779344f5423c58’, time: ‘2014-03-27 11:29:39’
System info: host: ‘jem-laptop’, ip: ‘127.0.1.1’, os.name: ‘Linux’, os.arch: ‘amd64’, os.version: ‘3.8.0-44-generic’, java.version: ‘1.7.0_25’
Session ID: 0ab1ac80-545f-11e4-9a1f-bf7a7f8f8322
Driver info: org.openqa.selenium.phantomjs.PhantomJSDriver
Capabilities [{platform=LINUX, acceptSslCerts=false, javascriptEnabled=true, browserName=phantomjs, rotatable=false, driverVersion=1.1.0, locationContextEnabled=false, version=1.9.7, cssSelectorsEnabled=true, databaseEnabled=false, handlesAlerts=false, browserConnectionEnabled=false, webStorageEnabled=false, nativeEvents=true, proxy={proxyType=direct}, applicationCacheEnabled=false, driverName=ghostdriver, takesScreenshot=true}]

at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:193)
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:145)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:554)
at org.openqa.selenium.remote.RemoteWebElement.execute(RemoteWebElement.java:268)
at org.openqa.selenium.remote.RemoteWebElement.click(RemoteWebElement.java:79)
at com.melexis.testdatawarehouse.tdwui.UploadTrial.main(UploadTrial.java:40)

Caused by: org.openqa.selenium.remote.ScreenshotException: Screen shot has been taken
Build info: version: ‘2.41.0’, revision: ‘3192d8a6c4449dc285928ba024779344f5423c58’, time: ‘2014-03-27 11:29:39’
System info: host: ‘jem-laptop’, ip: ‘127.0.1.1’, os.name: ‘Linux’, os.arch: ‘amd64’, os.version: ‘3.8.0-44-generic’, java.version: ‘1.7.0_25’
Driver info: driver.version: RemoteWebDriver
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:125)
… 4 more
Caused by: org.openqa.selenium.remote.ErrorHandler$UnknownServerException: {“errorMessage”:“Element is not currently visible and may not be manipulated”,“request”:{“headers”:{“Accept”:“application/json, image/png”,“Connection”:“Keep-Alive”,“Content-Length”:“27”,“Content-Type”:“application/json; charset=utf-8”,“Host”:“localhost:25619”},“httpVersion”:“1.1”,“method”:“POST”,“post”:“{"id":":wdc:1413372792182"}”,“url”:“/click”,“urlParsed”:{“anchor”:“”,“query”:“”,“file”:“click”,“directory”:“/”,“path”:“/click”,“relative”:“/click”,“port”:“”,“host”:“”,“password”:“”,“user”:“”,“userInfo”:“”,“authority”:“”,“protocol”:“”,“source”:“/click”,“queryKey”:{},“chunks”:[“click”]
},“urlOriginal”:“/session/0ab1ac80-545f-11e4-9a1f-bf7a7f8f8322/element/%3Awdc%3A1413372792182/click”}}
Build info: version: ‘2.41.0’, revision: ‘3192d8a6c4449dc285928ba024779344f5423c58’, time: ‘2014-03-27 11:29:39’
System info: host: ‘jem-laptop’, ip: ‘127.0.1.1’, os.name: ‘Linux’, os.arch: ‘amd64’, os.version: ‘3.8.0-44-generic’, java.version: ‘1.7.0_25’
Driver info: driver.version: unknown

And in debug mode I can see it happens when we click on the upload button (element2.click()) and I can see ghostdriver does a post to phantomJS but got a 500 Http code. Does someone have already this issue? I guess phantomJS cannot cope well with the javascript executed when do an upload.

I was also able to get a few time the stuff passing so it seems timing issue.

I saw
this thread
but it seems related to TestBench and I don’t use it (but maybe similar issue)

16818.png

Hi,

I am also using PhantomJS and currently creating testcases for file upload. The below code was working well with Firefox and Chrome driver. But it is not working with PhantomJS. The line input.sendKeys(file… is not working.

final WebElement input = driver.findElement(By.className( "gwt-FileUpload" )); input.sendKeys( fileNameWithPath ); Best Regards,
Venkata Narayana

From what I saw it seems phantomJS cannot run all script. When I switched to saucelab it worked just like a charm (as it uses real drivers in VM).