Ejemplo n.º 1
0
	def __init__ ( self, p_config ):
	#----------------------------------------------------------------------

		BaseDriver.__init__(self, p_config)

		self.m_command = p_config.get_option_value('drivers', 'pipes_driver.command')
		self.m_popen   = None
Ejemplo n.º 2
0
def create_test_users(request, start_pennyworth_db_connection):
    """
    Gets login credentials for the test users. If using the database,
    creates the test users with a series of queries to the Pennyworth db.

    Credentials are stored in SSM with the following format:
    {
        "user_type1": {
            "username": "******",
            "password": "******",
            "passhash": "..."
        },
        ...
    }
    """
    all_user_creds = db.get_test_user_credentials(
        request.config.getoption('stage'))
    for user_type in all_user_creds.keys():
        user_creds = all_user_creds[user_type]
        BaseDriver.USERS_MAP[user_type] = BaseDriver.Credentials(**user_creds)
    if request.config.getoption('use_database'):
        for user_type in all_user_creds.keys():
            user_creds = all_user_creds[user_type]
            BaseDriver.USER_IDS[user_type] = db.setup_user(
                user_creds['username'], user_type, user_creds['passhash'])
Ejemplo n.º 3
0
	def close ( self ):
	#----------------------------------------------------------------------

		l_ret = BaseDriver.close(self)

		if self.m_popen:
			try:
				self.m_popen.wait()
			except:
				l_ret = False

		self.m_popen = None

		return l_ret
Ejemplo n.º 4
0
def extract_pokedex(c: Config):
    with BaseDriver(c.WEBDRIVER_PATH, c.HEADLESS_DRIVER) as base_driver:
        base_driver.load_page(
            page_url="https://pokemondb.net/pokedex/stats/gen1",
            wait_element=True,
            wait_element_id="pokedex",
            timeout=5)

        pokemon_table_extracted = base_driver.lazy_table_to_csv(
            css_selector_table="#pokedex",
            csv_name=os.path.join(c.OUTPUT_DIR, "pokedex.csv"))

        base_driver.timeout = 30

        # Skip table header
        # ['#', 'Name', 'Type', 'Total', 'HP', 'Attack', 'Defense', 'Sp. Atk', 'Sp. Def', 'Speed']
        progress_bar = tqdm(pokemon_table_extracted[1:],
                            desc="Pokemons",
                            colour='green',
                            leave=False,
                            unit_scale=True)
        for r in progress_bar:
            pokemon_name: str = r[1]

            progress_bar.set_description(
                f"Extracting moves from {pokemon_name}")

            # F**k nidorans, farfetch'd, mr. mine
            pokemon_name = pokemon_name.replace('♀', '-f')
            pokemon_name = pokemon_name.replace('♂', '-m')
            pokemon_name = pokemon_name.replace("'", '')
            pokemon_name = pokemon_name.replace(".", '-')
            pokemon_name = pokemon_name.replace(" ", '')

            # Navigate to moves list
            base_driver.load_page(
                page_url=
                f"https://pokemondb.net/pokedex/{pokemon_name}/moves/1",
                wait_element=True,
                wait_element_id="tabs-moves-1")

            base_driver.lazy_table_to_csv(
                css_selector_table=
                "#tabs-moves-1 > div:nth-child(1) > div:nth-child(1) > div:nth-child(3) > "
                "table:nth-child(1)",
                csv_name=os.path.join(c.OUTPUT_DIR, f"moves/moves_{r[1]}.csv"),
                use_progress_bar=False)
        progress_bar.close()
Ejemplo n.º 5
0
	def open ( self ):
	#----------------------------------------------------------------------

		if not self.m_command:
			return False

		try:
			self.m_popen = subprocess.Popen(self.m_command, bufsize=0,
											stdin=subprocess.PIPE,
											stdout=subprocess.PIPE,
											close_fds=True)
		except:
			self.m_popen = None
			return False

		return BaseDriver.open(self, self.m_popen.stdout, self.m_popen.stdin)
Ejemplo n.º 6
0
def extract_pokedex_robot(c: Config):
    with BaseDriver(c.WEBDRIVER_PATH, c.HEADLESS_DRIVER) as base_driver:
        base_driver.load_page(
            page_url="https://pokemondb.net/pokedex/stats/gen1",
            wait_element=True,
            wait_element_id="pokedex",
            timeout=5)

        table_extracted = base_driver.lazy_table_to_csv(
            css_selector_table="#pokedex",
            csv_name=os.path.join(c.OUTPUT_DIR, "pokedex.csv"))

        base_driver.timeout = 30

        # Skip table header
        # ['#', 'Name', 'Type', 'Total', 'HP', 'Attack', 'Defense', 'Sp. Atk', 'Sp. Def', 'Speed']
        progress_bar = tqdm(table_extracted[1:],
                            desc="Pokemons",
                            colour='green',
                            leave=False,
                            unit_scale=True)
        for r in progress_bar:
            progress_bar.set_description(f"Extracting moves from {r[1]}")

            # Navigate to first item on Name column
            base_driver.search_link_text_and_navigate(
                link_text=r[1],
                wait_element=True,
                wait_element_locator=(By.CLASS_NAME, "data-table"))

            # Navigate for the first generation moves
            link = base_driver.search_link_by_text_and_attribute(
                "1", ("title", "Generation 1: Red, Blue, Yellow"))
            base_driver.click_and_wait(element=link,
                                       wait_element_locator=(By.CLASS_NAME,
                                                             "data-table"))

            base_driver.lazy_table_to_csv(
                css_selector_table=
                "#tabs-moves-1 > div:nth-child(1) > div:nth-child(1) > div:nth-child(3) > "
                "table:nth-child(1)",
                csv_name=os.path.join(c.OUTPUT_DIR,
                                      f"moves_robot/moves_{r[1]}.csv"),
                use_progress_bar=False)
            time.sleep(2)
            base_driver.browser_history_back(2)
Ejemplo n.º 7
0
 def __init__(self,i):
     dr = BaseDriver()
     self.driver =dr.android_driver(i)
     self.loc=GetByLocal(self.driver)
Ejemplo n.º 8
0
def _driver_manager(request):
    """
    Provides an instance of BaseDriver as a fixture to allow use of other fixtures.
    Mimics the set for the built-in sb fixture from SeleniumBase so that certain SeleniumBase
    features work properly, like screenshots at end of tests & on failure.
    """
    if request.cls:
        request.cls.sb = BaseDriver('base_method')
        request.cls.sb.setUpClass()
        request.cls.sb.setUp()
        request.cls.sb._needs_tearDown = True
        sb_config._sb_node[request.node.nodeid] = request.cls.sb
        yield request.cls.sb
        if request.cls.sb._needs_tearDown:
            request.cls.sb.tearDown()
            request.cls.sb._needs_tearDown = False
    else:
        rdriver = BaseDriver('base_method')
        rdriver.setUpClass()
        rdriver.setUp()
        rdriver._needs_tearDown = True
        sb_config._sb_node[request.node.nodeid] = rdriver
        yield rdriver
        if rdriver._needs_tearDown:
            rdriver.tearDown()
            rdriver._needs_tearDown = False
Ejemplo n.º 9
0
 def __init__(self, driver):
     # base_driver = BaseDriver()
     self.driver = BaseDriver.android_driver(driver)
     self.get_by_local = ByLocal(
         self.driver)  #GetByLocal:获取定位信息,如:id,ClassName