Jump to content

  •  

Photo

Screenshot website using selenium and phantomjs error

groovy scriptmaster phantomjs selenium ghostdriver

  • Please log in to reply
3 replies to this topic

#1 greerso  newbie

greerso
  • Members
  • 26 posts
  • FM Application:13 Advance
  • Platform:Mac OS X Mavericks
  • Skill Level:Intermediate
  • Time Online: 17h 51m 9s

Posted 27 June 2014 - 10:30 AM

I'm using the java project "selenium" with "ghostdriver" and phantomjs as my browser to create screenshots of web pages.  My code works perfectly in groovyConsole but has an error with the phantomjs driver once inside Scriptmaster.

 

I think the problem may be that it requires access to a binary phantomjs that is not part of the jars.

 

This is the code that executes in groovyConsole and produces a screenshot:

import java.io.File
import java.util.concurrent.TimeUnit
import org.apache.commons.io.FileUtils
import org.openqa.selenium.OutputType
import org.openqa.selenium.TakesScreenshot
import org.openqa.selenium.WebDriver
import org.openqa.selenium.phantomjs.PhantomJSDriver

System.setProperty("webdriver.phantomjs.driver", "/jars/phantomjsdriver-1.0.4.jar")
System.setProperty("phantomjs.binary.path", "/jars/phantomjs")

WebDriver driver = new PhantomJSDriver();
driver.manage().window().maximize()
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS)
driver.get("http://www.google.com")
File scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE)
FileUtils.copyFile(scrFile, new File("google.png"), true)
driver.close()

The error I get from Scriptmaster is:

 

 

org.openqa.selenium.remote.UnreachableBrowserException: Could not start a new session. Possible causes are invalid address of the remote server or browser start-up failure.

Build info: version: '2.34.0', revision: '11cd0ef', time: '2013-08-06 17:10:22'

System info: os.name: 'Mac OS X', os.arch: 'i386', os.version: '10.10', java.version: '1.6.0_65'

Driver info: driver.version: PhantomJSDriver

 

Parameters:

{}

 

---Script---

Script:

import java.io.File

import java.util.concurrent.TimeUnit

import org.apache.commons.io.FileUtils

import org.openqa.selenium.OutputType

import org.openqa.selenium.TakesScreenshot

import org.openqa.selenium.WebDriver

import org.openqa.selenium.phantomjs.PhantomJSDriver

 

System.setProperty("webdriver.phantomjs.driver", "/jars/phantomjsdriver-1.0.4.jar")

System.setProperty("phantomjs.binary.path", "/jars/phantomjs")

 

WebDriver driver = new PhantomJSDriver();

driver.manage().window().maximize()

driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS)

driver.get("http://www.google.com")

File scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE)

FileUtils.copyFile(scrFile, new File("google.png"), true)

driver.close()

 

Its also worth noting that in groovyConsole, the code still works without the two setProperty lines.

 

If I simplify the code the code to just:

import org.openqa.selenium.OutputType
import org.openqa.selenium.TakesScreenshot
import org.openqa.selenium.WebDriver
import org.openqa.selenium.phantomjs.PhantomJSDriver

System.setProperty("webdriver.phantomjs.driver", "/jars/phantomjsdriver-1.0.4.jar")
System.setProperty("phantomjs.binary.path", "/jars/phantomjs")

WebDriver driver = new PhantomJSDriver()
driver.get("http://www.google.com")
driver.close()

I get the same error in Scriptmaster and no error in groovyConsole.


  • 0

-

Danny


#2 _ian  enthusiast

_ian
  • Members
  • 47 posts
  • FM Application:13 Advance
  • Platform:Cross Platform
  • Skill Level:Expert
  • Certification:8, 9, 10, 11, 12
  • Membership:TechNet
  • Time Online: 1d 18h 51m 41s

Posted 17 July 2014 - 02:27 AM

I'm curious why you're using Selenium here? If you use the PhantomJS sample script Rasterize.js then you can call PhantomJS from the shell and it will work nicely.

 

I've just tested with the shell script example in ScriptMaster and it works correctly. At least on OS X - don't see why there'd be a problem on windows though.


  • 0

Ian
 

  • FileMaker 12 Certified Developer
  • FileMaker 11 Certified Developer
  • FileMaker 10 Certified Developer
  • FileMaker 9 Certified Developer
  • FileMaker 8 Certified Developer

#3 greerso  newbie

greerso
  • Members
  • 26 posts
  • FM Application:13 Advance
  • Platform:Mac OS X Mavericks
  • Skill Level:Intermediate
  • Time Online: 17h 51m 9s

Posted 17 July 2014 - 05:47 AM

Rasterize.js from the shell is how I am and have been running it.  I was looking for a way to make it more self contained and possibly more powerful and flexible.  Do you think that its not possible to use Selenium in a Scriptmaster function?  Do you know why the script would run in GroovyConsole and not in Scriptmaster, I would like to try to understand why it doesn't work?


  • 0

-

Danny


#4 _ian  enthusiast

_ian
  • Members
  • 47 posts
  • FM Application:13 Advance
  • Platform:Cross Platform
  • Skill Level:Expert
  • Certification:8, 9, 10, 11, 12
  • Membership:TechNet
  • Time Online: 1d 18h 51m 41s

Posted 17 July 2014 - 05:58 AM

I've not tried Selenium with a ScriptMaster function so I don't have enough experience to form an opinion. By coincidence I was doing a fair bit with PhantomJS last week, though with PHP not FileMaker. 


  • 0

Ian
 

  • FileMaker 12 Certified Developer
  • FileMaker 11 Certified Developer
  • FileMaker 10 Certified Developer
  • FileMaker 9 Certified Developer
  • FileMaker 8 Certified Developer





FMForum Advertisers