def get_driver(cls,selenium_hub,browser_type):
        driver=None
        browser_type=browser_type.lower()
        download_file_content_types = "application/octet-stream,application/vnd.ms-excel,text/csv,application/zip,application/binary"

        if browser_type=='ie':
            opt = ie_webdriver.Options()
            opt.force_create_process_api = True
            opt.ensure_clean_session = True
            opt.add_argument('-private')
            ie_capabilities = webdriver.DesiredCapabilities.INTERNETEXPLORER.copy()
            ie_capabilities.update(opt.to_capabilities())
            driver = webdriver.Remote(selenium_hub, desired_capabilities=ie_capabilities)
        elif browser_type=='firefox':
            firefox_profile=FirefoxProfile()
            # firefox_profile参数可以在火狐浏览器中访问about:config进行查看
            firefox_profile.set_preference('browser.download.folderList',2) # 0是桌面;1是“我的下载”;2是自定义
            firefox_profile.set_preference('browser.download.dir',ReadConfig().config.download_dir)
            firefox_profile.set_preference('browser.helperApps.neverAsk.saveToDisk',download_file_content_types)
            firefox_options = Firefox_Options()
            if ReadConfig().config.is_firefox_headless.lower()=='true':
                firefox_options.add_argument('--headless')
            driver = webdriver.Remote(selenium_hub, webdriver.DesiredCapabilities.FIREFOX.copy(),browser_profile=firefox_profile,options=firefox_options)
        elif browser_type=='chrome':
            chrome_options=Chrome_Options()
            prefs={'download.default_directory':ReadConfig().config.download_dir,'profile.default_content_settings.popups':0}
            chrome_options.add_experimental_option('prefs',prefs)
            if ReadConfig().config.is_chrome_headless.lower()=='true':
                chrome_options.add_argument('--headless')
            driver = webdriver.Remote(selenium_hub, webdriver.DesiredCapabilities.CHROME.copy(),options=chrome_options)
        else:
            return driver
        driver.maximize_window()
        driver.delete_all_cookies()
        return driver
    def __init__(self):
        if self.__inited is None:
            self.config = ReadConfig().config
            self.demoProjectConfig = DemoProjectReadConfig().config
            self.driver = webdriver.Remote(
                self.config.appium_hub,
                desired_capabilities=self.demoProjectConfig.
                get_desired_capabilities())
            self.appPerator = AppOperator(self.driver)

            self.__inited = True
Exemple #3
0
 def __init__(self, driver):
     self._config = ReadConfig().config
     self._doRequest = DoRequest(self._config.appium_hub)
     self._doRequest.setHeaders({'Content-Type': 'application/json'})
     self._driver = driver
     self._session_id = driver.session_id
     # 获得设备支持的性能数据类型
     self._performance_types = json.loads(
         self._doRequest.post_with_form(
             '/session/' + self._session_id +
             '/appium/performanceData/types').body)['value']
     # 获取当前窗口大小
     self._windows_size = self.get_window_size()
    def __init__(self,browserOperator_type=0):
        """
        :param browserOperator_type:0-未登录、1-已登录
        """
        self.config=ReadConfig().config
        self.demoProjectConfig=DemoProjectReadConfig().config

        self.driver = DriverTool.get_driver(self.config.selenium_hub, self.config.current_browser)
        self.driver.get(self.demoProjectConfig.web_host + '/cloud/auth/login/')
        self.browserOperator = BrowserOperator(self.driver)
        if browserOperator_type==1:
            loginPage=LoginPage(self.browserOperator)
            loginPage.login_success(self.demoProjectConfig.normal_username, self.demoProjectConfig.normal_password)
Exemple #5
0
import pytest
import sys

if __name__ == '__main__':
    parser = argparse.ArgumentParser()
    parser.add_argument('-k',
                        '--keyword',
                        help='只执行匹配关键字的用例,会匹配文件名、类名、方法名',
                        type=str)
    parser.add_argument('-d', '--dir', help='指定要测试的目录', type=str)
    args = parser.parse_args()

    print '开始初始化......'
    print '开始检测selenium server是否可用......'
    try:
        doRquest = DoRequest(ReadConfig().config.selenium_hub)
        httpResponseResult = doRquest.get('/status')
        result = json.loads(httpResponseResult.body)
        if result['status'] == 0:
            print 'selenium server状态为可用......'
        else:
            sys.exit('selenium server状态为不可用')
    except:
        sys.exit('selenium server状态为不可用')

    print '初始化基础数据......'
    init()
    print '初始化基础数据完成......'
    print '初始化完成......'

    print '开始测试......'
import pytest
import sys

if __name__ == '__main__':
    parser = argparse.ArgumentParser()
    parser.add_argument('-k',
                        '--keyword',
                        help='只执行匹配关键字的用例,会匹配文件名、类名、方法名',
                        type=str)
    parser.add_argument('-d', '--dir', help='指定要测试的目录', type=str)
    args = parser.parse_args()

    print '开始初始化......'
    print '开始检测appium server是否可用......'
    try:
        doRquest = DoRequest(ReadConfig().config.appium_hub)

        httpResponseResult = doRquest.get('/status')
        result = json.loads(httpResponseResult.body)
        if result['status'] == 0:
            print 'appium server状态为可用......'
        else:
            sys.exit('appium server状态为不可用')
    except:
        sys.exit('appium server状态为不可用')

    print '启动jvm......'
    jpype.startJVM(jpype.get_default_jvm_path(), "-ea",
                   "-Djava.class.path=" + JavaTool.getAllJar())
    print '启动jvm成功'