简体   繁体   中英

Running python Selenium tests on CircleCI

I'm trying to run some python selenium tests in the test phase of CircleCI.

My circle.yml looks like this:

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
...

and tests.py looks like this:

from selenium import webdriver

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

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

I have two questions:

First off, how to I output data from test.py back to CircleCI's interface (the print statement obviously doesn't work)

Secondly, what's the correct address to use in the driver.get() call, as I get an http://127.0.0.1/ is not available error?

Here's the full traceback:

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

Finally figured it out. From http://docs.seleniumhq.org/docs/04_webdriver_advanced.jsp#remotewebdriver

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

sets it up correctly and standard print statements do work to output results back to CircleCI.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM