def setUp(self): self.selenium = MySelenium('Chrome') self.driver = self.selenium.driver self.base_url = Config().get('URL') # Variables self.user_first_name = random_first_name() self.user_last_name = random_last_name() self.user_email = random_email()
def setUp(self): self.selenium = MySelenium('Chrome') self.driver = self.selenium.driver self.base_url = Config().get('URL') self.first_name = random_first_name() self.last_name = random_last_name() self.email = random_email() self.new_first_name = random_first_name() self.new_last_name = random_last_name()
def setUp(self): self.selenium = MySelenium('Chrome') self.driver = self.selenium.driver self.base_url = Config().get('URL') # Variables self.user_first_name = random_first_name() self.user_last_name = random_last_name() self.user_email = random_email() self.project_name = random_project_name() # Scripts admin_create_new_user_logout(self) login_as_user(self) time.sleep(1)
def setUp(self): self.selenium = MySelenium('Chrome') self.base_url = Config().get('URL') self.first_name = random_first_name() self.last_name = random_last_name() self.email = random_email() self.driver = self.selenium.driver self.driver.get(self.base_url + "/login") self.driver.find_element( "xpath", "//div[@id='login-tabpane-admin']/form/div/input").send_keys( "admin") self.driver.find_element( "xpath", "//div[@id='login-tabpane-admin']/form/button").click() time.sleep(1)
class TestStartPomodoro(unittest.TestCase): def setUp(self): self.selenium = MySelenium('Chrome') self.driver = self.selenium.driver self.base_url = Config().get('URL') # Variables self.user_first_name = random_first_name() self.user_last_name = random_last_name() self.user_email = random_email() self.project_name = random_project_name() admin_create_new_user_logout(self) login_as_user(self) user_add_project(self) time.sleep(1) def tearDown(self): clean_up(self) self.driver.close() def test_start_pomodoro_not_associate(self): driver = self.driver # Click on "Pomodoro" tab driver.find_element_by_id("sidebar_user_Pomodoro").click() # Click on "Create a new pomodoro" button driver.find_element_by_id("create_pomodoro_button").click() # Type in 3 second pomodoro driver.find_element_by_id("create_second").send_keys(1) # Don't associate Select(driver.find_element_by_id( "project_select_box")).select_by_visible_text("No association") # Confirm create pomodoro driver.find_element_by_id("create_confirm_button").click() # Wait for continue modal, check for # of pomodoro = 1 self.selenium.element_wait("id", "decide_stop") time.sleep(1) pomodoro_count = driver.find_element_by_xpath( "//div[div/strong[contains(text(), '# of pomodoro completed:')]]/div[2]" ) self.assertEqual(pomodoro_count.text, '1') def test_start_pomodoro_associate(self): driver = self.driver # Check Sessions = 0, Total Pomodoros = 0 project_entry = driver.find_element_by_xpath( "//tr[td[contains(text(), '{}')]]".format(self.project_name)) self.assertEqual( project_entry.find_element_by_xpath("td[3]").text, '0') self.assertEqual( project_entry.find_element_by_xpath("td[4]").text, '0') # Click on "Pomodoro" tab driver.find_element_by_id("sidebar_user_Pomodoro").click() # Click on "Create a new pomodoro" button driver.find_element_by_id("create_pomodoro_button").click() # Type in 3 second pomodoro driver.find_element_by_id("create_second").send_keys(1) # Associate with current random project name Select(driver.find_element_by_id( "project_select_box")).select_by_visible_text(self.project_name) # Confirm create pomodoro driver.find_element_by_id("create_confirm_button").click() # Wait for continue modal, check for # of pomodoro = 1 self.selenium.element_wait("id", "decide_stop") pomodoro_count = driver.find_element_by_xpath( "//div[div/strong[contains(text(), '# of pomodoro completed:')]]/div[2]" ) self.assertEqual(pomodoro_count.text, '1') # Click No driver.find_element_by_id("decide_stop").click() time.sleep(1) # Go back to project tab driver.find_element_by_id("sidebar_user_Projects").click() time.sleep(1) # Check Sessions and Total Pomodoros incremented project_entry = driver.find_element_by_xpath( "//tr[td[contains(text(), '{}')]]".format(self.project_name)) self.assertEqual( project_entry.find_element_by_xpath("td[3]").text, '1') self.assertEqual( project_entry.find_element_by_xpath("td[4]").text, '1') def test_start_pomodoro_associate_break_stop(self): driver = self.driver # Click on "Pomodoro" tab driver.find_element_by_id("sidebar_user_Pomodoro").click() # Click on "Create a new pomodoro" button driver.find_element_by_id("create_pomodoro_button").click() # Type in 1 second pomodoro and 1 second break driver.find_element_by_id("create_second").send_keys(1) # Associate with current random project name Select(driver.find_element_by_id( "project_select_box")).select_by_visible_text(self.project_name) # Confirm create pomodoro driver.find_element_by_id("create_confirm_button").click() # Wait for continue modal self.selenium.element_wait("id", "decide_break") # Click Take a break driver.find_element_by_id("decide_break").click() time.sleep(1) driver.find_element_by_id("continue_second").send_keys(1) driver.find_element_by_id("continue_confirm_button").click() # Wait for continue modal again, check for # of pomodoro = 1 time.sleep(1) self.selenium.element_wait("id", "decide_stop") pomodoro_count = driver.find_element_by_xpath( "//div[div/strong[contains(text(), '# of pomodoro completed')]]/div[2]" ) self.assertEqual(pomodoro_count.text, '1') # Go back to project tab driver.find_element_by_id("decide_stop").click() time.sleep(1) driver.find_element_by_id("sidebar_user_Projects").click() time.sleep(1) # Check Sessions and Total Pomodoros incremented project_entry = driver.find_element_by_xpath( "//tr[td[contains(text(), '{}')]]".format(self.project_name)) self.assertEqual( project_entry.find_element_by_xpath("td[3]").text, '1') self.assertEqual( project_entry.find_element_by_xpath("td[4]").text, '1') def test_start_pomodoro_associate_break_continue(self): driver = self.driver # Click on "Pomodoro" tab driver.find_element_by_id("sidebar_user_Pomodoro").click() # Click on "Create a new pomodoro" button driver.find_element_by_id("create_pomodoro_button").click() # Type in 1 second pomodoro and 1 second break driver.find_element_by_id("create_second").send_keys(1) # Associate with current random project name Select(driver.find_element_by_id( "project_select_box")).select_by_visible_text(self.project_name) # Confirm create pomodoro driver.find_element_by_id("create_confirm_button").click() # Wait for continue modal self.selenium.element_wait("id", "decide_break") # Click Take a break driver.find_element_by_id("decide_break").click() time.sleep(1) driver.find_element_by_id("continue_second").send_keys(1) driver.find_element_by_id("continue_confirm_button").click() # Wait for continue modal again time.sleep(1) self.selenium.element_wait("id", "decide_work") # Do another pomodoro ********* driver.find_element_by_id("decide_work").click() # Type in 1 second pomodoro and 1 second break driver.find_element_by_id("continue_second").send_keys(1) driver.find_element_by_id("continue_confirm_button").click() self.selenium.element_wait("id", "decide_work") # Go back to project tab driver.find_element_by_id("decide_stop").click() time.sleep(1) driver.find_element_by_id("sidebar_user_Projects").click() time.sleep(1) # Check Sessions and Total Pomodoros incremented project_entry = driver.find_element_by_xpath( "//tr[td[contains(text(), '{}')]]".format(self.project_name)) self.assertEqual( project_entry.find_element_by_xpath("td[3]").text, '1') self.assertEqual( project_entry.find_element_by_xpath("td[4]").text, '2') def test_start_pomodoro_no_associate_break(self): driver = self.driver # Click on "Pomodoro" tab driver.find_element_by_id("sidebar_user_Pomodoro").click() # Click on "Create a new pomodoro" button driver.find_element_by_id("create_pomodoro_button").click() # Type in 1 second pomodoro and 1 second break driver.find_element_by_id("create_second").send_keys(1) # Confirm create pomodoro driver.find_element_by_id("create_confirm_button").click() # Wait for continue modal self.selenium.element_wait("id", "decide_break") # Click Take a break driver.find_element_by_id("decide_break").click() time.sleep(1) driver.find_element_by_id("continue_second").send_keys(1) driver.find_element_by_id("continue_confirm_button").click() # Wait for continue modal again time.sleep(1) self.selenium.element_wait("id", "decide_work") # Do another pomodoro driver.find_element_by_id("decide_work").click() # Type in 1 second pomodoro and 1 second break driver.find_element_by_id("continue_second").send_keys(1) driver.find_element_by_id("continue_confirm_button").click() self.selenium.element_wait("id", "decide_work") # Go back to project tab driver.find_element_by_id("decide_stop").click() time.sleep(1) driver.find_element_by_id("sidebar_user_Projects").click() time.sleep(1) # Check Sessions and Total Pomodoros incremented project_entry = driver.find_element_by_xpath( "//tr[td[contains(text(), '{}')]]".format(self.project_name)) self.assertEqual( project_entry.find_element_by_xpath("td[3]").text, '0') self.assertEqual( project_entry.find_element_by_xpath("td[4]").text, '0')
class TestUserAddProject(unittest.TestCase): def setUp(self): self.selenium = MySelenium('Chrome') self.driver = self.selenium.driver self.base_url = Config().get('URL') # Variables self.user_first_name = random_first_name() self.user_last_name = random_last_name() self.user_email = random_email() self.project_name = random_project_name() # Scripts admin_create_new_user_logout(self) login_as_user(self) time.sleep(1) def tearDown(self): clean_up(self) self.driver.close() def test_user_add_new_project_with_non_exist_name(self): """ Test add a new project """ driver = self.driver # Click create new user button to show modal create_project_button = driver.find_element_by_id( "create_project_button") create_project_button.click() time.sleep(1) # Check CreateModal is pop up create_modal = self.selenium.is_element_exist("id", "create_project_modal") # Type in project name create_project_name = driver.find_element_by_id("create_project_name") create_project_name.send_keys(self.project_name) # click "create" button confirm_create_project_button = driver.find_element_by_id( "confirm_create_project_button") confirm_create_project_button.click() time.sleep(1) # look for the user just generated new_project_name = self.selenium.is_element_exist( "xpath", "//tr[td[contains(text(), '{}')]]".format(self.project_name)) self.assertTrue(new_project_name) def test_user_add_project_with_exist_name(self): driver = self.driver # Add first project user_add_project(self) time.sleep(1) # Test add another project with same name user_add_project(self) # check error_msg is_error_modal = self.selenium.is_element_exist("id", "error_modal") self.assertTrue(is_error_modal) if is_error_modal: error_modal = driver.find_element_by_id("error_modal") error_msg = driver.find_element_by_xpath( "//div[@id='error_modal']/div/div[2]").text self.assertEqual(error_msg, "Request failed with status code 409")
class TestUserEditProject(unittest.TestCase): def setUp(self): self.selenium = MySelenium('Chrome') self.driver = self.selenium.driver self.base_url = Config().get('URL') # Variables self.first_name = random_first_name() self.last_name = random_last_name() self.email = random_email() self.project_name = random_project_name() self.new_project_name = random_project_name() def tearDown(self): clean_up(self) self.driver.close() def test_user_edit_project_with_non_exist_name(self): driver = self.driver # create a new user self.driver.get(self.base_url + "/login") self.driver.find_element( "xpath", "//div[@id='login-tabpane-admin']/form/div/input").send_keys( "admin") self.driver.find_element( "xpath", "//div[@id='login-tabpane-admin']/form/button").click() time.sleep(1) create_new_user_button = driver.find_element_by_id( "create_new_user_button") create_new_user_button.click() create_first_name = driver.find_element_by_id("create_first_name") create_last_name = driver.find_element_by_id("create_last_name") create_emal = driver.find_element_by_id("create_email") create_first_name.send_keys(self.first_name) create_last_name.send_keys(self.last_name) create_emal.send_keys(self.email) confirm_create_new_user_button = driver.find_element_by_id( "confirm_create_new_user_button") confirm_create_new_user_button.click() logger.info("create a user for deleting") time.sleep(1) driver.find_element_by_id("logout").click() time.sleep(1) # create a project with this user driver.find_element_by_link_text("User").click() time.sleep(1) driver.find_element( "xpath", "//div[@id='login-tabpane-user']/form/div/input").send_keys( self.email) driver.find_element( "xpath", "//div[@id='login-tabpane-user']/form/button").click() time.sleep(1) driver.find_element_by_id("create_project_button").click() driver.find_element_by_id("create_project_name").send_keys( self.project_name) driver.find_element_by_id("confirm_create_project_button").click() logger.info("create a project for the user") time.sleep(1) # edit the created project edit_button = driver.find_element( "xpath", "//tr[td[contains(text(), '{}')]]//i[contains(@class, 'pe-7s-note')]" .format(self.project_name)) edit_button.click() logger.info("click edit button") time.sleep(1) # Check edit modal pops up is_eidt_modal = self.selenium.is_element_exist("id", "edit_modal") self.assertTrue(is_eidt_modal) logger.info("edit modal pops up") # edit with new project name edit_project_name = driver.find_element_by_id("edit_project_name") edit_project_name.clear() edit_project_name.send_keys(self.new_project_name) logger.info("change project name: " + self.project_name + ' to ' + self.new_project_name) # click confirm button confirm_edit_button = driver.find_element_by_id("confirm_edit") confirm_edit_button.click() time.sleep(1) logger.info("click confirm button") # check the user just modified is_old_project_name = self.selenium.is_element_exist( "xpath", "//tr[td[contains(text(), '{}')]]/td[2]".format(self.project_name)) self.assertFalse(is_old_project_name) is_new_project_name = "xpath", "//tr[td[contains(text(), '{}')]]/td[2]".format( self.new_project_name) self.assertTrue(is_new_project_name) logger.info("edit project name to: " + self.new_project_name) def test_user_edit_project_with_exist_name(self): driver = self.driver # create a new user self.driver.get(self.base_url + "/login") self.driver.find_element( "xpath", "//div[@id='login-tabpane-admin']/form/div/input").send_keys( "admin") self.driver.find_element( "xpath", "//div[@id='login-tabpane-admin']/form/button").click() time.sleep(1) create_new_user_button = driver.find_element_by_id( "create_new_user_button") create_new_user_button.click() create_first_name = driver.find_element_by_id("create_first_name") create_last_name = driver.find_element_by_id("create_last_name") create_emal = driver.find_element_by_id("create_email") create_first_name.send_keys(self.first_name) create_last_name.send_keys(self.last_name) create_emal.send_keys(self.email) confirm_create_new_user_button = driver.find_element_by_id( "confirm_create_new_user_button") confirm_create_new_user_button.click() logger.info("create a user for deleting") time.sleep(1) driver.find_element_by_id("logout").click() time.sleep(1) # create two projects with this user driver.find_element_by_link_text("User").click() time.sleep(1) driver.find_element( "xpath", "//div[@id='login-tabpane-user']/form/div/input").send_keys( self.email) driver.find_element( "xpath", "//div[@id='login-tabpane-user']/form/button").click() time.sleep(1) driver.find_element_by_id("create_project_button").click() driver.find_element_by_id("create_project_name").send_keys( self.project_name) driver.find_element_by_id("confirm_create_project_button").click() logger.info("create a project for the user") time.sleep(1) driver.find_element_by_id("create_project_button").click() driver.find_element_by_id("create_project_name").send_keys( self.new_project_name) driver.find_element_by_id("confirm_create_project_button").click() logger.info("create another project for the user") time.sleep(1) # edit the first project with the second project name edit_button = driver.find_element( "xpath", "//tr[td[contains(text(), '{}')]]//i[contains(@class, 'pe-7s-note')]" .format(self.project_name)) edit_button.click() logger.info("click edit button") time.sleep(1) # Check edit modal pops up is_eidt_modal = self.selenium.is_element_exist("id", "edit_modal") self.assertTrue(is_eidt_modal) logger.info("edit modal pops up") # edit with the exisit project name edit_project_name = driver.find_element_by_id("edit_project_name") edit_project_name.clear() edit_project_name.send_keys(self.new_project_name) logger.info("change project name: " + self.project_name + ' to ' + self.new_project_name) time.sleep(1) # click confirm button confirm_edit_button = driver.find_element_by_id("confirm_edit") confirm_edit_button.click() logger.info("click confirm button") time.sleep(1) # check error_msg is_error_modal = self.selenium.is_element_exist("id", "error_modal") self.assertTrue(is_error_modal) if is_error_modal: error_modal = driver.find_element_by_id("error_modal") error_msg = driver.find_element_by_xpath( "//div[@id='error_modal']/div/div[2]").text self.assertEqual(error_msg, "Request failed with status code 409")
class TestStopPomodoro(unittest.TestCase): def setUp(self): self.selenium = MySelenium('Chrome') self.driver = self.selenium.driver self.base_url = Config().get('URL') # Variables self.user_first_name = random_first_name() self.user_last_name = random_last_name() self.user_email = random_email() self.project_name = random_project_name() admin_create_new_user_logout(self) login_as_user(self) user_add_project(self) time.sleep(1) def tearDown(self): clean_up(self) self.driver.close() def test_stop_pomodoro_associate_no_log(self): driver = self.driver start_associated_pomodoro(self) time.sleep(1) # Click "Stop current ongoing Pomodoro" driver.find_element_by_id("stop_pomodoro_button").click() # Make sure stop modal pops up self.assertTrue(self.selenium.is_element_exist("id", "stop_cancel_button")) # Click no, go to project, check session incremented but total pomodoro not incremented driver.find_element_by_id("stop_cancel_button").click() time.sleep(1) driver.find_element_by_id("sidebar_user_Projects").click() time.sleep(1) project_entry = driver.find_element_by_xpath("//tr[td[contains(text(), '{}')]]".format(self.project_name)) self.assertEqual(project_entry.find_element_by_xpath("td[3]").text, '1') self.assertEqual(project_entry.find_element_by_xpath("td[4]").text, '0') def test_stop_pomodoro_associate_do_log(self): driver = self.driver start_associated_pomodoro(self) time.sleep(1) # Click "Stop current ongoing Pomodoro" driver.find_element_by_id("stop_pomodoro_button").click() # Make sure stop modal pops up self.assertTrue(self.selenium.is_element_exist("id", "stop_confirm_button")) # Click no, go to project, check session incremented but total pomodoro not incremented driver.find_element_by_id("stop_confirm_button").click() time.sleep(1) # Click yes, go to project, check both session and total pomodoros imcremented driver.find_element_by_id("sidebar_user_Projects").click() time.sleep(1) project_entry = driver.find_element_by_xpath("//tr[td[contains(text(), '{}')]]".format(self.project_name)) self.assertEqual(project_entry.find_element_by_xpath("td[3]").text, '1') self.assertEqual(project_entry.find_element_by_xpath("td[4]").text, '1') def test_stop_pomodoro_not_associated(self): driver = self.driver start_not_associated_pomodoro(self) time.sleep(1) # Click "Stop current ongoing Pomodoro" driver.find_element_by_id("stop_pomodoro_button").click() # Make sure stop modal pops up self.assertTrue(self.selenium.is_element_exist("id", "stop_confirm_button")) driver.find_element_by_id("stop_confirm_button").click() time.sleep(1) # Click yes, go to project, check both session and total pomodoros not imcremented driver.find_element_by_id("sidebar_user_Projects").click() time.sleep(1) project_entry = driver.find_element_by_xpath("//tr[td[contains(text(), '{}')]]".format(self.project_name)) self.assertEqual(project_entry.find_element_by_xpath("td[3]").text, '0') self.assertEqual(project_entry.find_element_by_xpath("td[4]").text, '0')
class TestAdminDeleteUser(unittest.TestCase): def setUp(self): self.selenium = MySelenium('Chrome') self.driver = self.selenium.driver self.base_url = Config().get('URL') self.first_name = random_first_name() self.last_name = random_last_name() self.email = random_email() self.project_name = random_project_name() self.driver.get(self.base_url + "/login") self.driver.find_element( "xpath", "//div[@id='login-tabpane-admin']/form/div/input").send_keys( "admin") self.driver.find_element( "xpath", "//div[@id='login-tabpane-admin']/form/button").click() time.sleep(1) def tearDown(self): clean_up(self) self.driver.close() def test_admin_delete_user_without_projects(self): driver = self.driver # create a new user create_new_user_button = driver.find_element_by_id( "create_new_user_button") create_new_user_button.click() create_first_name = driver.find_element_by_id("create_first_name") create_last_name = driver.find_element_by_id("create_last_name") create_emal = driver.find_element_by_id("create_email") create_first_name.send_keys(self.first_name) create_last_name.send_keys(self.last_name) create_emal.send_keys(self.email) confirm_create_new_user_button = driver.find_element_by_id( "confirm_create_new_user_button") confirm_create_new_user_button.click() time.sleep(1) logger.info("create a user for deleting") search_user(self) # delete the created user delete_button = driver.find_element( "xpath", "//tr[td[contains(text(), '{}')]]//i[contains(@class, 'pe-7s-trash')]" .format(self.email)) delete_button.click() logger.info("click the delete button") time.sleep(1) # Check delete modal doesn't pop up is_delete_modal = self.selenium.is_element_exist("id", "delete_modal") self.assertFalse(is_delete_modal) logger.info("delete modal doesn't pop up") # Check delete success is_email = self.selenium.is_element_exist( "xpath", "//tr[td[contains(text(), '{}')]]".format(self.email)) self.assertFalse(is_email) logger.info("delete the user successfully") def test_admin_delete_user_with_projects_confirm(self): driver = self.driver # create a new user create_new_user_button = driver.find_element_by_id( "create_new_user_button") create_new_user_button.click() create_first_name = driver.find_element_by_id("create_first_name") create_last_name = driver.find_element_by_id("create_last_name") create_emal = driver.find_element_by_id("create_email") create_first_name.send_keys(self.first_name) create_last_name.send_keys(self.last_name) create_emal.send_keys(self.email) confirm_create_new_user_button = driver.find_element_by_id( "confirm_create_new_user_button") confirm_create_new_user_button.click() logger.info("create a user for deleting") time.sleep(1) driver.find_element_by_id("logout").click() time.sleep(1) # create a project with this user driver.find_element_by_link_text("User").click() time.sleep(1) driver.find_element( "xpath", "//div[@id='login-tabpane-user']/form/div/input").send_keys( self.email) driver.find_element( "xpath", "//div[@id='login-tabpane-user']/form/button").click() time.sleep(1) driver.find_element_by_id("create_project_button").click() project_name = random_project_name() driver.find_element_by_id("create_project_name").send_keys( self.project_name) driver.find_element_by_id("confirm_create_project_button").click() logger.info("create a project for the user") time.sleep(1) driver.find_element_by_id("logout").click() time.sleep(1) # delete the created user driver.find_element( "xpath", "//div[@id='login-tabpane-admin']/form/div/input").send_keys( "admin") driver.find_element( "xpath", "//div[@id='login-tabpane-admin']/form/button").click() time.sleep(1) search_user(self) delete_button = driver.find_element( "xpath", "//tr[td[contains(text(), '{}')]]//i[contains(@class, 'pe-7s-trash')]" .format(self.email)) delete_button.click() logger.info("click the delete button") time.sleep(1) # Check delete modal pops up is_delete_modal = self.selenium.is_element_exist("id", "delete_modal") self.assertTrue(is_delete_modal) logger.info("delete modal pops up") # click confirm confirm_delete_button = driver.find_element_by_id("confirm_delete") confirm_delete_button.click() logger.info("click the confirm button") time.sleep(1) # Check delete success is_email = self.selenium.is_element_exist( "xpath", "//tr[td[contains(text(), '{}')]]".format(self.email)) self.assertFalse(is_email) logger.info("delete the user successfully") def test_admin_delete_user_with_projects_not_confirm(self): driver = self.driver # create a new user create_new_user_button = driver.find_element_by_id( "create_new_user_button") create_new_user_button.click() create_first_name = driver.find_element_by_id("create_first_name") create_last_name = driver.find_element_by_id("create_last_name") create_emal = driver.find_element_by_id("create_email") create_first_name.send_keys(self.first_name) create_last_name.send_keys(self.last_name) create_emal.send_keys(self.email) confirm_create_new_user_button = driver.find_element_by_id( "confirm_create_new_user_button") confirm_create_new_user_button.click() logger.info("create a user for deleting") time.sleep(1) driver.find_element_by_id("logout").click() time.sleep(1) # create a project with this user driver.find_element_by_link_text("User").click() time.sleep(1) driver.find_element( "xpath", "//div[@id='login-tabpane-user']/form/div/input").send_keys( self.email) driver.find_element( "xpath", "//div[@id='login-tabpane-user']/form/button").click() time.sleep(1) driver.find_element_by_id("create_project_button").click() project_name = random_project_name() driver.find_element_by_id("create_project_name").send_keys( self.project_name) driver.find_element_by_id("confirm_create_project_button").click() logger.info("create a project for the user") time.sleep(1) driver.find_element_by_id("logout").click() time.sleep(1) # delete the created user driver.find_element( "xpath", "//div[@id='login-tabpane-admin']/form/div/input").send_keys( "admin") driver.find_element( "xpath", "//div[@id='login-tabpane-admin']/form/button").click() time.sleep(1) search_user(self) delete_button = driver.find_element( "xpath", "//tr[td[contains(text(), '{}')]]//i[contains(@class, 'pe-7s-trash')]" .format(self.email)) delete_button.click() logger.info("click the delete button") time.sleep(1) # Check delete modal pops up is_delete_modal = self.selenium.is_element_exist("id", "delete_modal") self.assertTrue(is_delete_modal) logger.info("delete modal pops up") # click cancel cancel_delete_button = driver.find_element( "xpath", "//*[@id='delete_modal']/div/div[3]/button[1]") cancel_delete_button.click() logger.info("click the cancel button") time.sleep(1) # Check delete is cancelled is_email = self.selenium.is_element_exist( "xpath", "//tr[td[contains(text(), '{}')]]".format(self.email)) self.assertTrue(is_email) logger.info("cancel deleting the user")
class TestUserDeleteProject(unittest.TestCase): def setUp(self): self.selenium = MySelenium('Chrome') self.driver = self.selenium.driver self.base_url = Config().get('URL') # Variables self.user_first_name = random_first_name() self.user_last_name = random_last_name() self.user_email = random_email() self.project_name = random_project_name() admin_create_new_user_logout(self) login_as_user(self) user_add_project(self) time.sleep(1) def tearDown(self): clean_up(self) self.driver.close() def test_user_delete_project_without_sessions(self): driver = self.driver # delete the created project delete_button = driver.find_element( "xpath", "//tr[td[contains(text(), '{}')]]//i[contains(@class, 'pe-7s-trash')]" .format(self.project_name)) delete_button.click() logger.info("click the delete button") time.sleep(1) # Check delete modal doesn't pop up is_delete_modal = self.selenium.is_element_exist("id", "delete_modal") self.assertFalse(is_delete_modal) logger.info("delete modal doesn't pop up") # Check delete success is_project = self.selenium.is_element_exist( "xpath", "//tr[td[contains(text(), '{}')]]".format(self.project_name)) self.assertFalse(is_project) logger.info("delete the project successfully") def test_user_delete_project_with_sessions_confirm(self): driver = self.driver create_session_for_project(self) # delete the created project delete_button = driver.find_element( "xpath", "//tr[td[contains(text(), '{}')]]//i[contains(@class, 'pe-7s-trash')]" .format(self.project_name)) delete_button.click() logger.info("click the delete button") time.sleep(1) # Check delete modal pops up is_delete_modal = self.selenium.is_element_exist("id", "delete_modal") self.assertTrue(is_delete_modal) logger.info("delete modal pop up") time.sleep(1) # click confirm confirm_delete_button = driver.find_element_by_id("confirm_delete") confirm_delete_button.click() logger.info("click the confirm button") time.sleep(1) # Check delete success is_project = self.selenium.is_element_exist( "xpath", "//tr[td[contains(text(), '{}')]]".format(self.project_name)) self.assertFalse(is_project) logger.info("delete the project successfully") def test_user_delete_project_with_sessions_not_confirm(self): driver = self.driver create_session_for_project(self) # delete the created project delete_button = driver.find_element( "xpath", "//tr[td[contains(text(), '{}')]]//i[contains(@class, 'pe-7s-trash')]" .format(self.project_name)) delete_button.click() logger.info("click the delete button") time.sleep(1) # Check delete modal pops up is_delete_modal = self.selenium.is_element_exist("id", "delete_modal") self.assertTrue(is_delete_modal) logger.info("delete modal doesn't pop up") # click cancel cancel_delete_button = driver.find_element_by_id("cancel_delete") cancel_delete_button.click() logger.info("click the cancel button") time.sleep(1) # Check delete success is_project = self.selenium.is_element_exist( "xpath", "//tr[td[contains(text(), '{}')]]".format(self.project_name)) self.assertTrue(is_project) logger.info("cancel deleting the project")
def setUp(self): self.selenium = MySelenium('Chrome') self.driver = self.selenium.driver self.base_url = Config().get('URL') self.driver.get(self.base_url + "/login") time.sleep(1)
class TestAdminLogin(unittest.TestCase): def setUp(self): self.selenium = MySelenium('Chrome') self.driver = self.selenium.driver self.base_url = Config().get('URL') self.driver.get(self.base_url + "/login") time.sleep(1) def tearDown(self): self.driver.close() def test_admin_login_with_correct_name(self): driver = self.driver # type "admin" into username_input username_input = driver.find_element( "xpath", "//div[@id='login-tabpane-admin']/form/div/input") username_input.send_keys("admin") logger.info("type 'admin' into input") # click submit button submit_button = driver.find_element( "xpath", "//div[@id='login-tabpane-admin']/form/button") submit_button.click() logger.info('click submit button') time.sleep(1) # Check url is "/dashboard" and username is "admin" curURL = driver.current_url logger.info('curURL is: ' + curURL) self.assertEqual(curURL, self.base_url + "/dashboard") name = driver.find_element("id", "username").text logger.info('current username is' + name) self.assertEquals(name, "admin") def test_admin_login_with_wrong_name(self): driver = self.driver # type "admin1" into username_input username_input = driver.find_element( "xpath", "//div[@id='login-tabpane-admin']/form/div/input") username_input.send_keys("admin1") logger.info("type 'admin1' into input") # click submit button submit_button = driver.find_element( "xpath", "//div[@id='login-tabpane-admin']/form/button") submit_button.click() logger.info('click submit button') time.sleep(1) # Find url is "/dashboard" and alert is "Enter 'admin' as the username" curURL = driver.current_url logger.info('curURL is: ' + curURL) self.assertEqual(curURL, self.base_url + "/login") is_alert = self.selenium.is_element_exist("xpath", "//div[@role='alert']") self.assertTrue(is_alert) logger.info('alert pops up') if is_alert: alert_msg = driver.find_element("xpath", "//div[@role='alert']").text self.assertEqual(alert_msg, "Admin name is wrong!") logger.info('check alert_msg is: ' + alert_msg)
class TestAdminEditUser(unittest.TestCase): def setUp(self): self.selenium = MySelenium('Chrome') self.driver = self.selenium.driver self.base_url = Config().get('URL') self.first_name = random_first_name() self.last_name = random_last_name() self.email = random_email() self.new_first_name = random_first_name() self.new_last_name = random_last_name() def tearDown(self): clean_up(self) self.driver.close() def test_admin_edit_user(self): driver = self.driver # create a new user for editting self.driver.get(self.base_url + "/login") self.driver.find_element( "xpath", "//div[@id='login-tabpane-admin']/form/div/input").send_keys( "admin") self.driver.find_element( "xpath", "//div[@id='login-tabpane-admin']/form/button").click() time.sleep(1) create_new_user_button = driver.find_element_by_id( "create_new_user_button") create_new_user_button.click() time.sleep(1) create_first_name = driver.find_element_by_id("create_first_name") create_last_name = driver.find_element_by_id("create_last_name") create_emal = driver.find_element_by_id("create_email") create_first_name.send_keys(self.first_name) create_last_name.send_keys(self.last_name) create_emal.send_keys(self.email) confirm_create_new_user_button = driver.find_element_by_id( "confirm_create_new_user_button") confirm_create_new_user_button.click() time.sleep(1) logger.info("create a user for editting") search_user(self) # edit the created user edit_button = driver.find_element( "xpath", "//tr[td[contains(text(), '{}')]]//i[contains(@class, 'pe-7s-note')]" .format(self.email)) edit_button.click() logger.info("click edit button") time.sleep(1) # Check edit modal pops up is_eidt_modal = self.selenium.is_element_exist("id", "edit_modal") self.assertTrue(is_eidt_modal) logger.info("edit modal pops up") # edit with new firstname and new lastname edit_first_name = driver.find_element_by_id("edit_first_name") edit_last_name = driver.find_element_by_id("edit_last_name") edit_first_name.clear() edit_first_name.send_keys(self.new_first_name) edit_last_name.clear() edit_last_name.send_keys(self.new_last_name) logger.info("change first name: " + self.first_name + ' to ' + self.new_first_name) logger.info("change last name: " + self.last_name + ' to ' + self.new_last_name) # click confirm button confirm_edit_button = driver.find_element_by_id("confirm_edit") confirm_edit_button.click() time.sleep(1) logger.info("click confirm button") # check the user just modified editted_first_name = driver.find_element( "xpath", "//tr[td[contains(text(), '{}')]]/td[2]".format(self.email)).text editted_last_name = driver.find_element( "xpath", "//tr[td[contains(text(), '{}')]]/td[3]".format(self.email)).text self.assertEqual(editted_first_name, self.new_first_name) self.assertEqual(editted_last_name, self.new_last_name) logger.info("edit first name to: " + editted_first_name) logger.info("edit last name to: " + editted_last_name)
class TestAdminAddUser(unittest.TestCase): def setUp(self): self.selenium = MySelenium('Chrome') self.base_url = Config().get('URL') self.first_name = random_first_name() self.last_name = random_last_name() self.email = random_email() self.driver = self.selenium.driver self.driver.get(self.base_url + "/login") self.driver.find_element( "xpath", "//div[@id='login-tabpane-admin']/form/div/input").send_keys( "admin") self.driver.find_element( "xpath", "//div[@id='login-tabpane-admin']/form/button").click() time.sleep(1) def tearDown(self): clean_up(self) self.driver.close() def test_admin_add_new_user_with_non_exist_user(self): driver = self.driver # Click create new user button to show modal create_new_user_button = driver.find_element_by_id( "create_new_user_button") create_new_user_button.click() logger.info('click the create new user button') time.sleep(1) # Check CreateModal is pop up create_modal = self.selenium.is_element_exist("id", "create_modal") self.assertTrue(create_modal) logger.info('create user modal pops up') # Type in firstname, lastname, email into inputs create_first_name = driver.find_element_by_id("create_first_name") create_last_name = driver.find_element_by_id("create_last_name") create_emal = driver.find_element_by_id("create_email") create_first_name.send_keys(self.first_name) create_last_name.send_keys(self.last_name) create_emal.send_keys(self.email) logger.info("input first name: " + self.first_name) logger.info("input last name: " + self.last_name) logger.info("input email: " + self.email) # click confirm button confirm_create_new_user_button = driver.find_element_by_id( "confirm_create_new_user_button") confirm_create_new_user_button.click() logger.info("click submit button") time.sleep(1) search_user(self) # check whether the user is created successfully new_user_email = self.selenium.is_element_exist( "xpath", "//tr[td[contains(text(), '{}')]]".format(self.email)) self.assertTrue(new_user_email) logger.info("create user successfully") if new_user_email: new_user_first_name = driver.find_element( "xpath", "//tr[td[contains(text(), '{}')]]/td[2]".format( self.email)).text new_user_last_name = driver.find_element( "xpath", "//tr[td[contains(text(), '{}')]]/td[3]".format( self.email)).text self.assertEqual(new_user_first_name, self.first_name) self.assertEqual(new_user_last_name, self.last_name) logger.info("check the first name: " + new_user_first_name) logger.info("check the last name: " + new_user_last_name) def test_admin_add_user_with_exist_user(self): driver = self.driver # Click create new user button to add a new user create_new_user_button = driver.find_element_by_id( "create_new_user_button") create_new_user_button.click() logger.info('click the create new user button') time.sleep(1) # Check CreateModal is pop up create_modal = self.selenium.is_element_exist("id", "create_modal") self.assertTrue(create_modal) logger.info('create user modal pops up') # Type in firstname, lastname, email into inputs create_first_name = driver.find_element_by_id("create_first_name") create_last_name = driver.find_element_by_id("create_last_name") create_emal = driver.find_element_by_id("create_email") create_first_name.send_keys(self.first_name) create_last_name.send_keys(self.last_name) create_emal.send_keys(self.email) logger.info("input first name: " + self.first_name) logger.info("input last name: " + self.last_name) logger.info("input email: " + self.email) # click confirm button confirm_create_new_user_button = driver.find_element_by_id( "confirm_create_new_user_button") confirm_create_new_user_button.click() logger.info("click submit button") time.sleep(1) # Click create new user button to add the same user again create_new_user_button = driver.find_element_by_id( "create_new_user_button") create_new_user_button.click() logger.info('click the create new user button') time.sleep(1) # Check CreateModal is pop up create_modal = self.selenium.is_element_exist("id", "create_modal") self.assertTrue(create_modal) logger.info('create user modal pops up') # Type in firstname, lastname, email into inputs create_first_name = driver.find_element_by_id("create_first_name") create_last_name = driver.find_element_by_id("create_last_name") create_emal = driver.find_element_by_id("create_email") create_first_name.send_keys(self.first_name) create_last_name.send_keys(self.last_name) create_emal.send_keys(self.email) logger.info("input first name: " + self.first_name) logger.info("input last name: " + self.last_name) logger.info("input email: " + self.email) # click confirm button confirm_create_new_user_button = driver.find_element_by_id( "confirm_create_new_user_button") confirm_create_new_user_button.click() logger.info("click submit button") time.sleep(1) # check error_msg is_error_modal = self.selenium.is_element_exist("id", "error_modal") self.assertTrue(is_error_modal) logger.info('error modal pops up') if is_error_modal: error_modal = driver.find_element_by_id("error_modal") error_msg = driver.find_element_by_xpath( "//div[@id='error_modal']/div/div[2]").text self.assertEqual(error_msg, "Request failed with status code 409") logger.info("error msg is: ", error_msg)
class TestUserLogin(unittest.TestCase): def setUp(self): self.selenium = MySelenium('Chrome') self.driver = self.selenium.driver self.base_url = Config().get('URL') # Variables self.user_first_name = random_first_name() self.user_last_name = random_last_name() self.user_email = random_email() def tearDown(self): clean_up(self) self.driver.close() def test_admin_login_with_existing_user(self): # setup script admin_create_new_user_logout(self) driver = self.driver driver.get(self.base_url + "/login") # Find tab for the user form user_tab = driver.find_element_by_link_text("User") logger.info('find user tab: ' + user_tab.text) # Click the user tab user_tab.click() logger.info('click the tab') time.sleep(1) # Find input for the user login username_input = driver.find_element("xpath", "//div[@id='login-tabpane-user']/form/div/input") # Check the input placeholder placeholder = username_input.get_attribute('placeholder') logger.info('find input: ' + placeholder) self.assertEqual(placeholder, "Enter your email") # type existing user email into username_input username_input.send_keys(self.user_email) logger.info('type into input: ' + username_input.get_attribute("value")) # find submit button submit_button = driver.find_element("xpath", "//div[@id='login-tabpane-user']/form/button") logger.info('find button: ' + submit_button.text) # click "submit" button submit_button.click() logger.info('click button') time.sleep(1) # Check url is "/dashboard" and username is "*****@*****.**" curURL = driver.current_url logger.info('curURL is: ' + curURL) self.assertEqual(curURL, self.base_url + "/dashboard") name = driver.find_element("id", "username").text logger.info('current username is' + name) self.assertEquals(name, self.user_email) def test_admin_login_with_non_existing_user(self): driver = self.driver driver.get(self.base_url + "/login") # Find tab for the user form user_tab = driver.find_element_by_link_text("User") logger.info('find user tab: ' + user_tab.text) # Click the user tab user_tab.click() logger.info('click the tab') time.sleep(1) # Find input for the user login username_input = driver.find_element("xpath", "//div[@id='login-tabpane-user']/form/div/input") # type non-existing user into username_input username_input.send_keys(random_email()) logger.info('type into input: ' + username_input.get_attribute("value")) # find submit button submit_button = driver.find_element("xpath", "//div[@id='login-tabpane-user']/form/button") logger.info('find button: ' + submit_button.text) # click "submit" button submit_button.click() logger.info('click button') time.sleep(1) # Find alert is "User does not exist!" curURL = driver.current_url logger.info('curURL is: ' + curURL) self.assertEqual(curURL, self.base_url + "/login") # Give it a few seconds to load... self.selenium.element_wait("xpath", "//div[@role='alert']", 5) alert = driver.find_element("xpath", "//div[@role='alert']") logger.info('check alert is: ' + alert.text) self.assertEqual(alert.text, "User does not exist!")