Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用Python的Selenium中的多个浏览器_Python_Selenium_Automated Tests - Fatal编程技术网

使用Python的Selenium中的多个浏览器

使用Python的Selenium中的多个浏览器,python,selenium,automated-tests,Python,Selenium,Automated Tests,我正在测试一个需要两个不同浏览器会话的聊天应用程序。我通过以下方式尝试了这一点: 启动了两种不同的浏览器,firefox和google chrome 试图打开网站的主页 代码如下: from selenium import selenium from selenium import webdriver from threading import Thread import unittest, time, re import time class envolveChatCheck(unit

我正在测试一个需要两个不同浏览器会话的聊天应用程序。我通过以下方式尝试了这一点:

  • 启动了两种不同的浏览器,firefox和google chrome
  • 试图打开网站的主页
代码如下:

from selenium import selenium
from selenium import webdriver
from threading import Thread
import unittest, time, re
import time


class envolveChatCheck(unittest.TestCase):

    def get_sauce_browser(self, port=4444, browser="*firefox"):
        return selenium('localhost', port, browser, 'http://example.com/')

    def get_browser_and_wait(self, browser, browser_num):
        print "starting browser %s" % browser_num
        browser.start()
        browser.open("/")
        print "browser %s ready" % browser_num

    def setUp(self):
        self.verificationErrors = []
        self.b1 = self.get_sauce_browser(browser='*googlechrome', port=4444)
        self.b2 = self.get_sauce_browser(browser='*firefox', port=4444)
        print "all browsers ready"

    def test_envolve_chat_check(self):
        print "starting b1"
        self.b1.start()
        print "starting b2"
        self.b2.start()

        print "opening homepage b1"
        self.b1.open("/")
        self.b1.wait_for_page_to_load("30000")

        print "opening homepage b2"
        self.b2.open("/")
        self.b2.wait_for_page_to_load("30000")


    def tearDown(self):
        self.b1.stop()
        self.b2.stop()
        self.assertEqual([], self.verificationErrors)
if __name__ == "__main__":
    unittest.main()
以下是我得到的错误:

Traceback (most recent call last):
File "envolveChatCheck.py", line 32, in test_envolve_chat_check
self.b1.open("/")
File "/usr/local/lib/python2.6/dist-packages/selenium/selenium.py", line 774, in open
self.do_command("open", [url,ignoreResponseCode])
File "/usr/local/lib/python2.6/dist-packages/selenium/selenium.py", line 214, in do_command
raise Exception, data
Exception: ERROR: Got a null result

有什么提示吗?

我的建议是使用多配置项目运行脚本

  • 下载并安装Jenkins
  • 转到管理插件
  • 在可用插件下选择“Python插件”
  • 可选(也有各种特定于Selenium的插件,尽管我没有有效地使用它们。假设系统上已经有Selenium)
  • 创建一个新作业并选择“构建多配置项目”
  • 在标题“配置矩阵”下单击“添加轴”
  • 选择“用户定义轴”
  • 设置轴的“名称”,类似于“浏览器”
  • “值”设置为要测试的浏览器,并用空格分隔。 例如:firefox“internet explorer”浏览器
    注意:我加了引号以确保internet explorer被视为一个值
  • 单击“添加构建步骤”
  • 选择“执行Python脚本”
  • 在python块中,您可以插入代码并提取前面设置的浏览器值:

    #!/usr/bin/python
    import os
    BROWSER = os.getenv('BROWSERS')
    
    Jenkins将使用前面创建的Axis中定义的值创建单独的作业,并且python脚本将为每个作业注入该值

    您可以用其他方法进一步扩展它,但这至少会帮助您关注测试用例逻辑,而不必太担心执行。上面的例子是基于Linux的


    注意:我使用SeleniumGrid插件和Windows从机从Linux运行IE测试脚本。

    在这里工作正常。您使用哪个版本的selenium服务器?你使用哪种版本的firefox和chrome?有时会正常执行,但如果执行多次,它就会开始崩溃。Firefox和chrome都有最新版本。