在CircleCI上运行python Selenium测试

时间:2016-02-05 06:54:12

标签: python selenium 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的界面(print语句显然不起作用)

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

这是完整的追溯:

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

1 个答案:

答案 0 :(得分:0)

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

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

正确设置它,标准的print语句可以将结果输出回CircleCI。