def valid_login(self, username=False): self.load_elements() if username: self.clear_input(self.email, USERNAME) else: self.clear_input(self.email, EMAIL) self.clear_input(self.password, PASSWORD) self.submit.send_keys(Keys.RETURN) wait = WebDriverWait(self.driver, 3) alert = wait.until( EC.visibility_of_element_located( (By.XPATH, '//div[@id="toast-container"]'))) text = alert.text sleep(5) try: assert self.driver.current_url == LOGGED_URL assert text == 'cool, have fun!!' self.result['Valid Login'] = SUCCESS if username: print_result('Valid Login with username Succeed') else: print_result('Valid Login with email Succeed') except AssertionError: if username: print_error('Valid Login with username raises an error') else: print_error('Valid Login with email raises an error') self.result['Valid Login'] = FAIL sleep(1) print()
def check_cc(self): get_url = 'https://api.constantcontact.com/v2/contacts?api_key=8frjx94rfxgfkxt6c75usrrw&email=' + CREATED_EMAIL get_data = { 'headers': { 'Authorization': 'Bearer ef2ab36e-f853-4546-8ebe-e0113e85cb5b', 'Content-Type': 'application/json' } } r = requests.request('GET', get_url, **get_data) if r.status_code == 200: user = json.loads(r.content) contacts_id = None try: contacts_id = user['results'][0]['id'] except: pass try: assert contacts_id is not None print_result('Contact Contact User Added Succeed') self.result['Contact Contact User Added'] = SUCCESS except AssertionError: print_error('Contact Contact User Added Fail') self.result['Contact Contact User Added'] = FAIL delete_url = 'https://api.constantcontact.com/v2/contacts/' + contacts_id + '?api_key=8frjx94rfxgfkxt6c75usrrw' rd = requests.request('DELETE', delete_url, **get_data) try: assert str(rd.status_code) == '204' print_result('Contact Contact User Delete Succeed') self.result['Contact Contact User Delete'] = SUCCESS except AssertionError: print_error('Contact Contact User Delete Fail') self.result['Contact Contact User Delete'] = FAIL
def google(self): self.load_elements() main_handle = self.driver.current_window_handle google = self.driver.find_element_by_id('login-gl') google.click() another_window = list(set(self.driver.window_handles) - {main_handle})[0] self.driver.switch_to.window(another_window) sleep(3) email = self.driver.find_element_by_id('identifierId') email.send_keys('*****@*****.**') next = self.driver.find_element_by_id('identifierNext') next.click() sleep(2) password = self.driver.find_element_by_xpath( '//input[@name="password"]') password.send_keys('5DDydr9r') next = self.driver.find_element_by_id('passwordNext') next.click() sleep(5) self.driver.switch_to.window(main_handle) try: assert self.driver.current_url == LOGGED_URL print_result('Google + success Succeed') self.result['Google + success'] = SUCCESS except AssertionError: print_error('Google + success login raises an error') self.result['Google + success'] = FAIL
def facebook(self, success=True): self.load_elements() main_handle = self.driver.current_window_handle facebook = self.driver.find_element_by_id('login-fb') facebook.click() another_window = list(set(self.driver.window_handles) - {main_handle})[0] self.driver.switch_to.window(another_window) sleep(3) email = self.driver.find_element_by_id('email') if success: email.send_keys('*****@*****.**') else: email.send_keys(FACEBOOK_EMAIL) sleep(1) password = self.driver.find_element_by_id('pass') if success: password.send_keys('Gerr@rd4') else: password.send_keys(FACEBOOK_PASSWORD) sleep(1) login = self.driver.find_element_by_xpath( '//label[@id="loginbutton"]/input') login.click() sleep(5) self.driver.switch_to.window(main_handle) sleep(1) if success: try: assert self.driver.current_url == LOGGED_URL print_result('Facebook success Succeed') self.result['Facebook success'] = SUCCESS except AssertionError: print_error('Facebook success login raises an error') self.result['Facebook success'] = FAIL else: try: assert self.driver.current_url == 'https://jazwings.com/login' print_result('Facebook failed Succeed') self.result['Facebook failed'] = SUCCESS except AssertionError: print_error('Facebook failed login raises an error') self.result['Facebook failed'] = FAIL sleep(1) print()
def check_points(self): toggle = self.driver.find_elements_by_xpath( '//a[@class="dropdown-toggle"]')[0] toggle.click() links = self.driver.find_elements_by_xpath( '//ul[@class="dropdown-menu"]/li/a') for link in links: if link.text == 'Profile': link.click() sleep(5) span = self.driver.find_element_by_id('creator_pts') try: assert '100' in span.text print_result('User Points Succeed') self.result['User Points'] = SUCCESS except AssertionError: self.result['User Points'] = FAIL print_error('User Points Failed')
def login_link(self): login_element = self.driver.find_element_by_id('login') login_element.click() sleep(2) self.load_elements() try: assert self.driver.current_url == 'https://jazwings.com/login' assert self.email is not None assert self.password is not None assert self.submit is not None self.result['Login link'] = SUCCESS print_result('Login link Succeed') except AssertionError: print_error('Login link raises an error') self.result['Login link'] = FAIL print()
def invalid_email(self, username, password, task): self.clear_input(self.email, username) self.clear_input(self.password, password) self.submit.send_keys(Keys.RETURN) wait = WebDriverWait(self.driver, 2) alert = wait.until( EC.visibility_of_element_located( (By.XPATH, '//div[@id="toast-container"]'))) text = alert.text sleep(5) try: assert text == 'Unable to log in with provided credentials.' self.result[task] = SUCCESS print_result('Invalid email Succeed') except AssertionError: print_error('Login with random text raises an error') self.result[task] = FAIL sleep(1) print()
def main(): args = _parse_args() service = services.factory.create(args.engine, Config()) resultnum = try_get_number(args.query) if args.last_query: results = service.get_latest_results() if results != None: output.print_results(results) if resultnum != None and 1 <= resultnum <= 10: results = service.get_latest_results() if results != None and resultnum <= len(results): output.print_result(results[resultnum - 1]) else: print "No results found" else: query = Query(args.query) results = service.search(query) output.print_results(results)
def delete_user(self): select_query = "SELECT id FROM auth_user WHERE username='******'" % CREATED_USERNAME user_id = None self.database.cursor.execute(select_query) for _id in self.database.cursor.fetchall(): user_id = _id[0] gamification_query = "DELETE FROM gamification_pointactionperson WHERE user_id='%s'" % user_id self.database.cursor.execute(gamification_query) query = "DELETE FROM people_person WHERE user_ptr_id IN (SELECT id FROM auth_user WHERE username='******')" % CREATED_USERNAME self.database.cursor.execute(query) self.database.prod.commit() self.database.cursor.execute(select_query) exist = False try: for _ in self.database.cursor.fetchall(): exist = True break except psycopg2.ProgrammingError: pass self.database.cursor.execute( "SELECT dob FROM people_person WHERE user_ptr_id='%s'" % str(user_id)) try: for _ in self.database.cursor.fetchall(): exist = True break except psycopg2.ProgrammingError: pass try: assert exist is False print_result('Delete User Succeed') self.result['Delete User'] = SUCCESS except AssertionError: print_error('Delete User Failed') self.result['Delete User'] = FAIL
def logout(self, redirect=True): toggle = self.driver.find_elements_by_xpath( '//a[@class="dropdown-toggle"]')[0] toggle.click() links = self.driver.find_elements_by_xpath( '//ul[@class="dropdown-menu"]/li/a') for link in links: if link.text == 'Logout': link.click() sleep(5) login = self.driver.find_element_by_id('login') try: assert self.driver.current_url == self.url assert login is not None if redirect: login.click() sleep(1) self.result['Valid Logout'] = SUCCESS print_result('Valid logout Succeed') except AssertionError: print_error('Logout raises an error') self.result['Valid Logout'] = FAIL sleep(1) print()
def and_or(article_id_list, operator_list): dot = Digraph('G') # set font as 新細明體(PmingLiu) # without setting this, windows cannot print Chinese dot.node_attr['fontname'] = "PmingLiu" article_id_stack = [] operator_stack = [] article_id_index = 0 operator_index = 0 # If a node is at the top level of a graph, we use its position in article_id_list as its index # If a node is not at the top level of a graph, we use negative number, node_index, as its index node_index = -1 node_prefix = 'last' with dot.subgraph(name='flow_chart1') as s: s.attr(rank='same') while article_id_index < len(article_id_list): cur_article_id_str = produce_graph_upper.list2str( article_id_list[article_id_index], 10, len(article_id_list)) article_id_stack.append( IdNode(article_id_list[article_id_index], article_id_index + 1)) # Create a node, s.node(node_prefix + str(article_id_index + 1), cur_article_id_str) if operator_index >= len(operator_list): break if len(operator_stack) == 0 or operator_stack[-1] == '|': operator_stack.append(operator_list[operator_index]) else: cur_article_node1 = article_id_stack.pop() cur_article_node2 = article_id_stack.pop() cur_operator = operator_stack.pop() cur_result = and_or_operation(cur_article_node1.id_list, cur_article_node2.id_list, cur_operator) article_id_stack.append(IdNode(cur_result, node_index)) # Create a node dot.node( node_prefix + str(node_index), produce_graph_upper.list2str(sorted(cur_result), 10, len(article_id_list))) # Connect node dot.edge(node_prefix + str(cur_article_node1.index), node_prefix + str(node_index), color=OperationColor.AND.value) dot.edge(node_prefix + str(cur_article_node2.index), node_prefix + str(node_index), color=OperationColor.AND.value) # After generating a new node, decrease node_index by one node_index -= 1 operator_stack.append(operator_list[operator_index]) operator_index += 1 article_id_index += 1 while len(operator_stack) > 0: cur_article_node1 = article_id_stack.pop() cur_article_node2 = article_id_stack.pop() cur_operator = operator_stack.pop() result = and_or_operation(cur_article_node1.id_list, cur_article_node2.id_list, cur_operator) article_id_stack.append(IdNode(result, node_index)) # Create a node dot.node( node_prefix + str(node_index), produce_graph_upper.list2str(sorted(result), 10, len(article_id_list))) dot.edge(node_prefix + str(cur_article_node1.index), node_prefix + str(node_index), color=OperationColor.OR.value if cur_operator == '|' else OperationColor.AND.value) dot.edge(node_prefix + str(cur_article_node2.index), node_prefix + str(node_index), color=OperationColor.OR.value if cur_operator == '|' else OperationColor.AND.value) # After generating a new node, increase node_index by one node_index -= 1 result_id = article_id_stack.pop() output.print_result(result_id.id_list) with dot.subgraph(name='cluster_legend') as c: c.graph_attr['label'] = "Legend" c.node_attr['shape'] = "plaintext" c.node("dummy_node_1", "") c.node("dummy_node_2", "") c.edge('dummy_node_1', 'AND', color=OperationColor.AND.value) c.edge('dummy_node_2', 'OR', color=OperationColor.OR.value) with dot.subgraph(name='cluster_dummy') as c: c.graph_attr['style'] = 'invis' c.node_attr['style'] = 'invis' c.node("dummy_node_3", "") dot.edge("dummy_node_3", "dummy_node_1", ltail="cluster_dummy", lhead="cluster_legend", style="invis") # print(dot) # dot.view() # dot: the graph # node_prefix + str(node_index + 1 if node_index != -1 else 1): the name of the last node # if we have only one node, the name of that node is node_prefix + str(1) return dot, node_prefix + str( node_index + 1 if node_index != -1 else 1), result_id.id_list
def create_account(self): account_link = self.driver.find_element_by_xpath( '//a[@ui-sref="createAccount"]') self.driver.execute_script("arguments[0].click();", account_link) # account_link.click() sleep(2) try: assert self.driver.current_url == REGISTER_URL self.result['Creation link'] = SUCCESS print_result('Creation link Succeed') except AssertionError: self.result['Creation link'] = FAIL print_error('Creation link Failed') first_name = self.driver.find_element_by_id('firstName') self.fill_field(first_name, CREATED_FIRST_NAME) sleep(1) last_name = self.driver.find_element_by_xpath( '//input[@name="lastName"]') self.fill_field(last_name, CREATED_LAST_NAME) sleep(1) self.select_option('birthday-month', 'January') sleep(1) self.select_option('birthday-day', '01') sleep(1) self.select_option('birthday-year', '1980') sleep(1) email = self.driver.find_element_by_xpath('//input[@name="email"]') self.fill_field(email, CREATED_EMAIL) sleep(1) password = self.driver.find_element_by_xpath( '//input[@name="password"]') self.fill_field(password, CREATED_PASSWORD) sleep(1) username = self.driver.find_element_by_id('displayName') self.fill_field(username, CREATED_USERNAME) sleep(1) self.select_option('country', CREATED_SOURCE) sleep(1) rules = self.driver.find_element_by_xpath('//input[@name="rules"]') rules.click() sleep(2) submit = self.driver.find_element_by_id('create-login-bt') self.driver.execute_script("arguments[0].click();", submit) sleep(5) check = False username_links = self.driver.find_elements_by_xpath('//a[@href="#"]') for username_link in username_links: if username_link.text == CREATED_USERNAME: check = True try: assert self.driver.current_url == CONFIRM_URL assert check print_result('Create User Succeed') self.result['Create User'] = SUCCESS except AssertionError: print_result('Create User Failed') self.result['Create User'] = FAIL print()