2016-09-16 2 views
0

Ich versuche, Chrome-Tests lokal auf dem Mac (El Capitan) auszuführen, aber ich kann die Tests nicht lokal auf Chrome ausführen, ich kann Chrome mit Remote-Webdriver aufrufen. Aber wenn ich versuche, die Tests ohne die Fernbedienung WebDriver d.h rufenden Chrom laufen direkt erhalte ich FehlerSeleniumtests können nicht lokal auf Mac ausgeführt werden

driver/chrome/webdriver.py", line 62, in __init__ 
    self.service.start() 
    File "/Users/testuser/practise/venv/lib/python2.7/site-packages/selenium/webdriver/common/service.py", line 92, in start 
    raise WebDriverException("Can not connect to the Service %s" % self.path) 
WebDriverException: Message: Can not connect to the Service chromedriver 

Ich habe die chromedriver binäre sich in /usr/local/bin und ich habe das gleiche in meinem PATH auch.

Selenium Version: selenium (2.53.6) 
Chromedriver Version: 2.24.417412 
Python Version: 2.7.10 

MY Beispielskript

# Import unittest module for creating unit tests 
import unittest 

# Import time module to implement 
import time 

# Import the Selenium 2 module (aka "webdriver") 
from selenium import webdriver 

# For automating data input 
from selenium.webdriver.common.keys import Keys 

# For providing custom configurations for Chrome to run 
from selenium.webdriver.chrome.options import Options 


# -------------------------------------- 
# Provide a class for the unit test case 
class PythonOrgSearchChrome(unittest.TestCase): 

    # Anything declared in setUp will be executed for all test cases 
    def setUp(self): 
     # Select which device you want to emulate by uncommenting it 
     # More information at: https://sites.google.com/a/chromium.org/chromedriver/mobile-emulation 
     mobile_emulation = { 

      "deviceName": "Google Nexus 5" 
      # Or specify a specific build using the following two arguments 
      #"deviceMetrics": { "width": 360, "height": 640, "pixelRatio": 3.0 }, 
      #"userAgent": "Mozilla/5.0 (Linux; Android 4.2.1; en-us; Nexus 5 Build/JOP40D) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.166 Mobile Safari/535.19" } 
     } 

     # Define a variable to hold all the configurations we want 
     chrome_options = webdriver.ChromeOptions() 

     # Add the mobile emulation to the chrome options variable 
     chrome_options.add_experimental_option("mobileEmulation", mobile_emulation) 

     # Create driver, pass it the path to the chromedriver file and the special configurations you want to run 
     self.driver = webdriver.Chrome(chrome_options=chrome_options) 

    # An individual test case. Must start with 'test_' (as per unittest module) 
    def test_search_in_python_chrome(self): 
     # Assigning a local variable for the global driver 
     driver = self.driver 

     # Go to google.com 
     driver.get('http://www.google.com') 

     # A test to ensure the page has keyword Google in the page title 
     self.assertIn("Google", driver.title) 



     # Find and select the search box element on the page 
     search_box = driver.find_element_by_name('q') 

     # Enter text into the search box 
     search_box.send_keys('Cat gif') 

     # Make sure the results page returned something 
     assert "No results found." not in driver.page_source 

     # Submit the search box form 
     search_box.submit() 

     # Can also use Keys function to submit 
     #search_box.send_keys(Keys.RETURN) 

     # Another pause so we can see what's going on 
     time.sleep(5) 

     # Take a screenshot of the results 
     driver.save_screenshot('screenshot-deskto-chrome.png') 

    # Anything declared in tearDown will be executed for all test cases 
    def tearDown(self): 
     # Close the browser. 
     # Note close() will close the current tab, if its the last tab it will close the browser. To close the browser entirely use quit() 
     self.driver.close() 

# Boilerplate code to start the unit tests 
if __name__ == "__main__": 
    unittest.main() 

Ich bin wirklich nicht sicher, was passiert ist, weil ich in der Lage bin über den Browser Remote WebDriver zu starten, Jede Hilfe wäre sehr geschätzt.

+0

Haben Sie neueste Selen mit neuesten chromedriver versucht? Um Probleme im Zusammenhang mit dem Pfad zu vermeiden, können Sie beide (selen und chromedriver) im selben Verzeichnis speichern und von dort aus ausführen. Manchmal kann es zu Inkompatibilitäten zwischen dem Chrome-Browser und dem Chrome-Browser kommen, wenn der Browser automatisch aktualisiert wird. – lauda

+0

AFAIK laufen die neuesten Versionen von Chrom-Treiber und Selen. Das gleiche funktioniert gut, wenn ich den Chrome mit Remote-Webdriver aufrufen. Wenn es ein Pfadproblem war, dann sollte sich der Remote-Webdriver auch beschwert haben – sri85

+0

Ich denke, dass das neueste Selen 3.0 ist. Bitte überprüfen und sehen Sie hier meine Antwort, wie Selen mit chromedriver starten http://stackoverflow.com/questions/39468600/how-to-run-tests-in-behate-on-firefox-48-0-using-selenium- Standalone-Server – lauda

Antwort

0

ich glaube, ich habe die Antwort gefunden, in meinem /etc/hostslocalhost auf etwas anderes als Ergebnis abgebildet wurde, die ich bekam

driver/chrome/webdriver.py", line 62, in __init__ 
    self.service.start() 
    File "/Users/testuser/practise/venv/lib/python2.7/site-packages/selenium/webdriver/common/service.py", line 92, in start 
    raise WebDriverException("Can not connect to the Service %s" % self.path) 
WebDriverException: Message: Can not connect to the Service chromedriver 
Verwandte Themen