Skip to content

Instantly share code, notes, and snippets.

@darrentorpey
Last active September 20, 2021 19:43
Show Gist options
  • Save darrentorpey/df18da16169bba4cf2af20103350f8a7 to your computer and use it in GitHub Desktop.
Save darrentorpey/df18da16169bba4cf2af20103350f8a7 to your computer and use it in GitHub Desktop.
selenium_debugging.py
# To see the current URL:
print('Current URL: {}'.format(self.browser.current_url))
main = self.driver.find_elements(By.CSS_SELECTOR, '.main-content')[0]
main_children = self.driver.find_elements(By.CSS_SELECTOR, '.main-content > *')
print('main', main.get_attribute('outerHTML'))
print('len', len(main_children))
print('main', main.get_attribute('outerHTML'))
# main.wait_until_exists(By.XPATH, '//*')
# find_elements_by_xpath("//*")
self.driver.wait_until_exists(By.CSS_SELECTOR, '.main-content > *')
main_children = self.driver.find_elements(By.CSS_SELECTOR, '.main-content > *')
print('len', len(main_children))
@pytest.mark.order6
def test_new_member_can_login(self, shared_data):
shared_data['member_email'] = 'dtorpey@ruelala.com'
shared_data['member_password'] = 'lordkane'
"""Logged in as the newly registered member"""
edr = EdrModal(self.browser)
edr.show_login.click()
edr.login_with(shared_data['member_email'], shared_data['member_password'])
@pytest.mark.order6
def test_new_member_can_login(self, shared_data):
print('At: {}'.format(self.browser.current_url))
self.wait_until_exists(By.CLASS_NAME, 'remodal-wrapper', hard_fail=True, timeout=2, failure_message="Couldn't find modal")
def get_door_page(self, types_of_pages):
door_page = None
for page_identifier in types_of_pages.keys():
found_element = self.driver.find_element(By.ID, page_identifier)
if found_element is not None:
print('FOUND!', page_identifier, self.driver.find_element(By.ID, page_identifier))
print(found_element.text)
print(found_element.get_attribute('innerHTML'))
print('outerHTML', found_element.get_attribute('outerHTML'))
print('children', found_element.get_attribute('children'))
# print(found_element.find_elements_by_css_selector('*'))
# print(self.driver.browser.page_source)
door_page = types_of_pages[page_identifier](self.driver)
break
# self.driver.wait_until_exists(*BoutiqueMainPageLocators.BOUTIQUE_DOOR_LIST)
if door_page is None:
main = self.driver.find_elements(By.CLASS_NAME, 'main-content')[0]
print('main', main.get_attribute('outerHTML'))
return door_page
def navigate_to_plp(self):
boutique_main_doors_index = 0
found_valid_plp = False
while not found_valid_plp:
print('[boutique_main_doors_index]', boutique_main_doors_index)
if boutique_main_doors_index > 0:
self.driver.fail('< First door was no good >')
self.driver.wait_until_exists(*BoutiqueMainPageLocators.BOUTIQUE_DOOR_LIST)
# Each time the test switches pages, the doors that used to be stored gets stale,
# so the test needs to collect a 'fresh' set of doors for each index
# boutique_main_doors = []
# boutique_main_doors = self.get_boutique_page(DOOR_COUNT_LIMIT)
# boutique_main_doors = self.driver.find_elements(By.CLASS_NAME, 'boutique-big')
# big_door_list = self.driver.find_elements(By.ID, 'big-door-list')
# print(big_door_list)
# main = self.driver.find_elements(By.CLASS_NAME, 'main-content')[0]
# print('main', main.get_attribute('outerHTML'))
# import time
# time.sleep(0.5)
boutique_main_doors = self.get_boutique_page(DOOR_COUNT_LIMIT)
print('Found %s doors' % (len(boutique_main_doors)))
if len(boutique_main_doors) == 0:
# body = self.driver.find_elements(By.TAG_NAME, 'body')[0]
# print('BAD NEWS')
# main = self.driver.find_elements(By.CLASS_NAME, 'main-content')[0]
# print('outerHTML', main.get_attribute('outerHTML'))
# boutique_main_doors = self.get_boutique_page(DOOR_COUNT_LIMIT)
# print('Now found %s doors' % (len(boutique_main_doors)))
self.driver.fail('No doors found on Boutique Main')
try:
door = boutique_main_doors[boutique_main_doors_index]
except IndexError:
"""
An IndexError will occur when the test cycles through all the child doors on
BoutiqueMain and none of the Boutqiue doors have a valid path
"""
self.driver.fail('No child doors on Boutique Main can path to a valid PLP')
self.enter_door(self.driver, door)
# print('VISITING | %s' % (self.driver.browser.current_url))
discovery_page = self.get_door_page(TYPES_OF_PAGES)
if discovery_page is not None:
print('Entered a {name}'.format(name=discovery_page.page_name))
found_valid_plp = discovery_page.navigate_to_plp()
else:
print('<< Page not recognized >>')
if not found_valid_plp:
self.driver.browser.back()
boutique_main_doors_index += 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment