RobotFramework环境配置七:多浏览器兼容性测试(1)

多浏览器兼容性测试(1)

RIDE已经支持多浏览器兼容性测试,例如:
firefox
ie
chrome
safari
但是,项目要求支持360极速和360安全浏览器。所以,我们需要增加代码让RIDE识别。其他浏览器类似(本地浏览器)。
说明:基于Selenium: 3.0.2

一、各浏览器webdriver

说明:
1. selenium3.x中,firefox需要下载webdriver(geckodriver.exe)。
2. 360极速和360安全浏览器的内核是chrome,目前支持内核版本45.x。拷贝两份chromedriver 2.20,可以重命名为360chromedriver & 360sechromedriver。

RobotFramework环境配置七:多浏览器兼容性测试(1)_第1张图片

RobotFramework环境配置七:多浏览器兼容性测试(1)_第2张图片

RobotFramework环境配置七:多浏览器兼容性测试(1)_第3张图片

PS:注意,360浏览器会自动升级。请关闭自动升级。
目录:C:\Users\username\AppData\Roaming\360se6\Application\8.1.1.250\installer,找到chromeup.dll文件,删除或者重命名。

RobotFramework环境配置七:多浏览器兼容性测试(1)_第4张图片

二、增加代码支持让RIDE识别360浏览器

修改selenium\webdriver目录下__init__.py代码。
目录:C:\Python27\Lib\site-packages\selenium\webdriver

from .firefox.webdriver import WebDriver as Firefox  # noqa
from .firefox.firefox_profile import FirefoxProfile  # noqa
from .chrome.webdriver import WebDriver as Chrome  # noqa
from .chrome.options import Options as ChromeOptions  # noqa
# 360 support
from .chrome360.webdriver import WebDriver as Chrome360 # 360 extreme browser
from .chrome360se.webdriver import WebDriver as Chrome360se # 360 security browser
#
from .ie.webdriver import WebDriver as Ie  # noqa
from .edge.webdriver import WebDriver as Edge  # noqa
from .opera.webdriver import WebDriver as Opera  # noqa
from .safari.webdriver import WebDriver as Safari  # noqa
from .blackberry.webdriver import WebDriver as BlackBerry  # noqa
from .phantomjs.webdriver import WebDriver as PhantomJS  # noqa
from .android.webdriver import WebDriver as Android  # noqa
from .remote.webdriver import WebDriver as Remote  # noqa
from .common.desired_capabilities import DesiredCapabilities  # noqa
from .common.action_chains import ActionChains  # noqa
from .common.touch_actions import TouchActions  # noqa
from .common.proxy import Proxy  # noqa

__version__ = '3.0.2'

修改Selenium2Library\keywords下browsermanagement.py代码
目录:C:\Python27\Lib\site-packages\robotframework_selenium2library-1.8.1-py2.7.egg\Selenium2Library\keywords

代码段一:

ROOT_DIR = os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))
FIREFOX_PROFILE_DIR = os.path.join(ROOT_DIR, 'resources', 'firefoxprofile')
BROWSER_NAMES = {'ff': "_make_ff",
                 'firefox': "_make_ff",
                 'ie': "_make_ie",
                 'internetexplorer': "_make_ie",
                 'googlechrome': "_make_chrome",
                 'gc': "_make_chrome",
                 'chrome': "_make_chrome",
                 #360 Extreme Browser
                 'chrome360': "_make_chrome360",
                 #360 Security Browser
                 'chrome360se': "_make_chrome360se",
                 'opera' : "_make_opera",
                 'phantomjs' : "_make_phantomjs",
                 'htmlunit' : "_make_htmlunit",
                 'htmlunitwithjs' : "_make_htmlunitwithjs",
                 'android': "_make_android",
                 'iphone': "_make_iphone",
                 'safari': "_make_safari",
                 'edge': "_make_edge"
                }

代码二:搜索def _make_chrome,增加两段代码

    def _make_chrome(self , remote , desired_capabilities , profile_dir):
        return self._generic_make_browser(webdriver.Chrome,
                webdriver.DesiredCapabilities.CHROME, remote, desired_capabilities)

#360 Extreme Browser
    def _make_chrome360(self , remote , desired_capabilities , profile_dir):
        return self._generic_make_browser(webdriver.Chrome360,
                webdriver.DesiredCapabilities.CHROME, remote, desired_capabilities)

#360 Security Browser
    def _make_chrome360se(self , remote , desired_capabilities , profile_dir):
        return self._generic_make_browser(webdriver.Chrome360se,
                webdriver.DesiredCapabilities.CHROME, remote, desired_capabilities)

三、360浏览器的实现代码

目录:C:\Python27\Lib\site-packages\selenium\webdriver

RobotFramework环境配置七:多浏览器兼容性测试(1)_第5张图片

RobotFramework环境配置七:多浏览器兼容性测试(1)_第6张图片

文件1:__init__.py,可以为空,也可以增加说明文字。例如,作者,版本,功能等。
文件2:新建webdriver.py,实现360极速浏览器。代码如下:

from selenium.webdriver import Chrome as ChromeWebdriver
from selenium.webdriver.chrome.options import Options
import os

class WebDriver(ChromeWebdriver):

    def __init__(self, b360bin=None, executable_path="360chromedriver", port=0,
                    chrome_options=None, service_args=None,
                    desired_capabilities=None, service_log_path=None):

        # 360 broswer direction
        if b360bin:
            self.bin = b360bin
        else:
            self.bin = r'%s\360Chrome\Chrome\Application\360chrome.exe' % os.getenv('LOCALAPPDATA') 
        chrome_options = Options()
        chrome_options.binary_location = self.bin
        ChromeWebdriver.__init__(self, executable_path, port,
                    chrome_options, service_args,
                    desired_capabilities, service_log_path)

360安全浏览器类似:

from selenium.webdriver import Chrome as ChromeWebdriver
from selenium.webdriver.chrome.options import Options
import os

class WebDriver(ChromeWebdriver):

    def __init__(self, b360bin=None, executable_path="360sechromedriver", port=0,
                    chrome_options=None, service_args=None,
                    desired_capabilities=None, service_log_path=None):

        # 360se broswer direction
        if b360bin:
            self.bin = b360bin
        else:
            self.bin = r'C:\Users\Administrator\AppData\Roaming\360se6\Application\360se.exe' 
        chrome_options = Options()
        chrome_options.binary_location = self.bin
        ChromeWebdriver.__init__(self, executable_path, port,
                    chrome_options, service_args,
                    desired_capabilities, service_log_path)

你可能感兴趣的:(Robotframework)