S0-E3/E30 :)
Did you created your selenium grid tests ? Did you know, that you can get them to run faster? Just use PhantomJS! Wait... what? NodeJS technology in Python stack?! YEAH! With docker you can combine them!
PhantomJS.
PhantomJS is a Javascript Headless browser that at least theoretically should run faster then Firefox.
This article is connected with How-To-Create-Your-Selenium-Grid-Compatible-Test - check it out :)
How to run your PhantomJS
Using docker you can just:
docker run -d -p 8910:8910 wernight/phantomjs phantomjs --webdriver=8910
Your testcase.
And here is what I thought will be a simple integration with Selenium Grid. Then I've found it does not have proper connector to Selenium Grid (eh...). Moreover I've found it has problems with making "send_keys" because of some strange dependency problems that you can find on stackoverflow (problem exists I've check it, before I found those SO pages): - here - here
So what can we do?
Well here's what I've been able to make with a not-fully working python api to remote PhantomJS :
import unittest
from selenium import webdriver
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
import time
class PhantomJSTests(unittest.TestCase):
def test_search_in_python_org(self):
# this test will not work on PhantomJS since it has a in-compatible API :(
# instead we need to create a simulation for that
driver = self.driver
print driver.get("https://github.com")
assert "GitHub" in driver.title
elem = driver.find_element_by_name("q")
# send_keys does not work on phantomjs - there are some strange workarounds but in my limited time I could not get them to work.
# I will however make a follow up on this!
# elem.send_keys("anselmos")
# time.sleep(5)
# elem.send_keys(Keys.ENTER)
# time.sleep(5)
# assert "No results found." not in driver.page_source
def setUp(self):
self.driver = webdriver.Remote(
command_executor='http://127.0.0.1:8910',
desired_capabilities=DesiredCapabilities.PHANTOMJS
)
if __name__ == "__main__":
unittest.main()
OR download it from here
Is there any other solutions to this ?
Well.... yeah. You can either recompile PhantomJS (by using different branch named " backport-ghostdriver-2-0-to-phantomjs-2-1 " and then using command docker run -v $PWD:/src debian:wheezy /src/deploy/docker-build.sh
as suggested on github issue page in this comment by jesg
Wait until someone will fix PhantomJS (that is apparently untill 2.5 -btw current ver. is 2.1.3 ... )
Or... use a Javascript API instead as described here
Thanks!
That's it :) Comment, share or don't :)
I hope you enjoyed this episode as much as I did :)
BTW I will do a follow up on problems with PhantomJS - and will give you feedback if there are any other solutions to the problem :)
If you have any suggestions what I should blog about in the next articles - please give me a hint :)
See you tomorrow! Cheers!
Comments
comments powered by Disqus