Does Selenium support headless browser testing?

前端 未结 12 2894
说谎
说谎 2020-11-27 03:49

I\'m looking at Selenium Server at the moment, and I don\'t seem to notice a driver that supports headless browser testing.

Unless I\'m mistaken, it doesn\'t support

12条回答
  •  感动是毒
    2020-11-27 04:15

    Here's a "modern answer" on how to use Selenium with xvfb and Firefox driver in an Ubuntu Linux environment running Django/Python:

    # install xvfb and Firefox driver
    sudo su
    apt-get install -y xvfb firefox
    wget https://github.com/mozilla/geckodriver/releases/download/v0.19.1/geckodriver-v0.19.1-linux64.tar.gz
    tar -x geckodriver -zf geckodriver-v0.19.1-linux64.tar.gz -O > 
    /usr/bin/geckodriver
    chmod +x /usr/bin/geckodriver
    
    # install pip modules
    pip install selenium
    pip install PyVirtualDisplay
    

    You can then follow the Django LiveServerTestCase instructions.

    To use the driver you just installed, do something like this:

    from pyvirtualdisplay import Display
    from selenium.webdriver.firefox.webdriver import WebDriver
    
    driver = WebDriver(executable_path='/usr/bin/geckodriver')
    display = Display(visible=0, size=(800, 600)).start()
    
    # add your testing classes here...
    
    driver.quit()
    display.stop()
    

提交回复
热议问题