class Test_CR(unittest.TestCase): @classmethod def setUpClass(cls): cls.driver = webdriver.Firefox() cls.driver.maximize_window() LogInPage(cls.driver).log_in_page("admin", "123456") time.sleep(2)
def Log_case(self, user="******", psw="123456", expect=True): LogInPage(self.driver).log_in_page(user, psw) result = self.a.is_text_exist(self.loc_current_user, user) print(result) expect_result = expect if expect == 'True': expect_result = True else: expect_result = False self.assertEqual(result, expect_result)
loc_add_trunck = ("xpath", ".//*[@id='openedBuild_chosen']/div/ul/li") loc_title = ("id", "title") loc_submit = ("id", "submit") loc_name = ("xpath", ".//*[@id='bugList']/tbody/tr[1]/td[4]/a") def add_bug(self, title="test BUG"): self.click(self.loc_text) self.click(self.loc_bug) # time.sleep(2) self.click(self.loc_add_bug) self.click(self.loc_click_trunck) self.click(self.loc_add_trunck) self.sendKeys(self.loc_title, title) js = 'document.getElementsByClassName("ke-edit-iframe")[0].contentWindow.document.body.innerHTML="Hello World"' self.driver.execute_script(js) self.click(self.loc_submit) def is_save_success(self, text): return self.is_text_exist(self.loc_name, text) if __name__ == "__main__": driver = webdriver.Firefox() LogInPage(driver).log_in_page("admin", "123456") a = AddBug(driver) timestr = time.strftime("%Y_%m_%d_%H_%M_%S") title = "test BUG" + timestr a.add_bug(title) result = a.is_save_success(title) print(result)
def setUpClass(cls): cls.driver = webdriver.Firefox() LogInPage(cls.driver).log_in_page("admin", "123456") cls.a = AddBug(cls.driver)
from selenium.webdriver.support.ui import WebDriverWait from selenium.common.exceptions import NoSuchElementException from common.logIn import LogInPage from selenium import webdriver POLL_FREQUENCY = 0.5 # How long to sleep inbetween calls to the method IGNORED_EXCEPTIONS = (NoSuchElementException, ) # exceptions ignored during calls to the method driver = webdriver.Firefox() class is_Correct(): def __init__(self, driver: webdriver.Firefox): self.driver = driver self.timeout = 10 self.t = 0.5 def is_text(self): ele = WebDriverWait(self.driver, self.timeout, self.t).until( EC.text_to_be_present_in_element( ("xpath", ".//*[@id='userMenu']/a"), "admin")) return ele if __name__ == "__main__": LogInPage(driver).log_in_page() a = is_Correct(driver) result = a.is_text() print(result)