Пример #1
0
def setup_module(m):
    global driver
    driver = SeleneDriver.wrap(webdriver.Chrome(ChromeDriverManager().install()))
    global GIVEN_PAGE
    GIVEN_PAGE = GivenPage(driver)
    global WHEN
    WHEN = GIVEN_PAGE
Пример #2
0
def driver():
    # テスト前処理
    options = ChromeOptions()
    # ヘッドレスモードを有効にする(次の行をコメントアウトすると画面が表示される)
    options.add_argument('--headless')

    # Selene使用前の記述はコメントアウトしています
    # # ChromeのWebDriverオブジェクトを作成する
    # driver = Chrome(options=options,
    #                 executable_path='/usr/local/bin/chromedriver')

    # # Windowsの場合のChromeのWebDriverオブジェクトの作成はこちらのコードになります
    # # ChromeのWebDriverオブジェクトを作成する
    # options.binary_location = \
    #     "C:\\Program Files (x86)" \
    #     "\\Google\\Chrome\\Application\\chrome.exe"
    # driver = Chrome(
    #     options=options,
    #     executable_path=
    #     'D:\\Program\\chromedriver_win32\\chromedriver.exe')

    # ChromeのWebDriverオブジェクトを作成する
    chrome_driver = Chrome(options=options,
                           executable_path='/usr/local/bin/chromedriver')
    # SeleneDriverにラップする
    driver = SeleneDriver.wrap(chrome_driver)

    # テストケース実施
    yield driver

    # テスト後処理
    driver.close()
Пример #3
0
def setup_module(m):
    global driver
    driver = SeleneDriver.wrap(get_test_driver())
    global GIVEN_PAGE
    GIVEN_PAGE = GivenPage(driver)
    global WHEN
    WHEN = GIVEN_PAGE
Пример #4
0
def setup_module(m):
    global driver
    driver = SeleneDriver.wrap(webdriver.Firefox())
    global GIVEN_PAGE
    GIVEN_PAGE = GivenPage(driver)
    global WHEN
    WHEN = GIVEN_PAGE
Пример #5
0
def main():
    ranking_url = "https://3ds.pokemon-gl.com/battle/usum/"
    options = Options()
    options.add_argument('--headless')
    driver = SeleneDriver.wrap(webdriver.Chrome(executable_path=ChromeDriverManager().install(), chrome_options=options))
    driver.get(ranking_url)
    ranking = driver.find_elements_by_class_name("pokemon-ranking-item")
    pattern = r"\(.+?\)"
    reg = re.compile(pattern)
    ranking_img_paths = [reg.search(elem.find_element_by_tag_name("img").get_attribute("style")).group()[2:-2] for elem in ranking]
    ranking_pokemon_names = [elem.find_element_by_class_name("name").text for elem in ranking]
    for path, name in zip(ranking_img_paths, ranking_pokemon_names):
        file_name = os.path.join("data", name)
        download(path, file_name)
        row = Image.open(file_name)
        resize_img = row.resize((200, 200))
        crops = []
        crops.append(resize_img.crop((0, 0, 100, 100)))
        crops.append(resize_img.crop((100, 0, 200, 100)))
        crops.append(resize_img.crop((0, 100, 100, 200)))
        crops.append(resize_img.crop((100, 100, 200, 200)))
        output = Image.new('RGBA', (200, 200), (255, 255, 255))
        output.paste(crops[0], (100, 100))
        output.paste(crops[1], (0, 100))
        output.paste(crops[2], (100, 0))
        output.paste(crops[3], (0, 0))
        output.save(file_name, "PNG", quality=100, optimize=True)
    driver.quit()
Пример #6
0
def test_blaze_with_explicit_driver():
    """Tried combining Selene and Selenium for better readability and usability"""
    driver = SeleneDriver.wrap(Chrome())
    try:
        driver.get('http://www.blazedemo.com/')
        Select(driver.element(
            by.name('fromPort'))).select_by_visible_text('Boston')
        Select(driver.element(
            by.name('toPort'))).select_by_visible_text('Berlin')
        driver.element('input[type="submit"]').click()
        driver.element('.container>h3').should(
            have.text('Flights from Boston to Berlin:'))
    finally:
        driver.quit()
Пример #7
0
def google(url, keyword):
    # run chrome headless
    options = Options()
    options.add_argument('--headless')
    driver = SeleneDriver.wrap(
        webdriver.Chrome(executable_path=ChromeDriverManager().install(),
                         chrome_options=options))
    driver.get(url)
    input = driver.find_element_by_name('q')
    input.send_keys(keyword)
    input.send_keys(Keys.RETURN)

    # save screen shot
    driver.save_screenshot(keyword + '.png')

    driver.quit()
Пример #8
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-

from selenium import webdriver
from selenium.webdriver import Chrome
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.keys import Keys
from selene.driver import SeleneDriver
from webdriver_manager.chrome import ChromeDriverManager

# run chrome headless
options = Options()
options.add_argument('--headless')

# install chromedriver if not found and start chrome
driver = SeleneDriver.wrap(webdriver.Chrome(executable_path=ChromeDriverManager().install(), chrome_options=options))

# search 'python' in google
driver.get('https://www.google.co.jp/')
input = driver.find_element_by_name('q')
input.send_keys('Python')
input.send_keys(Keys.RETURN)

# save screen shot
driver.save_screenshot('result.png')

driver.quit()