51Testing软件测试论坛

标题: 远程服务器控制浏览器一直报错 [WinError 10061] [打印本页]

作者: 成长的喵星人    时间: 2016-6-16 13:00
标题: 远程服务器控制浏览器一直报错 [WinError 10061]
用的是python+selenium server

程序如下:
#coding=utf-8
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import Select
from selenium.common.exceptions import NoSuchElementException
import unittest, time, re
from Public import login
from Public import url
import xml.dom.minidom
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
from selenium.webdriver import Remote


#引入xml文件
dom=xml.dom.minidom.parse('C:\\Python34\\enbrel_login\\data\\info.xml')
root=dom.documentElement

class EnbrelLogin(unittest.TestCase):
    def setUp(self):
        self.driver = url.browser(self)
        self.driver.implicitly_wait(30)
        #url,调用url.py
        self.base_url = url.url(self)
        self.verificationErrors = []
        self.accept_next_alert = True
        
    def test_enbrel_login(self):
        driver=self.driver
        driver.get(self.base_url)
        #登录,调用登录函数
        login.test_enbrel_login(self)
        #断言登录成功
        username=driver.find_element_by_id("dropdown-menu-head1").text
        self.assertEqual("Yi, Alina ",username)
        #退出,调用登录函数
        login.test_enbrel_logout(self)
    def tearDown(self):
        self.driver.quit()
        self.assertEqual([], self.verificationErrors)

if __name__ == "__main__":
    unittest.main()

调用模块1
import xml.dom.minidom
from selenium import webdriver
from selenium.webdriver import Remote
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
dom=xml.dom.minidom.parse('C:\\Python34\\enbrel_login\\data\\info.xml')
root=dom.documentElement
#读取url信息
url=root.getElementsByTagName("url")
geturl=url[0].firstChild.data

#读取浏览器信息
bb=root.getElementsByTagName('browser')
b=bb[0].firstChild.data

def url(self):
    return geturl

def browser(self):
    driver=webdriver.Remote(command_executor='http://127.0.0.1:4444/wd/hub',
                            desired_capabilities={'platform':'ANY',
                                                  'browserName':b,
                                                  'version':'',
                                                  'javascriptEnabled':True,
                                                  })
    return driver

调用模块2
#coding=utf-8
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import unittest, time

import xml.dom.minidom
#引入xml文件
dom=xml.dom.minidom.parse('C:\\Python34\\enbrel_login\\data\\info.xml')
root=dom.documentElement
#登录用户名和密码
bb=root.getElementsByTagName('login')
b=bb[0]
username=b.getAttribute("username")
password=b.getAttribute("password")

#登录  
def test_enbrel_login(self):
   
    driver = self.driver
    driver.find_element_by_id('username').clear()
    driver.find_element_by_id('username').send_keys(username)
    driver.find_element_by_id("password").clear()
    driver.find_element_by_id("password").send_keys(password)
    driver.find_element_by_id("btnLogin").click()
    time.sleep(2)
   
#退出
def test_enbrel_logout(self):
   
    driver=self.driver
    driver.find_element_by_xpath("//a[@id='dropdown-menu-head1']/span").click()
    driver.find_element_by_link_text("Logout").click()

一直报错

======================================================================
ERROR: test_enbrel_login (__main__.EnbrelLogin)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "C:\Python34\lib\urllib\request.py", line 1183, in do_open
    h.request(req.get_method(), req.selector, req.data, headers)
  File "C:\Python34\lib\http\client.py", line 1137, in request
    self._send_request(method, url, body, headers)
  File "C:\Python34\lib\http\client.py", line 1182, in _send_request
    self.endheaders(body)
  File "C:\Python34\lib\http\client.py", line 1133, in endheaders
    self._send_output(message_body)
  File "C:\Python34\lib\http\client.py", line 963, in _send_output
    self.send(msg)
  File "C:\Python34\lib\http\client.py", line 898, in send
    self.connect()
  File "C:\Python34\lib\http\client.py", line 871, in connect
    self.timeout, self.source_address)
  File "C:\Python34\lib\socket.py", line 516, in create_connection
    raise err
  File "C:\Python34\lib\socket.py", line 507, in create_connection
    sock.connect(sa)
ConnectionRefusedError: [WinError 10061] No connection could be made because the target machine actively refused it

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Python34\enbrel_login\login_case\enbrel_login.py", line 29, in setUp
    self.driver = url.browser(self)
  File "C:\Python34\enbrel_login\login_case\Public\url.py", line 23, in browser
    'javascriptEnabled':True,
  File "C:\Python34\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 90, in __init__
    self.start_session(desired_capabilities, browser_profile)
  File "C:\Python34\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 177, in start_session
    response = self.execute(Command.NEW_SESSION, capabilities)
  File "C:\Python34\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 234, in execute
    response = self.command_executor.execute(driver_command, params)
  File "C:\Python34\lib\site-packages\selenium\webdriver\remote\remote_connection.py", line 401, in execute
    return self._request(command_info[0], url, body=data)
  File "C:\Python34\lib\site-packages\selenium\webdriver\remote\remote_connection.py", line 469, in _request
    resp = opener.open(request, timeout=self._timeout)
  File "C:\Python34\lib\urllib\request.py", line 464, in open
    response = self._open(req, data)
  File "C:\Python34\lib\urllib\request.py", line 482, in _open
    '_open', req)
  File "C:\Python34\lib\urllib\request.py", line 442, in _call_chain
    result = func(*args)
  File "C:\Python34\lib\urllib\request.py", line 1211, in http_open
    return self.do_open(http.client.HTTPConnection, req)
  File "C:\Python34\lib\urllib\request.py", line 1185, in do_open
    raise URLError(err)
urllib.error.URLError: <urlopen error [WinError 10061] No connection could be made because the target machine actively refused it>

在网上找了很久,都没解决,有人知道吗?







欢迎光临 51Testing软件测试论坛 (http://bbs.51testing.com/) Powered by Discuz! X3.2