def test_link(self): bro = Browser(browser_name=Browser.CHROME, headless=True) bro.goto("https://the-internet.herokuapp.com/").link( "xpath:=//*[@id='content']/ul/li[1]/a").click() #phew! t = bro.element("content").text self.assertTrue("Also known as split testing" in t) bro.close()
def test4(self): b = Browser() driver = b.driver driver.get("https://the-internet.herokuapp.com/") ba = WebDriverWait(driver, 5, 1, (ElementNotVisibleException)).until( EC.presence_of_element_located((By.XPATH, "//*[@id='content']/ul/li[2]/a")) ) ba.click() h = driver.window_handles for i in h: print(i) b.close()
def test_contents(self): bro = Browser(browser_name=Browser.CHROME, headless=True) bro.goto("https://httpbin.org/get") c = bro.content() self.assertTrue(isinstance(c, str) and r"</pre></body></html>" in c) rc = bro.content(raw=True) self.assertTrue(isinstance(rc, bytes)) #print(bro.html()) #html self.assertTrue(bro.json['url'] == "https://httpbin.org/get") #json self.assertTrue(r"Content-Type" in bro.response_headers) self.assertTrue(bro.response_code == 200) #print(bro.response_encoding) bro.close()
def test_screenshots(self): home_dir = os.getenv('HOME') or os.path.expanduser( os.getenv('USERPROFILE')) bro = Browser(browser_name=Browser.CHROME, headless=True) bro.goto("https://www.google.com/") v = bro.button("name:=btnK").name self.assertEqual(v, "btnK") bro.input("name:=q").enter("sachin") bro.button("name:=btnK").click() f = bro.take_screenshot() self.assertTrue(file_exists(f)) bro.input("name:=q").enter("virat kohli").submit() f = bro.take_screenshot(os.path.join(home_dir, "tmp")) self.assertTrue(file_exists(f)) bro.input("name:=q").enter("ab de villiers").submit() f = bro.take_screenshot(os.path.join(home_dir, "tmp")) self.assertTrue(file_exists(f)) bro.input("name:=q").enter("dhoni").submit() f = bro.take_screenshot("googly_dhoni") self.assertTrue(file_exists(f)) bro.input("name:=q").enter("ganguly").submit() f = bro.take_screenshot("googly_ganguly.png") self.assertTrue(file_exists(f)) bro.close()