def chrome_browser(): from automagica.activities import Chrome chrome = Chrome() yield chrome chrome.quit()
def test_highlight(): """ Test Highlight element """ # Open the browser browser = Chrome() # Go to a website browser.get("https://wikipedia.org") # Find first link on page first_link = browser.find_elements_by_xpath("//a[@href]")[0] # Highlight first link browser.highlight(first_link) browser.quit() assert True
def test_by_id(): """ Test Find id in browser """ # Open the browser browser = Chrome() # Go to a website browser.get("https://wikipedia.org") # Find element by class elements = browser.by_id("search-input") browser.quit() assert "elements" in locals()
def test_by_class_and_by_text(): """ Test Find element in browser based on class and text """ # Open the browser browser = Chrome() # Go to a website browser.get("https://wikipedia.org") # Find elements by class and text element = browser.by_class_and_by_text("search-input", "Search Wikipedia") browser.quit() assert "element" in locals()
def test_by_xpath(): """ Test Find XPath in browser """ # Open the browser browser = Chrome() # Go to a website browser.get("https://wikipedia.org") # Find element by xpath element = browser.by_xpath("//*[@id='js-link-box-en']") browser.quit() assert "element" in locals()
def test_save_all_images(): """ Test Save all images """ # Open the browser browser = Chrome() # Go to a website browser.get("https://nytimes.com") # Save all images images = browser.save_all_images() browser.quit() assert type(images) is list
def test_get_text_on_webpage(): """ Test Get all text on webpage """ # Open the browser browser = Chrome() # Go to a website browser.get("https://nytimes.com") # Get text from page text_on_page = browser.get_text_on_webpage() # Quit the browser browser.quit() assert type(text_on_page) is str
def test_find_first_link(): """ Test Find first link on a webpage """ # Open the browser browser = Chrome() # Go to a website browser.get("https://nytimes.com") # Find elements by text first_link = browser.find_first_link() # Quit the browser browser.quit() assert type(first_link) is str
def test_find_all_links(): """ Test Find all links """ # Open the browser browser = Chrome() # Go to a website browser.get("https://nytimes.com") # Find elements by text links = browser.find_all_links() # Quit the browser browser.quit() assert type(links) is list
def test_find_elements_by_text(): """ Test Find elements by text """ # Open the browser browser = Chrome() # Go to a website browser.get("https://nytimes.com") # Find elements by text elements = browser.find_elements_by_text("a") # Quit the browser browser.quit() assert type(elements) is list
def test_chrome_activities(): """ Test scenario for testing Chrome browser activities (requires Google Chrome) """ # Open Chrome chrome = Chrome(auto_update_chromedriver=True) # Browse to Google chrome.browse_to("https://google.com") # Save the page source source = chrome.page_source # Quit the browser chrome.quit() assert "Google" in source
def test_switch_to_iframe(): """ Test Switch to iframe in browser """ # Open the browser browser = Chrome() # Go to a website browser.get("https://www.w3schools.com/html/html_iframe.asp") url_before_switch = browser.current_url # Switch to iframe iframe = browser.switch_to_iframe() url_after_switch = browser.current_url browser.quit() assert url_before_switch == url_after_switch