SHARE
TWEET

Untitled

a guest May 26th, 2019 61 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # -*- coding: utf-8 -*-
  2. from selenium import webdriver
  3. from selenium.webdriver.common.by import By
  4. from selenium.webdriver.common.keys import Keys
  5. from selenium.webdriver.support.ui import Select
  6. from selenium.common.exceptions import NoSuchElementException
  7. from selenium.common.exceptions import NoAlertPresentException
  8. import unittest, time, re
  9.  
  10. class UntitledTestCase(unittest.TestCase):
  11.     def setUp(self):
  12.         self.driver = webdriver.Firefox()
  13.         self.driver.implicitly_wait(30)
  14.         self.base_url = "https://www.katalon.com/"
  15.         self.verificationErrors = []
  16.         self.accept_next_alert = True
  17.    
  18.     def test_untitled_test_case(self):
  19.         driver = self.driver
  20.         driver.get("https://www.binaryhexconverter.com/decimal-to-binary-converter")
  21.         driver.find_element_by_id("tabin").click()
  22.         driver.find_element_by_id("tabin").clear()
  23.         driver.find_element_by_id("tabin").send_keys("10")
  24.         driver.find_element_by_xpath("(.//*[normalize-space(text()) and normalize-space(.)='Binary Value'])[1]/following::input[1]").click()
  25.         for i in range(60):
  26.             try:
  27.                 if "00001010" == driver.find_element_by_id("resulttxt").get_attribute("value"): break
  28.             except: pass
  29.             time.sleep(1)
  30.         else: self.fail("time out")
  31.         try: self.assertEqual("(10)10 = (00001010)2", driver.find_element_by_id("baseresult").text)
  32.         except AssertionError as e: self.verificationErrors.append(str(e))
  33.    
  34.     def is_element_present(self, how, what):
  35.         try: self.driver.find_element(by=how, value=what)
  36.         except NoSuchElementException as e: return False
  37.         return True
  38.    
  39.     def is_alert_present(self):
  40.         try: self.driver.switch_to_alert()
  41.         except NoAlertPresentException as e: return False
  42.         return True
  43.    
  44.     def close_alert_and_get_its_text(self):
  45.         try:
  46.             alert = self.driver.switch_to_alert()
  47.             alert_text = alert.text
  48.             if self.accept_next_alert:
  49.                 alert.accept()
  50.             else:
  51.                 alert.dismiss()
  52.             return alert_text
  53.         finally: self.accept_next_alert = True
  54.    
  55.     def tearDown(self):
  56.         self.driver.quit()
  57.         self.assertEqual([], self.verificationErrors)
  58.  
  59. if __name__ == "__main__":
  60.     unittest.main()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top