Skip to content

Commit

Permalink
use chromedriver more tests (#133)
Browse files Browse the repository at this point in the history
* use chromedriver more tests

* docstring

* chromedriver to path

* for macos

* linux binary path for chrome

* see where chrome is

* update

* update

* update

* try trusty

* update chrome binary for linux

* quit driver on finish

* sleep again

* lint

* don't print

* remove prints

* remove import
  • Loading branch information
jwkvam committed May 31, 2017
1 parent 6c0b2ca commit dc62fbd
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 10 deletions.
9 changes: 9 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
dist: trusty
language: python
cache: pip
addons:
chrome:
stable

python:
# We don't actually use the Travis Python, but this keeps it organized.
- "2.7"
Expand Down Expand Up @@ -34,6 +39,10 @@ install:
- source activate test-environment
- pip install -r requirements.txt
- make checkdocs
- wget https://chromedriver.storage.googleapis.com/2.29/chromedriver_linux64.zip
- unzip chromedriver_linux64.zip
- chmod +x chromedriver
- sudo mv -f chromedriver /usr/local/bin

script:
- make test
Expand Down
2 changes: 1 addition & 1 deletion bowtie/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Interactive dashboard toolkit."""

__version__ = '0.3.3'
__version__ = '0.3.4-dev'

from bowtie._layout import Layout
from bowtie._command import command
Expand Down
17 changes: 17 additions & 0 deletions bowtie/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
"""Pytest configuration."""

import os
from sys import platform
import shutil
from selenium import webdriver

import pytest

Expand All @@ -14,3 +16,18 @@ def remove_build():
yield
path = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'build')
shutil.rmtree(path)


@pytest.fixture
def chrome_driver():
"""Set up chrome driver."""
options = webdriver.ChromeOptions()
if platform == 'darwin':
options.binary_location = '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome'
else:
options.binary_location = '/usr/bin/google-chrome-stable'
options.add_argument('headless')
options.add_argument('window-size=1200x800')
driver = webdriver.Chrome(chrome_options=options)
yield driver
driver.quit()
39 changes: 30 additions & 9 deletions bowtie/tests/test_plotly.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,40 @@
import subprocess
import time

from selenium.webdriver import PhantomJS
# from selenium.webdriver import PhantomJS
# from selenium.webdriver import ActionChains

from bowtie import Layout
from bowtie.control import Nouislider, Button
from bowtie.visual import Plotly

from plotly.graph_objs import Scatter
from plotly.graph_objs import Layout as PlotLayout


# pylint: disable=invalid-name
viz = Plotly()
ctrl = Nouislider()
ctrl2 = Button()


def callback(*args):
"""dummy function"""
# pylint: disable=unused-argument
pass
chart = {
"data": [
Scatter(x=[1, 2, 3, 4], y=[4, 1, 3, 7])
],
"layout": PlotLayout(
title="hello world"
)
}
viz.do_all(chart)


# pylint: disable=unused-argument
def test_plotly(remove_build):
def test_plotly(remove_build, chrome_driver):
"""Tests plotly."""
viz = Plotly()
ctrl = Nouislider()
ctrl2 = Button()

path = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'build')
layout = Layout(directory=path)
Expand All @@ -40,11 +53,19 @@ def test_plotly(remove_build):
env = os.environ
env['PYTHONPATH'] = '{}:{}'.format(os.getcwd(), os.environ.get('PYTHONPATH', ''))
server = subprocess.Popen(os.path.join(path, 'src/server.py'), env=env)

time.sleep(5)

driver = PhantomJS()
driver.get('http://localhost:9991')
chrome_driver.get('http://localhost:9991')
chrome_driver.implicitly_wait(5)

assert chrome_driver.title == 'Bowtie App'

button = chrome_driver.find_element_by_class_name('ant-btn')
button.click()

points = chrome_driver.find_elements_by_class_name('point')

assert driver.title == 'Bowtie App'
assert len(points) == 4

server.kill()

0 comments on commit dc62fbd

Please sign in to comment.