Daniil Pimenau Daniil Pimenau - 1 month ago 34
Java Question

executePhantomJS on Remotewebdriver

if I use a web driver then it works perfectly

driver = new PhantomJSDriver(capabilities);
driver.executePhantomJS( "var page = this;");


How can I make it work?

driver = new RemoteWebDriver(capabilities);
driver.executePhantomJS( "var page = this;");


UPDATE

My code

capabilities = DesiredCapabilities.phantomjs();
driver = new RemoteWebDriver(capabilities);


driver.executePhantomJS( "var page = this; binary =0;mimetype=''; count = 0;id=0; bla = '{';"
+"page.onResourceReceived = function(request) {"
+ "if(id !== request.id){"
+"bla += '\"'+count+ '\":'+JSON.stringify(request, undefined, 4)+',';"
+"if(request.contentType.substring(0, 11) =='application'){"
+"console.log(request.contentType);"
+ "mimetype = request.contentType;"
+ "binary++;"
+ "}"
+"count++;"
+ "id = request.id;"
+ "}"
+"};");


Java gives error: The method executePhantomJS(String) is undefined for the type RemoteWebDriver.

If i use executeScript it will not work.

I need run 100 test parallel, i can't use webdriver.

Answer

I guess that you wanna run PhantomJSDriver on your Se Grid. This is how it works for me (C# Factory implementation):

public IWebDriver CreateWebDriver(string identifier)
    {
     if (identifier.ToLower().Contains("ghostdriver"))
        {
            return new RemoteWebDriver(new Uri(ConfigurationManager.AppSettings["Selenium.grid.Url"]), DesiredCapabilities.PhantomJS());
        }
    }

or try this one

   Console.WriteLine("Creating GhostDriver (PhantomJS) driver.");
   //Temporary commented for testing purposes
   IWebDriver ghostDriver = new PhantomJSDriver("..\\..\\..\\MyFramework\\Drivers");
                ghostDriver.Manage().Window.Maximize();
                //ghostDriver.Manage().Window.Size = new Size(1920, 1080);
                ghostDriver.Manage()
                    .Timeouts()
                    .SetPageLoadTimeout(new TimeSpan(0, 0, 0,
                        Convert.ToInt32(ConfigurationManager.AppSettings["Driver.page.load.time.sec"])));
                return ghostDriver;

In case that you wonder why there is ConfigurationManager - I avoid the hard-coded values, so they are extracted from the App.config file.