1

I'm saving an screenshot when the page is loaded. If I test it with production, it works OK (the page is rendered correctly). But, if I test with local development server, the page isn't rendered correctly when I check the screenshot. Some elements (HTML, images) are missing.

The problems is PhantomJS. If I use Firefox, it works OK. But I need 'headless', because it's a requirement.

I'm using Python 2.7.6 + Selenium 2.45.0 + PhantomJS 1.9.8 (OS X Yosemite 10.10).

Code:

import unittest
import time

from selenium import webdriver

class Test(unittest.TestCase):

    HEADLESS = 1
    DEVELOPMENT = 1

    def setUp(self):

        if self.HEADLESS:
             self.driver = webdriver.PhantomJS()
             self.driver.set_window_size(1400, 1200)
         else:
             self.driver = webdriver.Firefox()
             self.driver.maximize_window()

        self.driver.implicitly_wait(100)

        url = 'http'
        if self.DEVELOPMENT:
            url += '://development.localhost.lan:3000/login'
        else:
            url += 's://PRODUCTION_WEB.com/login'

        self.driver.get(url)
        time.sleep(10)
        self.driver.save_screenshot('login.png')

    def tearDown(self):
        print 'tearDown'

    def test_import(self):
        print 'test_import'

if __name__ == '__main__':
    suite = unittest.TestLoader().loadTestsFromTestCase(Test)
    unittest.TextTestRunner(verbosity=2).run(suite)

Also, I've tested the following, with no results:

  • service_args=['--local-to-remote-url-access=true']
  • service_args=['--ignore-ssl-errors=true'] : (production is https)
  • set user_agent
  • enable/disable cookies
  • activate localToRemoteUrlAccessEnabled

Please, could anyone give me any advice? Thanks in advance!

Xatpy
  • 273
  • 2
  • 13
  • 1
    Just FYI, if `phantomjs` is the reason for your headaches and it makes you violent, you can approach it with firefox or chrome with a **virtual display**, e.g. http://stackoverflow.com/questions/6183276/how-do-i-run-selenium-in-xvfb. – alecxe Apr 01 '15 at 16:10
  • Thanks @alecxe! Finally, I couldn't find a workaround with PhantomJS, so I'm using **xvfb**. [Reference](http://elementalselenium.com/tips/38-headless) > xvfb-run python tests.py – Xatpy Apr 06 '15 at 13:19

0 Answers0