예제 #1
0
import unittest

from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions
from selenium.webdriver.support.wait import WebDriverWait

from pwdriver.core import WebDriverFactory
from pwdriver.val import OS_NAME
from pwdriver import util

logger = util.get_logger('edge')


class EdgeTest(unittest.TestCase):
    def setUp(self):
        WebDriverFactory().setup_edgedriver()
        from msedge.selenium_tools import Edge, EdgeOptions
        options = EdgeOptions()
        options.use_chromium = True
        options.set_capability('platform', 'MAC' if OS_NAME == 'MAC' else 'WINDOWS')
        self.driver1 = Edge(options=options)
        self.driver2 = Edge(options=options)
        self.driver1.maximize_window()
        self.wait1 = WebDriverWait(self.driver1, 5)
        self.wait2 = WebDriverWait(self.driver2, 5)

    def tearDown(self):
        self.driver2.quit()
        self.driver1.quit()

    def test_something(self):
예제 #2
0
from selenium.webdriver.support.abstract_event_listener import AbstractEventListener

from pwdriver.util import get_logger


logger = get_logger('listener')


class EventListener(AbstractEventListener):
    def before_navigate_to(self, url, driver):
        logger.info(f'{driver.current_url} -> {url}')

    def before_navigate_back(self, driver):
        logger.info(f'{driver.current_url} -> history.back')

    def before_navigate_forward(self, driver):
        logger.info(f'{driver.current_url} -> history.forward')

    def before_find(self, by, value, driver):
        logger.info(f'{by}: {value}')

    def before_click(self, element, driver):
        logger.info(f'tag: {element.tag_name}({element.location})')

    def before_change_value_of(self, element, driver):
        logger.info(element.text)

    def before_execute_script(self, script, driver):
        logger.info(script)
예제 #3
0
파일: ie.py 프로젝트: jinmoo21/PWDriver
import unittest

from selenium import webdriver
from selenium.webdriver import IeOptions
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions
from selenium.webdriver.support.wait import WebDriverWait

from pwdriver import util
from pwdriver.core import WebDriverFactory
from pwdriver.val import OS_NAME

logger = util.get_logger('ie')


@unittest.skipIf(OS_NAME == 'MAC', 'Cannot run on Mac.')
class IeTest(unittest.TestCase):
    def setUp(self):
        WebDriverFactory().setup_iedriver()
        options = IeOptions()
        options.ignore_protected_mode_settings = True
        options.ensure_clean_session = True
        options.require_window_focus = True
        options.ignore_zoom_level = True
        self.driver1 = webdriver.Ie(options=options)
        self.driver2 = webdriver.Ie(options=options)
        self.driver1.maximize_window()
        self.wait1 = WebDriverWait(self.driver1, 5)
        self.wait2 = WebDriverWait(self.driver2, 5)

    def tearDown(self):
예제 #4
0
파일: safari.py 프로젝트: jinmoo21/PWDriver
import unittest

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions
from selenium.webdriver.support.wait import WebDriverWait

from pwdriver import util
from pwdriver.val import OS_NAME

logger = util.get_logger('safari')


@unittest.skipIf(OS_NAME == 'WIN', 'Cannot run on Windows.')
class SafariTest(unittest.TestCase):
    def setUp(self):
        self.driver = webdriver.Safari()
        self.driver.maximize_window()
        self.wait = WebDriverWait(self.driver, 5)

    def tearDown(self):
        self.driver.quit()

    def test_something(self):
        self.driver.get('https://www.google.com')
        logger.info(self.driver.title)
        self.assertIn(self.driver.title, 'Google')
        self.driver.get('https://www.naver.com')
        news_btn = self.driver.find_element(By.CSS_SELECTOR, '.link_news')
        news_btn.click()
        logger.info(self.driver.current_url)
예제 #5
0
파일: core.py 프로젝트: jinmoo21/PWDriver
import os
import re
import requests
import tarfile
import zipfile

from selenium import webdriver

from pwdriver.val import CONFIG_NAME, CHROME, CHROMEDRIVER, CHROMEDRIVER_API, CHROMEDRIVER_NAME, DRIVER, \
    EDGE, EDGEDRIVER, EDGEDRIVER_API, EDGEDRIVER_NAME, GECKO, GECKODRIVER, GECKODRIVER_API, GECKODRIVER_NAME, \
    IE, IEDRIVER, IEDRIVER_API, IEDRIVER_NAME, INI, LOG, LOG_DIR, OS_BIT, OS_NAME, ROOT_DIR, SAFARI, TAR_GZ, ZIP
from pwdriver import util

logger = util.get_logger('core')


class WebDriverFactory:
    def _set_config(self):
        import configparser as cp
        config = cp.ConfigParser()
        import glob
        config_path = glob.glob(os.path.join(ROOT_DIR, '**', CONFIG_NAME), recursive=True)[0]
        if not os.path.isfile(config_path):
            raise NotImplementedError(f'Not found \'.ini\' configuration file in directory.')
        config.read(config_path)
        self._automation_browser = config.get('automation', 'automation.browser')
        if self._automation_browser not in [CHROME, GECKO, EDGE, IE, SAFARI]:
            raise NotImplementedError(f'Unsupported browser name: {self._automation_browser}')
        self._automation_local = util.parse_boolean(config.get('automation', 'automation.local'))
        if self._automation_browser in [EDGE, IE, SAFARI] and not self._automation_local:
            raise NotImplementedError(f'{self._automation_browser} browser not installed on remote.')
예제 #6
0
import unittest

from selenium.webdriver.common.by import By
from selenium.webdriver.support.events import EventFiringWebDriver
from selenium.webdriver.support import expected_conditions
from selenium.webdriver.support.wait import WebDriverWait

from pwdriver.core import WebDriverFactory
from pwdriver.listener import EventListener
from pwdriver.util import get_logger


logger = get_logger('eventdriver')


class EventDriverTest(unittest.TestCase):
    def setUp(self):
        core1 = WebDriverFactory().launch()
        core2 = WebDriverFactory().launch()
        self.driver1 = EventFiringWebDriver(core1, EventListener())
        self.driver2 = EventFiringWebDriver(core2, EventListener())
        self.driver1.maximize_window()
        self.wait1 = WebDriverWait(self.driver1, 5)
        self.wait2 = WebDriverWait(self.driver2, 5)

    def tearDown(self):
        self.driver2.quit()
        self.driver1.quit()

    def test_something(self):
        self.driver1.get('https://www.google.com')
예제 #7
0
import unittest

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions
from selenium.webdriver.support.wait import WebDriverWait

from pwdriver.core import WebDriverFactory
from pwdriver import util

logger = util.get_logger('firefox')


class FirefoxTest(unittest.TestCase):
    def setUp(self):
        WebDriverFactory().setup_geckodriver()
        self.driver1 = webdriver.Firefox()
        self.driver2 = webdriver.Firefox()
        self.driver1.maximize_window()
        self.wait1 = WebDriverWait(self.driver1, 5)
        self.wait2 = WebDriverWait(self.driver2, 5)

    def tearDown(self):
        self.driver2.quit()
        self.driver1.quit()

    def test_something(self):
        self.driver1.get('https://www.google.com')
        logger.info(self.driver1.title)
        self.assertIn(self.driver1.title, 'Google')
        self.driver1.get('https://www.naver.com')
예제 #8
0
파일: chrome.py 프로젝트: jinmoo21/PWDriver
import unittest

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions
from selenium.webdriver.support.wait import WebDriverWait

from pwdriver.core import WebDriverFactory
from pwdriver import util

logger = util.get_logger('chrome')


class ChromeTest(unittest.TestCase):
    def setUp(self):
        WebDriverFactory().setup_chromedriver()
        self.driver1 = webdriver.Chrome()
        self.driver2 = webdriver.Chrome()
        self.driver1.maximize_window()
        self.wait1 = WebDriverWait(self.driver1, 5)
        self.wait2 = WebDriverWait(self.driver2, 5)

    def tearDown(self):
        self.driver2.quit()
        self.driver1.quit()

    def test_something(self):
        self.driver1.get('https://www.google.com')
        logger.info(self.driver1.title)
        self.assertIn(self.driver1.title, 'Google')
        self.driver1.get('https://www.naver.com')