Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PhantomJS support #94

Closed
KevM opened this issue Aug 29, 2013 · 11 comments
Closed

PhantomJS support #94

KevM opened this issue Aug 29, 2013 · 11 comments

Comments

@KevM
Copy link
Collaborator

KevM commented Aug 29, 2013

My hope is to have a subset of my UI tests as part of our check-in test pass. Seems like WebDriver now supports PhantomJS. How hard would it be to add support for this as a browser type? I believe it is similar to Chrome Driver in that there needs to be an .exe runnable from a known path.

@lefthandedgoat
Copy link
Owner

I will add it tonight. I played with it some at work and it does not support javascript alerts, just an fyi.

@KevM
Copy link
Collaborator Author

KevM commented Aug 29, 2013

Awesome! ⛵

We are so past using javascript alerts. In fact it is verboten. 🇩🇪

lefthandedgoat added a commit that referenced this issue Aug 30, 2013
@lefthandedgoat
Copy link
Owner

This will be released in a new build tonight.

Simply use 'start phantomJS' instead of 'start chrome'. I tested it with my basic test suite build for canopy regression testing and it worked fine as long as I skipped tests with alerts in them.

The test suite was a little smaller that normal and ran in 70 seconds with phantomJS 1.9.x, Chrome ran the full suite in 59 seconds. So if you want speed chrome is the way to go.

If you want headless then you can use this powershell trick I figured out (you have to turn on powershell locally with Set-ExecutionPolicy, google it):

Start-Service winrm

$nlm = [Activator]::CreateInstance([Type]::GetTypeFromCLSID([Guid]"{DCB00C01-570F-4A9B-8D69-199FDBA5723B}"))
#$connections = $nlm.getnetworkconnections()
#$connections | foreach {
#  if ($_.getnetwork().getcategory() -eq 0) {
#    $_.getnetwork().setcategory(1)
#  }
#}

Enable-PSRemoting -force

set-item wsman:localhost\Shell\MaxMemoryPerShellMB 2048
icm -computer localhost { C:\projects\canopy\basictests\bin\Debug\basictests.exe }

The lines in the middle are comented with #. You may need that uncommented if it complaines about your network adapters being public? Happened to me I think because of vmware network adapters.

Last line change it to be the path to your tests.

Its a cool trick you can use for anything, run it remotely on your own pc =). Unfortunately this doesn't work with chrome, I think its because chromedriver cant launch an instance of chrome. It does work with Firefox and provides the same experience as phantom would.

@lefthandedgoat
Copy link
Owner

Now available in canopy 0.8.0
http://www.nuget.org/packages/canopy

@KevM
Copy link
Collaborator Author

KevM commented Aug 30, 2013

Checking it out now. Hmm curious about the performance you see that is disappointing.

Noticed that it does not support the js method trying to figure out why.

image 202013-08-30 20at 2010 53 29 20am 1

@lefthandedgoat
Copy link
Owner

https://gist.github.com/lefthandedgoat/6381311

That basic sampled worked for me with phantomJS.

Looking at the screenshot, I found this on stack overflow:
http://stackoverflow.com/questions/2704929/uncaught-error-security-err-dom-exception-18-when-i-try-to-set-a-cookie

@KevM
Copy link
Collaborator Author

KevM commented Aug 30, 2013

I am clearing localstorage so that seems like it may not be supported. Taking out that js call makes all my tests run.

I am seeing

  • Chrome - 37 seconds
  • Phantom JS - 41 seconds (default)
  • Phantom JS - 36 seconds with system proxy set to None

Very slow network performance. The workaround is to set proxy type to "none" (issue 10580)

Created my own browser like so:

let service = OpenQA.Selenium.PhantomJS.PhantomJSDriverService.CreateDefaultService(canopy.configuration.phantomJSDir)
service.ProxyType <- "none"
let b = new OpenQA.Selenium.PhantomJS.PhantomJSDriver(service) :> OpenQA.Selenium.IWebDriver
canopy.core.browser <- b
canopy.core.browsers <- browsers @ [browser]
  • Firefox 81 seconds

Moar data

Since PhantomJS seems slow at network requests and we use RequireJS and have a lot of network traffic for unoptimized versions of our site I wanted to compare the two leaders against our optimized production version:

  • Chrome 26 seconds
  • Phantom JS - 22 seconds with proxy set to None
  • Phantom JS - 22 seconds (default)

@KevM
Copy link
Collaborator Author

KevM commented Aug 30, 2013

Updated Chrome numbers above 👍

@lefthandedgoat
Copy link
Owner

This weekend I will provide some more options for starting phantomJS with no proxy and the pull request you sent. Thanks!

@lefthandedgoat
Copy link
Owner

canopy 0.8.1 is available on nuget with the above commit and your pull request.

@KevM
Copy link
Collaborator Author

KevM commented Sep 3, 2013

Cool thanks. I'll try it out and close this issue. If I run into problems I'm sure you'll hear from me. ⛵

@KevM KevM closed this as completed Sep 3, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants