def test_something(self): # Use the assert* functions to determine the outcome of a test. unittest.assertEqual(1,1) unittest.assertNotEqual(1,0) unittest.assertTrue(1 == 1) unittest.assertFalse(1 == 0) unittest.assertIs(a, b) unittest.assertIsNot(a, c) unittest.assertIsNone(None) unittest.assertIsNotNone(a) unittest.assertIn(1, a) unittest.assertNotIn(4, b) unittest.assertIsInstance(c, list) unittest.assertNotIsInstance(d, list) unittest.assertRaises() unittest.assertRaisesRegex() unittest.assertWarns() unittest.assertWarnsRegex() unittest.assertLogs() unittest.assertAlmostEqual() unittest.assertNotAlmostEqual() unittest.assertGreater() unittest.assertGreaterEqual() unittest.assertLess() unittest.assertLessEqual() unittest.assertRegex() unittest.assertNotRegex() unittest.assertCountEqual()
def animation_to_image_window(unittest, driver): animWindow = WebDriverWait(driver, 20).until(EC.presence_of_element_located((By.XPATH, "//div[@qxclass='skel.widgets.Window.DisplayWindowAnimation']"))) unittest.assertIsNotNone( animWindow, "Could not find animation window") ActionChains(driver).click( animWindow ).perform() # Make sure the animation window is enabled by clicking an element within the window # Chrome browser is unable to enable the animation window by clicking on the window channelText = WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.ID, "ChannelIndexText"))) ActionChains(driver).click( channelText).perform() ActionChains(driver).context_click( channelText ).send_keys(Keys.ARROW_RIGHT).send_keys(Keys.ARROW_RIGHT).send_keys(Keys.ENTER).perform()
def add_window(unittest, driver): # Click the Window button windowButton = WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.XPATH, "//div[@qxclass='qx.ui.toolbar.MenuButton']/div[text()='Window']/.."))) unittest.assertIsNotNone( windowButton, "Could not find window button in the context menu") ActionChains(driver).click(windowButton).perform() # Look for the add button in the submenu. addButton = WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.XPATH, "//div/div[text()='Add']/.."))) unittest.assertIsNotNone( addButton, "Could not click minimize button on window subcontext menu.") ActionChains(driver).click( addButton ).send_keys(Keys.ARROW_RIGHT).send_keys(Keys.ENTER).perform() # Check that we now have a generic empty window in the display and that the window count has gone up by one. emptyWindow = WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.XPATH, "//div[@qxclass='skel.widgets.Window.DisplayWindowGenericPlugin']"))) unittest.assertIsNotNone( emptyWindow, "Could not find empty display window") ActionChains(driver).click( emptyWindow ).perform() return emptyWindow
def load_image(unittest, driver, imageName): # If image is not specified, load default image # Change this to a test image available where the tests are running # Test image will ideally have more than 3 channels for a successful test run if imageName == "Default": imageName = "N15693D.fits" # Wait 20 seconds for the imageWindow to appear on the page imageWindow = WebDriverWait(driver, 30).until(EC.presence_of_element_located((By.XPATH, "//div[@qxclass='skel.widgets.Window.DisplayWindowImage']"))) # Find a window capable of loading an image and select the window ActionChains(driver).click( imageWindow ).perform() # Precaution, sometimes the driver does not enable the window when first clicks the window ActionChains(driver).click( imageWindow ).perform() # Click the data button dataButton = WebDriverWait(driver, 20).until(EC.presence_of_element_located((By.XPATH, "//div[text()='Data']/.."))) unittest.assertIsNotNone( dataButton, "Could not click data button in the context menu") ActionChains(driver).click(dataButton).perform() # Look for the open button and click it to open the file dialog. openDataButton = WebDriverWait(driver, 20).until(EC.presence_of_element_located((By.XPATH, "//div/div[text()='Open...']/.."))) unittest.assertIsNotNone(openDataButton, "Could not click open button on data subcontext menu.") ActionChains(driver).send_keys(Keys.ARROW_DOWN).send_keys(Keys.ENTER).perform() # Select the specific image loadButton = WebDriverWait(driver, 20).until(EC.presence_of_element_located((By.ID, "loadFileButton"))) fileDiv = WebDriverWait(driver, 20).until(EC.presence_of_element_located((By.XPATH, "//div[text()='"+imageName+"']"))) driver.execute_script( "arguments[0].scrollIntoView(true);", fileDiv) fileDiv.click() # Click the load button loadButton = driver.find_element_by_id( "loadFileButton") unittest.assertIsNotNone(loadButton, "Could not find load button to click") loadButton.click() # Now close the file dialog closeButton = driver.find_element_by_id( "closeFileLoadButton") unittest.assertIsNotNone(loadButton, "Could not find button to close the file browser") closeButton.click() # Check that the window is displaying an image. viewElement = driver.find_element_by_xpath("//div[@qxclass='skel.boundWidgets.View.View']") unittest.assertIsNotNone(viewElement, "Could not find view element on page.") imageElement = driver.find_element_by_id("pwUID0") unittest.assertIsNotNone(imageElement, "Could not find image on the page") return imageWindow
def load_image_different_window(unittest, driver, imageName): # Find a window capable of loading an image. imageWindow = WebDriverWait(driver, 20).until(EC.presence_of_element_located((By.XPATH, "//div[@qxclass='skel.widgets.Window.DisplayWindowImage']"))) unittest.assertIsNotNone( imageWindow, "Could not find image display window") ActionChains(driver).click(imageWindow).perform() # Add a new window below the main casa image window emptyWindow = add_window( unittest, driver) # Change the plugin of the empty window to an image loader ActionChains(driver).context_click( emptyWindow ).send_keys(Keys.ARROW_DOWN).send_keys(Keys.ARROW_RIGHT).send_keys(Keys.ENTER).perform() # Ensure that there is a new image window imageWindow2 = WebDriverWait(driver, 30).until(EC.presence_of_element_located((By.ID, "CasaImageLoader2"))) unittest.assertIsNotNone( imageWindow2, "Could not find second image window") ActionChains(driver).click( imageWindow2 ).perform() # Precaution, sometimes the driver does not enable the window when first clicks the window ActionChains(driver).click( imageWindow2 ).perform() # Click the data button dataButton = WebDriverWait(driver, 20).until(EC.presence_of_element_located((By.XPATH, "//div[text()='Data']/.."))) unittest.assertIsNotNone( dataButton, "Could not click data button in the context menu") ActionChains(driver).click(dataButton).perform() # Look for the open button and click it to open the file dialog. openDataButton = WebDriverWait(driver, 20).until(EC.presence_of_element_located((By.XPATH, "//div/div[text()='Open...']/.."))) unittest.assertIsNotNone(openDataButton, "Could not click open button on data subcontext menu.") ActionChains(driver).send_keys(Keys.ARROW_DOWN).send_keys(Keys.ENTER).perform() # Select the specific image loadButton = WebDriverWait(driver, 20).until(EC.presence_of_element_located((By.ID, "loadFileButton"))) fileDiv = WebDriverWait(driver, 20).until(EC.presence_of_element_located((By.XPATH, "//div[text()='"+imageName+"']"))) driver.execute_script( "arguments[0].scrollIntoView(true);", fileDiv) fileDiv.click() # Click the load button loadButton = driver.find_element_by_id( "loadFileButton") unittest.assertIsNotNone(loadButton, "Could not find load button to click") loadButton.click() # Now close the file dialog closeButton = driver.find_element_by_id( "closeFileLoadButton") unittest.assertIsNotNone(loadButton, "Could not find button to close the file browser") closeButton.click() # Check that the window is displaying an image. viewElement = driver.find_element_by_xpath("//div[@qxclass='skel.boundWidgets.View.View']") unittest.assertIsNotNone(viewElement, "Could not find view element on page.") imageElement = driver.find_element_by_id("pwUID0") unittest.assertIsNotNone(imageElement, "Could not find image on the page") # Return the second image loader window for further linking tests return imageWindow2