Jump to content

Screenshot website using selenium and phantomjs error


greerso
 Share

This topic is 2571 days old. Please don't post here. Open a new topic instead.

Recommended Posts

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.

Link to comment
Share on other sites

  • 3 weeks later...

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.

Link to comment
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?

Link to comment
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. 

Link to comment
Share on other sites

This topic is 2571 days old. Please don't post here. Open a new topic instead.

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
 Share

  • Similar Content

    • By Mr. Scott
      When I fired up FMPA 18 the first time with plugins installed, I received an alert for a number of well-known commercial plugins as well as every one of the plugins created with ScriptMaster Advanced.
      Will a near-future release of ScriptMaster Advanced allow us to create "digitally signed" plugins?
      If so, ETA or a workaround?
      Thanks in advance,
      - - Scott

    • By Ibrahim Bittar
      Hello
      Yesterday I created a plugin with ScriptMaster 5.1. It only has 5 functions.
      In most computers it shows the "Preparing Plugin for First use Dialog", sometimes it takes several minutes but finally it ends and the plugin starts working as expected. However, in 20-25% of the computers I've installed it (via Install Plug-In script step) I'm getting initialization errors. The plugin shows unchecked and it fails to initialize if I try to activate the check box.
      I've looked everywhere to see what I can delete in order to have the "Preparing Plugin...." dialog again to see if I am luckier this time but nothing seems to help and my users are starting to get angry.
      Please find attached the plugin I made (Win32, Win64 and Mac) and some log files i could find.
      Hope you can help me.
      EikonsysOne_CFDi_52.zip
    • By john renfrew
      WHen testing out High Sierra I am getting a Jav app in the dock every time I run FileMkaer with Scriptmaster. Closing doesn't seem to remove the app..
      It crashed the other day a couple of times so I ended up with three icons there
       
      What is this, can can it not be so???
    • By john renfrew
      I have been trying to follow the tutorial for iText 7 and and coming unstuck quite early on and not sure if it is a change in the way the jars are loaded or as a result of using standalone JVM...
      As you know I might just have a lot of expertise with v5 and have no problems, but I also can't use 7 with older scriptmaster as there is MajorVersion issue as it requires later than Java 6
      Anyone care to be enlightening??
    • By Raúl Basurco M.
      ScriptMaster 5.01 is not working as usual.
      Just downloaded and updated and my solutions started to report errors on many dialog boxes.

  • Who Viewed the Topic

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.