Skip to content

Commit

Permalink
Merge pull request #76 from seleniumbase/geckodriver-bug-fix
Browse files Browse the repository at this point in the history
Geckodriver bug fixes
  • Loading branch information
mdmintz authored Mar 11, 2017
2 parents 651fcb1 + 932146b commit 9d2e614
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 38 deletions.
19 changes: 4 additions & 15 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -73,17 +73,6 @@ RUN apt-get -qy --no-install-recommends install \
&& ln -s /opt/firefox/firefox /usr/bin/firefox \
&& rm -f /tmp/firefox-esr.tar.bz2

#======================================
# Install Geckodriver / Firefox Driver
#======================================
RUN export BASE_URL=https://github.com/mozilla/geckodriver/releases/download \
&& export VERSION=$(curl -sL \
https://api.github.com/repos/mozilla/geckodriver/releases/latest | \
grep tag_name | cut -d '"' -f 4) \
&& curl -sL \
$BASE_URL/$VERSION/geckodriver-$VERSION-linux64.tar.gz | tar -xz \
&& mv geckodriver /usr/local/bin/geckodriver

#===================
# Install PhantomJS
#===================
Expand All @@ -107,12 +96,12 @@ RUN exec "$@"
#=====================
COPY seleniumbase /SeleniumBase/seleniumbase/
COPY examples /SeleniumBase/examples/
COPY docker_requirements.txt /SeleniumBase/docker_requirements.txt
COPY server_setup.py /SeleniumBase/server_setup.py
COPY requirements.txt /SeleniumBase/requirements.txt
COPY setup.py /SeleniumBase/setup.py
RUN pip install --upgrade pip
RUN pip install --upgrade setuptools
RUN cd /SeleniumBase && ls && pip install -r docker_requirements.txt
RUN cd /SeleniumBase && python server_setup.py install
RUN cd /SeleniumBase && ls && pip install -r requirements.txt
RUN cd /SeleniumBase && python setup.py install

#==========================================
# Create entrypoint and grab example tests
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ To run automation on various web browsers, you'll need to download a driver file

* For PhantomJS headless browser automation, get [PhantomJS](http://phantomjs.org/download.html) on your System Path.

(NOTE: For older versions of Firefox such as 46.0 and earlier, you don't need Geckodriver. The older driver comes prepackaged with Selenium.)

Mac:

* On a Mac, you can install drivers more easily by using ``brew`` (aka ``homebrew``), but you have to install that first. [Brew installation instructions are here](https://github.com/seleniumbase/SeleniumBase/blob/master/help_docs/requirements_installation.md).
Expand Down
15 changes: 0 additions & 15 deletions docker_requirements.txt

This file was deleted.

16 changes: 13 additions & 3 deletions seleniumbase/core/browser_launcher.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from selenium import webdriver
from selenium.common.exceptions import WebDriverException
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
from seleniumbase.core import download_helper
from seleniumbase.fixtures import constants
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities


def get_driver(browser_name):
Expand Down Expand Up @@ -33,8 +34,17 @@ def get_driver(browser_name):
"text/csv, text/xml, application/xml, text/plain, "
"text/octet-stream"))
firefox_capabilities = DesiredCapabilities.FIREFOX
return webdriver.Firefox(
firefox_profile=profile, capabilities=firefox_capabilities)
try:
# Use Geckodriver for Firefox if it's on the PATH
firefox_capabilities['marionette'] = True
firefox_driver = webdriver.Firefox(
firefox_profile=profile, capabilities=firefox_capabilities)
except WebDriverException:
# Don't use Geckodriver: Only works for old versions of Firefox
firefox_capabilities['marionette'] = False
firefox_driver = webdriver.Firefox(
firefox_profile=profile, capabilities=firefox_capabilities)
return firefox_driver
except:
return webdriver.Firefox()
if browser_name == constants.Browser.INTERNET_EXPLORER:
Expand Down
4 changes: 4 additions & 0 deletions seleniumbase/fixtures/base_case.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ def click_link_text(self, link_text, timeout=settings.SMALL_TIMEOUT):

def get_text(self, selector, by=By.CSS_SELECTOR,
timeout=settings.SMALL_TIMEOUT):
self.wait_for_ready_state_complete()
element = page_actions.wait_for_element_visible(
self.driver, selector, by, timeout)
try:
Expand All @@ -190,6 +191,7 @@ def get_text(self, selector, by=By.CSS_SELECTOR,

def get_attribute(self, selector, attribute, by=By.CSS_SELECTOR,
timeout=settings.SMALL_TIMEOUT):
self.wait_for_ready_state_complete()
element = page_actions.wait_for_element_present(
self.driver, selector, by, timeout)
try:
Expand Down Expand Up @@ -323,10 +325,12 @@ def is_element_visible(self, selector, by=By.CSS_SELECTOR):
return page_actions.is_element_visible(self.driver, selector, by)

def is_link_text_visible(self, link_text):
self.wait_for_ready_state_complete()
return page_actions.is_element_visible(self.driver, link_text,
by=By.LINK_TEXT)

def is_text_visible(self, text, selector, by=By.CSS_SELECTOR):
self.wait_for_ready_state_complete()
if selector.startswith('/') or selector.startswith('./'):
by = By.XPATH
return page_actions.is_text_visible(self.driver, text, selector, by)
Expand Down
10 changes: 8 additions & 2 deletions seleniumbase/fixtures/page_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,13 @@
import sys
import time
import traceback
from seleniumbase.config import settings
from selenium.common.exceptions import WebDriverException
from selenium.webdriver.common.by import By
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.remote.errorhandler import ElementNotVisibleException
from selenium.webdriver.remote.errorhandler import NoSuchElementException
from selenium.webdriver.remote.errorhandler import NoAlertPresentException
from seleniumbase.config import settings


def is_element_present(driver, selector, by=By.CSS_SELECTOR):
Expand Down Expand Up @@ -388,7 +389,12 @@ def wait_for_ready_state_complete(driver, timeout=settings.EXTREME_TIMEOUT):
start_ms = time.time() * 1000.0
stop_ms = start_ms + (timeout * 1000.0)
for x in range(int(timeout * 10)):
ready_state = driver.execute_script("return document.readyState")
try:
ready_state = driver.execute_script("return document.readyState")
except WebDriverException:
# Bug fix for: [Permission denied to access property "document"]
time.sleep(0.03)
return True
if ready_state == u'complete':
time.sleep(0.01) # Better be sure everything is done loading
return True
Expand Down
4 changes: 2 additions & 2 deletions server_setup.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
"""
The setup package to install SeleniumBase dependencies and plugins
Uses the older Selenium 2.53.6 for compatibility reasons
(Uses the older Selenium 2.53.6 for compatibility reasons)
"""

from setuptools import setup, find_packages # noqa

setup(
name='seleniumbase',
version='1.3.0',
version='1.3.1',
url='http://seleniumbase.com',
author='Michael Mintz',
author_email='@mintzworld',
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

setup(
name='seleniumbase',
version='1.3.0',
version='1.3.1',
url='http://seleniumbase.com',
author='Michael Mintz',
author_email='@mintzworld',
Expand Down

0 comments on commit 9d2e614

Please sign in to comment.