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

    • getting content of EML file
      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>
       
    • Plugin registration problem
      By MBeck65
      Hello,
      I'm a ScriptMaster Advanced Edition user (I subscribed it during last January) and I have a problem with the registration of a plugin that I created for my environment.
      I describe my environment by hoping that you can support me to solve the problem that I have:
      1. I'm using ScriptMaster on a Mac system (Yosemite) on which both FileMaker Advanced Pro 13.09 and FileMaker Server 13.09 are installed.
      2. I developed and tested with ScriptMaster some functions that I included inside a plugin and I created it with the name myPlugin on my Mac.
      3. I have put the produced plugin myPlugin.fmplugin in the 2 directory that I use in my FileMaker environment, I mean: 
               - HD1/FileMaker Server/Database/Extensions
               - HD1/FileMaker Server/Web Publishing/publishing-engine/cwpc/Plugins
      4. I opened a FileMaker file that uses the functions of my plugin and I registed the plugin on FileMaker Pro Advanced by using the key created by ScriptMaster at the end of the plugin creation.
      5. I deployed my FileMaker file on the FileMaker Server and I work with it so that one of the functions inside the plugin is invoked. The function worked as good as expected but... inside the 360Plugins_ServerScripting64.log file I see the following info:
      INFO: Registered successfully with demo license; will run for two hours after launch.
      And infact it's so: after two hours the plugin stops to work and I'm not more able to use my functions...
      I suppose there's something wrong in the procedure that I follow to register my plugin or, maybe, there's something wrong in my machine environment... I don't know... But I can't work... Could you please help me to understand how to solve this problem?
      Thanks a lot for your support.
       
      Massimo Becattini
    • Max files limit when running ScriptMaster on Server 13
      By Jonathan Perel
      Hi Folks,
       
      I'm wondering if anyone out there is having stability issues when running server side scripts which use ScriptMaster on FileMaker 13 Server. Everything seems to run well for a while, but after running for a while, scripts running on FileMaker Server Side start failing.
       
      It appears that every time a script using ScriptMaster runs server side, the appopriate JAR files are loaded, but when the script is done those file handles are never released. Eventually, the number of open file handles gets to the maximum allowed for a user/process and the fmsased process can no longer open any files. This means that ScriptMaster can no longer load (even FileMaker functions such as server side sending mail via SMTP won't work), until you reset the server side process via:
      fmsadmin restart fmse You can keep track of the ever growing list of ScriptMaster JAR handles via the following command:
      lsof | grep ScriptMaster | grep jar | wc -l So has anyone out there seen this issue or found a work around? I never saw this issue with FileMaker 12 Server, so I'm not sure if its a FM Server issue or a ScriptMaster issue.
       
      I have tried adding an "SMReset" prior to the initialization of ScriptMaster, and when my script is about to end. It does not seem to release the JARs.
       
      I'm going to try having my script check the number of open files for the fmsaed process:
      lsof -p `pgrep fmsased` | wc -1 and when that number gets too large ( say 100,000) restart the fmse engine with:
      fmsadmin -y restart fmse Cheers,
      JP
    • Reading Bar Codes with zxing Java Library
      By Bob Minteer
      Has anyone had success using the zxing library to read/decode bar codes with ScriptMaster ?   I generate them just fine using the Barcode4J library.
       
      I think I am having dependency issues (take a pill...) and not much forward momentum getting it to work.
       
      Examples, suggestions or commiseration are greatly accepted.  
       
      regards...
       
      Bob Minteer
       
    • Plugin registration on FileMaker Server 13
      By Yuichiro Kinoshita
      I've built a new plugin made by ScriptMaster Advanced 4 and trying to use it on FileMaker Server 13. It works well in 2 hours, but seems to expire after that.
       
      Registration script works well on client-side(FileMaker Pro), but does not work on FileMaker Server. What should I do to use the plugin on FileMaker Server?
       
       Thank you in advanced.