Sign in to follow this  
Followers 0
greerso

Screenshot website using selenium and phantomjs error

4 posts in this topic

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.

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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?

Share this post


Link to post
Share on other sites

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. 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0

  • Similar Content

    • By john renfrew
      Is it possible to get access to the fmpro object inside an inner class in code???
      Example
       
      //at head of groovy code class myClass extends HelperClass { def xx = fmpro.evaluate('Get(PersistentID)') def ... def ... }  
      Currently fails with groovy.lang.MissingPropertyException: No such property: fmpro for class: myClass
    • By truelifeajf
      I'm at a loss as to why I'm getting "ERROR" when:
      I have an image (JPG) 3648 x 5472 pixels at this location:
      $crop_location = /Volumes/Macintosh HD/Applications/Wolf Spring/Wolf Spring Lightroom/Originals/Anderson_Austin_RB6649233682XA-O9330018750AV-crop.JPG
      The file location is definitely correct.
      This function:
      CropImage( $crop_location ; 0 ; 300 ; 3648 ; 5172 )
      Should simply crop 300 pixels off the top, right?
      I get "ERROR"
      Any ideas?
    • By john renfrew
      Once again, but now with more urgency, please can you indicate a timeframe for updating ScriptMaster to be able to use later versions of Java on the Mac.
      There is a completely brand new version of iText (in readiness for PDF 2.0) which has a whole new set of libraries, the code I use needs rewriting in some places, but more importantly is giving MajorMinor version errors as soon as I write my first line of code.
      I already have several functions I can not move but this is somewhat of a killer for me, given that is it my specialist subject...
      This has been rumbling on for too long without any clear help from 360Works.
       
      john
    • By Bilbo
      Hi,
      I have a little problem to run a Merge PDF with the new version of scriptmaster (4.42) and iText 5.5.5 on a Filemaker Pro 14.05 adv on windows 7.
      With this 4.32 version it works: https://dl.dropboxusercontent.com/u/30717534/M4.32.fmp12
      However with this new version 4.42, the Merge PDF script fails: https://dl.dropboxusercontent.com/u/30717534/M4.42.fmp12
      I have tried to get help on another forum, but unfortunately for the moment we didn't found the solution. We arrived at the conclusion that it must be something by my side, but I cannot figure out what is the problem, as I tried on 3 different computers.
      Could anybody try my files on a windows platform please and give me feedback please?
      Does anybody have an idea how to fix it?
      Thanks a lot
    • By john renfrew
      Just done a bit of research for a system I am building into extracting the text from .eml files. so here a first version. Requires apache Commons-mail
      <code>
      // EMLextract ( fm_fileIn )
      // 15_09_03 JRenfrew
      // v1.0
      // requires commons-mail
      // from http://www.cnblogs.com/jiaoyiping/p/3761560.html
       
      import org.apache.commons.mail.util.MimeMessageParser
      import org.apache.commons.mail.util.MimeMessageUtils
       
      removeCarr = { it ->
          return it.replace('\r\n' , '\n').replace('\n\n', '\n')
      } //end removeCarr
       
      file = new File (fm_fileIn)
      mimeMessage = MimeMessageUtils.createMimeMessage(null, file)
      parser = new MimeMessageParser(mimeMessage)
      parsed = parser.parse()
       
      if (parsed.hasPlainContent()){
          //smgetvariable to extract these - also getCc(), getBcc(), getReplyTo(), getTo()
          fm_from = parser.getFrom()
          fm_subj = parser.getSubject()
          return 'FROM: ' + fm_from + '\n' + 'SUBJECT: ' + fm_subj + '\n' + removeCarr(parsed.getPlainContent())
      } else if (parser.parse().hasHtmlContent()){
          return removeCarr(parsed.getHtmlContent())
      } else {
          return 'no text or html parts found'
      } //end if
       
      </code>