Beispiel #1
0
	def getWebDriver(self, type="chrome"):
		'''Initialize webdriver and return 
		Parameter:
		type: str (optional)
			value: chrome or firefox
			retrun chrome wendriver if value is unspecified'''
			
		from selenium import webdriver
		from selenium.webdriver.common.keys import Keys
		if type == "firefox":
			return webdriver.Firefox()
		else:
			return webdriver.Chrome()
Beispiel #2
0
class Test(unittest.TestCase):
    #装饰器截图
    driver = webdriver.Firefox()  # 全局参数driver

    def setUp(self):
        self.driver.get("https://www.baidu.com")

    @Screen(driver)
    def test01(self):
        u'''这个是失败的案例'''
        self.driver.find_element_by_id("11kw").send_keys("python")
        self.driver.find_element_by_id("su").click()

    @Screen(driver)
    def test_02(self):
        u'''这个是通过的案例'''
        self.driver.find_element_by_id("kw").send_keys("yoyo")
        self.driver.find_element_by_id("su").click()

    def tearDown(self):
        self.driver.quit()
def DeviceSetup(request, device):
    print("Running device setUp")
    if safe_str_cmp(device, 'ios'):
        print("Tests will be executed on ios")
        driver = webdriver.Firefox()
    elif safe_str_cmp(device, 'android'):
        print("Tests will be executed on Android")
        desired_caps = {}
        desired_caps['platformName'] = 'Android'
        desired_caps['automationName'] = 'uiautomator2'
        desired_caps['deviceName'] = 'emulator-5554'
        desired_caps['appPackage'] = 'com.android.calculator2'
        desired_caps['appActivity'] = 'com.android.calculator2.Calculator'

        driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)

    #add implicity wait
    if request.cls:
        request.cls.driver = driver

    yield driver
Beispiel #4
0
 def setUp(self):
     self.driver = webdriver.Firefox()
     self.driver.maximize_window()
     self.driver.get('http://www.baidu.com')
     self.driver.implicitly_wait(30)
Beispiel #5
0
def before_all(context):
    context.browser = webdriver.Firefox()
    # context.browser = webdriver.Chrome() if you have set chromedriver in your PATH
    context.browser.set_page_load_timeout(10)
    context.browser.implicitly_wait(10)
    context.browser.maximize_window()
Beispiel #6
0
# coding:utf-8
from appium import webdriver
from selenium import webdriver
from selenium.common.exceptions import NoSuchElementException
import time


driver = webdriver.Firefox()
driver.get("https://www.cnblogs.com/shanliguniang/")
try:
    element = driver.find_element("id","blog_nav_newpostxx")
except NoSuchElementException as msg:
    print u"查找元素异常%s"%msg
    nowTime = time.strftime("%Y%m%d.%H.%M.%S")
    t = driver.get_screanshot_as_file('%s.jpg'%nowTime)
    print(u"截图结果:%s"%t)
else:
    element.click()
Beispiel #7
0
def get_driver():
    driver = webdriver.Firefox()
    driver.get("http://www.tpshop.com/Home/user/login.html")
    return driver
 def get_driver(cls):
     if not cls.driver:
         cls.driver = webdriver.Firefox()
         cls.driver.maximize_window()
         cls.driver.get(page.url)
     return cls.driver
Beispiel #9
0
    def setup(self):
        """
        设置单机版 浏览器驱动
        :return:
        """
        # 判断当前系统
        try:
            if self.inspect_url_code(self.url):  # 如果项目地址正常
                current_sys = sys.platform.lower()
                log_path = os.path.join(LOG_DIR, f'{DAY}firefox.log')

                if current_sys == 'linux':  # linux系统

                    if self.browser == 'chrome':  # 谷歌浏览器
                        option = self.linux_chrome_args
                        driver = webdriver.Chrome(executable_path=LUINX_CHROMEDRIVER, options=option)
                        return self.browaer_setup_args(driver)

                    elif self.browser == 'firefox':  # 火狐浏览器
                        options = self.linux_firefox_args
                        driver = webdriver.Firefox(executable_path=LUINX_FIREFOXDRIVER, options=options,
                                                   service_log_path=log_path)
                        drivers = self.browaer_setup_args(driver)
                        return drivers # 在linux下启用 火狐浏览器需要借助Display

                    else:
                        logger.error(f'linux系统不支持此浏览器: {self.browser}')
                        return False

                elif current_sys == 'darwin':  # mac 系统

                    if self.browser == 'chrome':
                        driver = webdriver.Chrome(executable_path=MAC_CHROMEDRIVER)
                        return self.browaer_setup_args(driver)

                    elif self.browser == 'firefox':
                        driver = webdriver.Firefox(executable_path=MAC_FIREFOXDRIVER, service_log_path=log_path)
                        return self.browaer_setup_args(driver)

                    elif self.browser == 'safari':
                        driver = webdriver.Safari()
                        return self.browaer_setup_args(driver)

                    else:
                        logger.error(f'mac系统不支持此浏览器: {self.browser}')
                        return False
                elif current_sys == 'win32':

                    if self.browser == 'ie':
                        logger.warning('请确保当前服务器安装IE!')
                        driver = webdriver.Ie(executable_path=IE_PATH)
                        return self.browaer_setup_args(driver)

                    if self.browser == 'chrome':
                        driver = webdriver.Chrome(executable_path=WIN_CHROMEDRIVER)
                        return self.browaer_setup_args(driver)

                    elif self.browser == 'firefox':
                        driver = webdriver.Firefox(executable_path=WIN_FIREFOXDRIVER, service_log_path=log_path)
                        return self.browaer_setup_args(driver, )

                    else:
                        logger.error(f'windos系统不支持此浏览器: {self.browser}')

                        return False
                else:
                    logger.error(f'当前{current_sys}系统不支持!')
                    return False
            else:
                logger.error('项目地址地址请求异常!!!')
                return False

        except Exception as e:
            logger.error(f'浏览器驱动启动失败 {e}')
            return False