Best Python code snippet using selene_python
test_graph_creation.py
Source:test_graph_creation.py
...73 matron_button = self.driver.find_element_by_id("matron")74 75 # creating triagle using hallway only76 create_triangle = ActionChains(self.driver)77 create_triangle.move_to_element_with_offset(matron_button, 150, 500).context_click()\78 .move_to_element_with_offset(matron_button, 350, 500).context_click()\79 .move_to_element_with_offset(matron_button, 250, 250).context_click()\80 .move_to_element_with_offset(matron_button, 150, 500).context_click()81 82 create_triangle.perform()83 sleep(1)84 85 86 # remove map used for test case87 remove_saved_map(self.driver, "test_selenium")88 89 self.driver.close()90 91 92 def test_navigate_outside_screen(self):93 # set up for the test case94 initial_set_up_map(self.driver, "test_selenium")95 # matron button on the top left of the webpage96 matron_button = self.driver.find_element_by_id("matron") 97 98 # action chain for creating a node 99 action_create_a_node = ActionChains(self.driver)100 action_create_a_node.move_to_element_with_offset(matron_button, 10, 70).click()101 102 # action chain for dragging to right103 action_move_view_to_right = ActionChains(self.driver)104 action_move_view_to_right\105 .move_to_element_with_offset(matron_button, 200, 200)\106 .click_and_hold()\107 .move_by_offset(60, 0)\108 .move_by_offset(60, 0)\109 .release()110 111 # action chain for dragging to left112 action_move_view_to_left = ActionChains(self.driver) 113 action_move_view_to_left\114 .move_to_element_with_offset(matron_button, 200, 200)\115 .click_and_hold()\116 .move_by_offset(-60, 0)\117 .move_by_offset(-60, 0)\118 .release()119 120 # action chain for creating edges between two nodes121 create_edge = ActionChains(self.driver)122 create_edge\123 .move_to_element_with_offset(matron_button, 10, 70)\124 .context_click()\125 .move_to_element_with_offset(matron_button, 130, 70)\126 .context_click()127 128 # perform the action chains and label nodes129 create_node(self.driver, 10, 70, "r1", "room")130 action_move_view_to_left.perform()131 create_node(self.driver, 10, 70, "r2", "room")132 action_move_view_to_right.perform()133 create_edge.perform()134 sleep(1)135 136 # remove map used for test case137 remove_saved_map(self.driver, "test_selenium")138 139 self.driver.close()140 141 def test_saving_delete(self):142 # set up for the test case143 initial_set_up_map(self.driver, "test_selenium")144 145 # matron button on the top left of the webpage146 matron_button = self.driver.find_element_by_id("matron") 147 148 # create a node to be saved.149 create_node(self.driver, 150, 500, "r1", "room")150 151 # save and refresh152 self.driver.find_element_by_id("save_icon").click()153 matron_button.click()154 sleep(1)155 156 # Open the saved map157 input_element = self.driver.find_element_by_xpath("/html/body/div[5]/div[2]/div/input[2]")158 input_element.send_keys("test_selenium")159 input_element.send_keys(Keys.ENTER)160 sleep(1)161 162 # reload163 self.driver.find_element_by_id('edit_floor').click()164 sleep(1) 165 # remove map used for test case166 remove_saved_map(self.driver, "test_selenium")167 168 self.driver.close()169 def test_delete_keydown(self):170 # set up for the test case171 initial_set_up_map(self.driver, "test_selenium")172 173 # matron button on the top left of the webpage174 matron_button = self.driver.find_element_by_id("matron") 175 create_first_room = ActionChains(self.driver)176 create_second_room = ActionChains(self.driver)177 connect_with_two_hallway = ActionChains(self.driver)178 create_node(self.driver, 150, 500, "r1", "room")179 create_node(self.driver, 450, 500, "r2", "room")180 connect_with_two_hallway.move_to_element_with_offset(matron_button, 150, 500).context_click()\181 .move_to_element_with_offset(matron_button, 250, 500).context_click()\182 .move_to_element_with_offset(matron_button, 350, 500).context_click()\183 .move_to_element_with_offset(matron_button, 450, 500).context_click() 184 sleep(1)185 connect_with_two_hallway.perform()186 delete_edge_1 = ActionChains(self.driver)187 delete_edge_2 = ActionChains(self.driver)188 delete_edge_3 = ActionChains(self.driver)189 delete_edge_1.move_to_element_with_offset(matron_button, 200, 500).click().send_keys('x')190 delete_edge_2.move_to_element_with_offset(matron_button, 300, 500).click().send_keys('x')191 delete_edge_3.move_to_element_with_offset(matron_button, 400, 500).click().send_keys('x')192 delete_edge_1.perform()193 delete_edge_2.perform()194 delete_edge_3.perform()195 delete_all_nodes = ActionChains(self.driver)196 delete_all_nodes.move_to_element_with_offset(matron_button, 150, 500).click().send_keys('x')\197 .move_to_element_with_offset(matron_button, 250, 500).click().send_keys('x')\198 .move_to_element_with_offset(matron_button, 350, 500).click().send_keys('x')\199 .move_to_element_with_offset(matron_button, 450, 500).click().send_keys('x')200 delete_all_nodes.perform()201 sleep(1)202 203 # remove map used for test case204 remove_saved_map(self.driver, "test_selenium")205 206 self.driver.close()207 208 def test_distance(self):209 # set up for the test case210 initial_set_up_map(self.driver, "test_selenium")211 212 # matron button on the top left of the webpage213 matron_button = self.driver.find_element_by_id("matron") 214 215 # list of action chains216 make_r1 = ActionChains(self.driver)217 make_r2 = ActionChains(self.driver)218 path_1 = ActionChains(self.driver)219 path_2 = ActionChains(self.driver)220 path_3 = ActionChains(self.driver)221 222 make_r1.move_to_element_with_offset(matron_button, 200, 250).click()223 make_r2.move_to_element_with_offset(matron_button, 400, 250).click()224 path_1.move_to_element_with_offset(matron_button, 200,250).context_click()\225 .move_to_element_with_offset(matron_button, 400, 250).context_click()226 path_2.move_to_element_with_offset(matron_button, 200, 250).context_click()\227 .move_to_element_with_offset(matron_button, 300, 350).context_click()\228 .move_to_element_with_offset(matron_button, 400, 250).context_click()229 path_3.move_to_element_with_offset(matron_button, 200, 250).context_click()\230 .move_to_element_with_offset(matron_button, 200, 150).context_click()\231 .move_to_element_with_offset(matron_button, 400, 150).context_click()\232 .move_to_element_with_offset(matron_button, 400, 250).context_click()233 # make nodes234 create_node(self.driver, 200, 250, "r1", "room")235 create_node(self.driver, 400, 250, "r2", "room")236 path_1.perform()237 path_2.perform()238 path_3.perform()239 self.driver.find_element_by_id("save_icon").click()240 self.driver.find_element_by_id("distance_icon").click()241 self.driver.find_element_by_id("node1").send_keys("r1")242 self.driver.find_element_by_id("node2").send_keys("r2")243 self.driver.find_element_by_id("distance_btn").click()244 sleep(1)245 distance = self.driver.find_element_by_id("dist_result").text.split(':')246 247 # ensure the value here248 assert int(distance[1]) == 200249 dist_pop_up = self.driver.find_element_by_id("distance_modal")250 dist_pop_up.find_element_by_class_name("close").click()251 # remove map used for test case252 remove_saved_map(self.driver, "test_selenium")253 254 self.driver.close()255 def test_rescale_graph(self):256 # set up for the test case257 initial_set_up_map(self.driver, "test_selenium")258 # matron button on the top left of the webpage259 matron_button = self.driver.find_element_by_id("matron") 260 261 # create three nodes with equal distance262 create_node(self.driver, 200, 200, "r1", "room")263 create_node(self.driver, 300, 200, "r2", "room")264 create_node(self.driver, 400, 200, "r3", "room")265 266 # create edges267 ActionChains(self.driver)\268 .move_to_element_with_offset(matron_button, 200, 200).context_click()\269 .move_to_element_with_offset(matron_button, 300, 200).context_click()\270 .move_to_element_with_offset(matron_button, 300, 200).context_click()\271 .move_to_element_with_offset(matron_button, 400, 200).context_click()\272 .perform()273 274 # rescale the graph275 self.driver.find_element_by_id("rescale_icon").click()276 sleep(1)277 self.driver.find_element_by_id("rescale_button").click()278 self.driver.find_element_by_id("rescale_input").send_keys("1")279 self.driver.find_element_by_id("rescale_button").click()280 self.driver.find_element_by_id("rescale_button").click()281 self.driver.find_element_by_id("rescale_input").send_keys("2")282 self.driver.find_element_by_id("rescale_button").click()283 284 # compare the distance285 # first from r1 to r2...
mouseMap.py
Source:mouseMap.py
1from selenium import webdriver2def context_click(driver, element):3 '''ç¹å»é¼ æ å³é®æä½'''4 try:5 context_click = webdriver.ActionChains(driver).context_click(element).perform()6 except Exception as e:7 print('context_click error:%s' % e)8 else:9 return context_click10def double_click(driver, element):11 '''åå»é¼ æ æä½'''12 try:13 double_click = webdriver.ActionChains(driver).double_click(element).perform()14 except Exception as e:15 print('double_click error:%s' % e)16 else:17 return double_click18def drag_and_drop(driver, x, y):19 '''æå¨é¼ æ æä½'''...
test_MouseHOverOperations.py
Source:test_MouseHOverOperations.py
...9 act=ActionChains(driver)10 #time.sleep(3)11 #act.click().perform()12 #time.sleep(10)13 #act.context_click().perform()14 #clickOperation15 #act.click(driver.find_element_by_xpath("//*[text()='Login']")).perform()16 #contxtclick(rightclick)17 #act.context_click().perform()18 #act.context_click(driver.find_element_by_xpath("//*[text()='Login']")).perform()19 #double click20 #act.double_click(driver.find_element_by_xpath("//*[text()='Login']")).perform()21 #mouse over event22 act.move_to_element(driver.find_element_by_xpath("//*[contains(@title,'TUTORIAL')]")).perform()...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!