码迷,mamicode.com
首页 > 其他好文 > 详细

centos7在命令界面使用命令可以执行,但在jenkins中输入命令报Chrome has crashed.

时间:2019-09-23 10:24:16      阅读:131      评论:0      收藏:0      [点我收藏+]

标签:谷歌浏览器   google   ima   crash   dir   意思   delay   系统   tca   

问题:selenium.common.exceptions.WebDriverException: Message: unknown error: Chrome failed to start: exited abnormally
  (unknown error: DevToolsActivePort file doesn‘t exist)
  (The process started from chrome location /usr/bin/google-chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed.

 

解决方法:设置为不用打开图形界面运行浏览器,代码如下:

    #使用谷歌浏览器
    def getChromeDriver(self):
        chrome_options = webdriver.ChromeOptions()   #为驱动加入无界面配置

        chrome_options.add_argument(--headless)   #–headless”参数是不用打开图形界面
        chrome_options.add_argument(--no-sandbox)  #“–no - sandbox”参数是让Chrome在root权限下跑
        # chrome_options.add_argument(--disable-dev-shm-usage) #不加载图片, 提升速度
        # chrome_options.add_argument(blink-settings=imagesEnabled=false)
        # chrome_options.add_argument(--disable-gpu) # 谷歌文档提到需要加上这个属性来规避bug
        # chromedriver = webdriver.Chrome(chrome_options=chrome_options)
        # chromedriver = webdriver.Chrome()  # 需要把驱动所在路径配置到系统环境变量里
        path = r"%s/driver/chromedriver"% str(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) )  #配置驱动路径
        print("path:%s" % path)
        # path = r"D:\Users\Administrator\PycharmProjects\webtestdata\TestCaseFunction\driver\chromedriver.exe"  #配置驱动路径
        # option = webdriver.ChromeOptions()
        # option.add_argument(--user-data-dir=C:\\Users\\Administrator\\Local\\Google\\Chrome\\User Data\\Default)  # 设置成用户自己的数据目录
        #                                                             #浏览器输入chrome://version 下个人资料路径就是自己的数据目录
        # chromedriver = webdriver.Chrome(chrome_options=chrome_options)
        chromedriver = webdriver.Chrome(executable_path=path,chrome_options=chrome_options)
        # chromedriver = webdriver.Chrome(executable_path=path)
        # chromedriver = webdriver.Chrome(executable_path=path)
        chromedriver.maximize_window()   #窗口最大化
        self.delayTime(5)
        return  chromedriver

其中“chrome_options.add_argument(--headless)   #–headless”参数是不用打开图形界面”这行是关键,意思是设置为不用打开图形界面运行,

其中chromedriver = webdriver.Chrome(executable_path=path,chrome_options=chrome_options)这行中的“chrome_options=chrome_options”是将上面设置的参数添加到驱动中,

否则 “不用打开图形界面运行”的设置不会生效,就是一直报"Chrome has crashed"的错。

 

centos7在命令界面使用命令可以执行,但在jenkins中输入命令报Chrome has crashed.

标签:谷歌浏览器   google   ima   crash   dir   意思   delay   系统   tca   

原文地址:https://www.cnblogs.com/jingzaixin/p/11570444.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!