55
66package ch .racic .selenium .helper .download ;
77
8+ import net .anthavio .phanbedder .Phanbedder ;
89import org .apache .commons .io .FileUtils ;
910import org .eclipse .jetty .server .Handler ;
1011import org .eclipse .jetty .server .Server ;
1718import org .openqa .selenium .htmlunit .HtmlUnitDriver ;
1819import org .openqa .selenium .ie .InternetExplorerDriver ;
1920import org .openqa .selenium .phantomjs .PhantomJSDriver ;
21+ import org .openqa .selenium .phantomjs .PhantomJSDriverService ;
22+ import org .openqa .selenium .remote .DesiredCapabilities ;
2023import org .openqa .selenium .safari .SafariDriver ;
2124
2225import java .io .File ;
@@ -53,7 +56,9 @@ public static void setUpClass() throws Exception {
5356
5457 @ AfterClass
5558 public static void tearDownClass () throws Exception {
56- server .stop ();
59+ if (server != null ) {
60+ server .stop ();
61+ }
5762 }
5863
5964 @ Before
@@ -78,7 +83,7 @@ public void testGetFileFromUrlHtmlUnit() throws Exception {
7883
7984 @ Test
8085 public void testGetFileFromUrlChrome () throws Exception {
81- //TODO put this into pom profiles which are OS specific
86+ //TODO put this into pom profiles which are OS specific or build helper lib like phantomjs has
8287 System .setProperty ("webdriver.chrome.driver" , "driver/chromedriver" );
8388 driver = new ChromeDriver ();
8489 invokeGetFileDataFromUrl ();
@@ -101,14 +106,19 @@ public void testGetFileFromUrlFireFox() throws Exception {
101106
102107 @ Test
103108 public void testGetFileFromUrlInternetExplorer () throws Exception {
109+ //TODO Fetch latest binaries and make arch specific profiles
104110 driver = new InternetExplorerDriver ();
105111 invokeGetFileDataFromUrl ();
106112 invokeGetFileFromUrl ();
107113 }
108114
109115 @ Test
110116 public void testGetFileFromUrlPhantomJS () throws Exception {
111- driver = new PhantomJSDriver ();
117+ // See http://blog.anthavio.net/2014/04/phantomjs-embedder-for-selenium.html
118+ File phantomjs = Phanbedder .unpack ();
119+ DesiredCapabilities dcaps = new DesiredCapabilities ();
120+ dcaps .setCapability (PhantomJSDriverService .PHANTOMJS_EXECUTABLE_PATH_PROPERTY , phantomjs .getAbsolutePath ());
121+ driver = new PhantomJSDriver (dcaps );
112122 invokeGetFileDataFromUrl ();
113123 invokeGetFileFromUrl ();
114124 }
0 commit comments