运行 python CircleCI 上的 Selenium 测试

Running python Selenium tests on CircleCI

我正在尝试 运行 在 CircleCI 的测试阶段进行一些 python selenium 测试。

我的 circle.yml 看起来像这样:

machine:
  python:
    version: 2.7.9
  node:
    version: 0.10.34
  java:
    version: oraclejdk8
dependencies:
  post:
    - pip install selenium
    - wget http://selenium-release.storage.googleapis.com/2.44/selenium-server-standalone-2.44.0.jar
    - java -jar selenium-server-standalone-2.44.0.jar:
        background: true
test:
  post:
    - python /home/ubuntu/app/tests/tests.py
...

和 tests.py 看起来像这样:

from selenium import webdriver

driver = webdriver.Chrome()
driver.get('http://127.0.0.1')

print driver.find_element_by_class_name('a-class').text

我有两个问题:

首先,如何将数据从test.py输出回CircleCI的接口(打印语句显然不起作用)

其次,当我收到 http://127.0.0.1/ is not available 错误时,在 driver.get() 调用中使用的正确地址是什么?

这是完整的回溯:

http://127.0.0.1/ is not available
Traceback (most recent call last):
  File "/home/ubuntu/app/tests/tests.py", line 11, in <module>
    print driver.find_element_by_class_name('yes-cta').text
  File "/home/ubuntu/virtualenvs/venv-2.7.9/lib/python2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 378, in find_element_by_class_name
    return self.find_element(by=By.CLASS_NAME, value=name)
  File "/home/ubuntu/virtualenvs/venv-2.7.9/lib/python2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 712, in find_element
    {'using': by, 'value': value})['value']
  File "/home/ubuntu/virtualenvs/venv-2.7.9/lib/python2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 201, in execute
    self.error_handler.check_response(response)
  File "/home/ubuntu/virtualenvs/venv-2.7.9/lib/python2.7/site-packages/selenium/webdriver/remote/errorhandler.py", line 193, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.NoSuchElementException: Message: no such element
  (Session info: chrome=43.0.2357.130)

(Driver info: chromedriver=2.16.333243 (0bfa1d3575fc1044244f21ddb82bf870944ef961),platform=Linux 3.13.0-76-generic x86_64) python /home/ubuntu/app/tests/tests.py returned exit code 1

终于想通了。来自 http://docs.seleniumhq.org/docs/04_webdriver_advanced.jsp#remotewebdriver

driver.get('http://localhost:4444/wd/hub')

设置正确,标准打印语句可以将结果输出回 CircleCI。