Example #1
0
def get_new_firefox_driver():
    preporter.info("Spawning driver: FireFox")
    driver = webdriver.Firefox(executable_path=GeckoDriverManager().install())
    driver.delete_all_cookies()
    driver.fullscreen_window()

    return driver
Example #2
0
def get_new_edge_driver():
    preporter.info("Spawning driver: Edge")
    driver = webdriver.Edge(EdgeDriverManager().install())
    driver.delete_all_cookies()
    driver.fullscreen_window()

    return driver
 def search_item_and_click_on_star(self, item):
     """
     This method performs search for a given content and clicks on the star button which is present in the right side
     of the first result.
     :param item: Name of the content which will get searched
     :return: It returns the type of searched result it acted on. For example player,competition or team.
     """
     self.navigate_to_following_page()
     search_element = self.driver.find_element_visible(self.search_icon,
                                                       wait_until=10)
     self.tap(search_element)
     search_box_element = self.driver.find_element_visible(
         self.search_input_box, wait_until=10)
     preporter.info("Searching for :  {}".format(item))
     search_box_element.send_keys(item)
     first_search_result_element = self.driver.find_element_visible(
         self.searched_first_result, wait_until=10)
     search_result_type = self.driver.find_element_visible(
         self.search_result_type, wait_until=10).text
     actual_search_result_title = first_search_result_element.text
     if item.lower() == actual_search_result_title.lower():
         follow_button = self.driver.find_element_visible(
             self.follow_first_search_result, wait_until=10)
         self.tap(follow_button)
         return search_result_type
     else:
         preporter.info("Searching for {} but found {}".format(
             item, actual_search_result_title))
         raise ValueError(
             "Did't found proper search result for {}".format(item))
Example #4
0
 def download_file(self, url, path):
     try:
         file = self._session.get(url).content
         with open(path, 'wb') as f:
             f.write(file)
     except:
         preporter.info("Download file from jenkins {url} fail, please check your jenkins".format(url=url))
def validate_schema(response_body_schema, expected_schema):
    try:
        validate(response_body_schema, expected_schema)
        return True
    except ValidationError as e:
        preporter.info("Schema is not matched" + str(e))
        return False
Example #6
0
    def on_test_case_start(self, test_case):
        if self.is_dependent_test_case(test_case):
            if self.is_parent_test_passed(test_case):
                preporter.info(
                    "Parent test {} has passed. Starting execution of current test case."
                    .format(self.get_parent_test_case_name(test_case)))

            elif self.is_parent_test_failed(test_case):
                preporter.warn(
                    "Parent test {} has failed. Current test case will be skipped."
                    .format(self.get_parent_test_case_name(test_case)))
                self.add_skipped_test(test_case)
                fail("Skipping test case as parent test failed.")

            elif self.is_parent_test_skipped(test_case):
                preporter.warn(
                    "Parent test {} has been skipped. Current test case will be skipped."
                    .format(self.get_parent_test_case_name(test_case)))
                self.add_skipped_test(test_case)
                fail("Skipping test case as parent test has been skipped.")

            else:
                preporter.critical(
                    "Parent test {} has not been executed! Please check naming convention of test cases "
                    "and ensure parent test is executed first.".format(
                        self.get_parent_test_case_name(test_case)))
                self.add_skipped_test(test_case)
                fail(
                    "Skipping test case as parent test has NOT been executed yet."
                )
        else:
            preporter.info("Starting execution of current test case.")
Example #7
0
 def hover_over(self, locator, wait_until=None):
     preporter.info("Hovering over element: " + (str(locator)))
     wait_until = self._explicit_wait_time if wait_until is None else wait_until
     element = self.find_visible_element(locator, wait_until)
     self._driver.execute_script("return arguments[0].scrollIntoView();",
                                 element)
     hover_action = ActionChains(self.get_driver()).move_to_element(element)
     hover_action.perform()
Example #8
0
    def is_apk_exist(self, path):
        if os.path.isfile(path) and path.endswith('apk'):
            preporter.info("{file} exist".format(file=path))
            return True

        else:
            preporter.info("{file} does't exist".format(file=path))
            return False
def open_genemotion():
    device_name = '"Custom Phone - 5.0.0 - API 21 - 768x1280"'
    cmd = "open -a /Applications/Genymotion.app/Contents/MacOS/player.app --args --vm-name {}".format(device_name)
    try:
        start_process_by_command(cmd)
    except:
        preporter.info('emulator {} is not started'.format(device_name))
        raise
Example #10
0
 def tc_005_keyboard_shortcut_test(self):
     preporter.info("Opening URL: " + config.BASE_URL)
     self._driver.open_url(config.BASE_URL)
     self._home_page.navigate_to_help_tab()
     self._home_page.click_to_community_link()
     self._driver.switch_window()
     self._community_page.click_on_hamburger_menu()
     assert_true(self._community_page.is_keyboard_shortcuts_displayed(), "Keyboard shortcut button not displayed")
Example #11
0
def run_command_on_shell(command_string):
    try:
        process = start_process_by_command(command_string)
        out, error = process.communicate()
        return out.decode().splitlines()
    except:
        print("Command Error")
        preporter.info('error occur for command {}'.format(command_string))
        raise
Example #12
0
 def download_file(self, url, path):
     try:
         file = requests.get(url, auth=('shirley.licp', '1')).content
         with open(path, 'wb') as f:
             f.write(file)
     except:
         preporter.info(
             "Download file from jenkins {url} fail, please check your jenkins"
             .format(url=url))
Example #13
0
 def send_keys(self, locator, text, wait_until=None):
     preporter.info("Sending text '" + str(text) + "' to element: " +
                    (str(locator)))
     wait_until = self._explicit_wait_time if wait_until is None else wait_until
     element = self.find_clickable_element(locator, wait_until)
     self._driver.execute_script("return arguments[0].scrollIntoView();",
                                 element)
     element.click()
     element.clear()
     element.send_keys(text)
 def unfollow_item(self, item):
     """
     This method searches for a given content and removes it from the following list. It also navigates back to the
     following page by pressing back twice. This method expects that the content provided is in followed state.
     :param item: Content to be un-followed
     :return:
     """
     preporter.info("Unfollowing {}".format(item))
     self.search_item_and_click_on_star(item)
     self.driver.back()
     self.driver.back()
Example #15
0
    def download_build(self, apk_local_path, apk_name=None, debug=True):
        apk_url, apk_name_from_jenkins = self.get_build_url(debug)
        self.check_folder(apk_local_path)
        file_local_abs_path = os.path.join(apk_local_path, apk_name if apk_name else apk_name_from_jenkins)
        self.download_file(apk_url, file_local_abs_path)

        if self.is_apk_exist(file_local_abs_path):
            preporter.info("Download file {file} success!".format(file=file_local_abs_path))

        else:
            preporter.info("Download file {file} fail!".format(file=file_local_abs_path))
Example #16
0
def get_new_chrome_driver():
    preporter.info("Spawning driver: Chrome")
    chrome_options = webdriver.ChromeOptions()
    chrome_options.add_argument(
        "--disable-infobars")  # To remove automation info bar.
    driver = webdriver.Chrome(ChromeDriverManager().install(),
                              chrome_options=chrome_options)
    driver.delete_all_cookies()
    driver.fullscreen_window()

    return driver
 def navigate_to_following_page(self):
     """
     This method navigates user to the following page by clicking on following icon in navigation bar in bottom
     :return:
     """
     time.sleep(
         1)  # Added time sleep as following button do not have unique id
     preporter.info("Navigating to following page")
     following_button_element = self.driver.find_element_visible(
         self.following_nav_button, wait_until=10)
     self.tap(following_button_element)
Example #18
0
def is_appium_running():
    try:
        statu_url = "0.0.0.0:4723/wd/hub/status"
        response = requests.get(statu_url)

        if response.status_code == 200:
            return True
        else:
            return False
    except Exception as e:
        preporter.info("check staus on appium fail")
        return False
Example #19
0
    def download_build(self):
        apk_url, apk_name = self.get_build_url()
        self.check_folder(self.apk_path)
        self.download_file(apk_url, self.apk_path + "/" + apk_name)

        if self.is_apk_exist(self.apk_path + "/" + apk_name):
            preporter.info("Download file {file} success!".format(
                file=self.apk_path + "/" + apk_name))

        else:
            preporter.info("Download file {file} fail!".format(
                file=self.apk_path + "/" + apk_name))
Example #20
0
 def click(self, locator, wait_until=None):
     """
         This click method will click on the element after the element is visible and available for click,
         in the case when execution is really fast and the click has failed it will wait for two seconds and
         try to click it again. Most of the times the first click will work. In rare scenarios the second
         click will come into the picture when the explicit wait is very less .
     """
     preporter.info("Clicking element: " + (str(locator)))
     wait_until = self._explicit_wait_time if wait_until is None else wait_until
     self.find_visible_element(locator,
                               wait_until)  # Ignoring the returned element
     element = self.find_clickable_element(locator, wait_until)
     self.click_element(element)
Example #21
0
 def tc_003_available_countries_test(self):
     preporter.info("Opening URL: " + config.BASE_URL)
     self._driver.open_url(config.BASE_URL)
     try:
         self._home_page.click_on_current_selected_country()
         assert_list_elements_equal(self._home_page.get_all_countries_name(), available_countries,
                                    "All country flags did't matched")
     except (TimeoutException, WebDriverException):
         self._home_page.click_on_hiring_banner()  # TODO Find a better method to handle the banner
         self._home_page.click_on_homepage()
         self._home_page.click_on_current_selected_country()
         assert_list_elements_equal(self._home_page.get_all_countries_name(), available_countries,
                                    "All country flags did't matched")
def is_device_running(retry_times=MAX_TIMES, interval=WAIT_TIME):
    i = 0

    while i < retry_times:
        time.sleep(interval)
        device_info = run_command_on_shell('adb devices')

        if len(device_info) > 1:
            for line in device_info:
                preporter.info(line)
            return True

        i += 1

    return False
Example #23
0
 def tc_002_topic_search_perfect_match_test(self, announcement):
     preporter.info("Opening URL: " + config.BASE_URL)
     self._driver.open_url(config.BASE_URL)
     self._home_page.navigate_to_help_tab()
     self._home_page.click_to_community_link()
     self._driver.switch_window()
     preporter.info("Searching for " + announcement)
     self._community_page.search_text(announcement)
     try:
         assert_equals(self._community_page.get_first_order_search_results_titles()[0], announcement,
                       "Item is not in top of search results")
         self._driver.close_tab()
     except AssertionError:
         self._driver.close_tab()
         fail("Item is not in top of search results")
Example #24
0
 def tc_001_topic_title_test(self, topic):
     preporter.info("Opening URL: " + config.BASE_URL)
     self._driver.open_url(config.BASE_URL)
     self._home_page.navigate_to_help_tab()
     self._home_page.click_to_community_link()
     self._driver.switch_window()
     preporter.info("Searching for " + topic)
     self._community_page.search_text(topic)
     self._community_page.find_and_click_topic_from_search_results(topic)
     try:
         assert_equals(self._community_page.get_topic_title(), topic, "Expected topic title not proper")
         self._driver.close_tab()
     except AssertionError:
         self._driver.close_tab()
         fail("Expected topic title not proper")
 def follow_item(self, item):
     """
     This method searches for a given content and adds it to the following list. It also navigates back to the
     following page by pressing back twice. This method expects that the content provided is not in followed state.
     :param item: Content to be followed
     :return:
     """
     preporter.info("Following {}".format(item))
     search_result_type = self.search_item_and_click_on_star(item)
     if "Competitions" not in search_result_type:
         done_element = self.driver.find_element_visible(
             self.push_notification_done_button, wait_until=10)
         self.tap(done_element)
     self.driver.back()
     self.driver.back()
Example #26
0
def has_device_running(retry_times=MAX_RETRY_TIMES):
    # TODO: adb devices is not solid solution to determine device is ready for running automation, will figure out another approach to do this check
    i = 0

    while i < retry_times:
        time.sleep(interval)
        device_info = run_command_on_shell('adb devices')

        if len(device_info) > 1:
            for line in device_info:
                preporter.info(line)
            return True

        i += 1

    return False
def open_new_genymotion(device_name, timeout=MAX_TIMES * WAIT_TIME):
    """
    setup device with device id or name using genymotion
    :param device_identity:
    :return:
    """
    close_android_emulator()
    open_genemotion()
    start_time = datetime.now()
    time.sleep(timeout)

    if (not is_device_running()):
        elapsed = datetime.now() - start_time
        raise Exception(
            "Emulator is not started successfully within {}, please check environment manually".format(elapsed))
    else:
        preporter.info("Emulator started successfully")
Example #28
0
 def exec_test(self, assertion=None):
     self.returned_data = []
     if self.method.lower() == 'get':
         for url in self.url_list_for_method_get:
             preporter.info('\n\n正在请求: ' + url + '\n\n')
             self.returned_data.append(
                 httptools.request(url=url,
                                   method=self.method,
                                   session=self.session,
                                   headers=self.headers,
                                   assertion=assertion))
     else:
         if len(self.pre_send_params_list) > 0:
             for pre_send_params in self.pre_send_params_list:
                 preporter.info('\n\n正在请求: ' + self.url + '\n\n' +
                                '当前请求参数: ' + str(pre_send_params) + '\n\n')
                 self.returned_data.append(
                     httptools.request(url=self.url,
                                       method=self.method,
                                       json_data=pre_send_params,
                                       session=self.session,
                                       headers=self.headers,
                                       assertion=assertion))
         else:
             preporter.info('\n\n正在请求: ' + self.url + '\n\n')
             self.returned_data.append(
                 httptools.request(url=self.url,
                                   method=self.method,
                                   session=self.session,
                                   headers=self.headers,
                                   assertion=assertion))
Example #29
0
    def tc_004_available_countries_url_test(self, country):
        preporter.info("Opening URL: " + config.BASE_URL)
        self._driver.open_url(config.BASE_URL)
        try:
            self._home_page.click_on_current_selected_country()
            self._home_page.search_in_available_countries(country)
            self._home_page.click_on_first_search_item()
            preporter.info("Searching for country: " + country)
            preporter.info("Matching with URL: " + self._driver.get_url())
            assert_equals(self._driver.get_url(), countries_to_url_map[country],
                          "URL did't match with country code: " + country)
        except (TimeoutException, WebDriverException):

            self._home_page.click_on_hiring_banner()  # TODO Find a better method to handle the banner
            self._home_page.click_on_homepage()
            self._home_page.click_on_current_selected_country()
            self._home_page.search_in_available_countries(country)
            self._home_page.click_on_first_search_item()
            preporter.info("Searching for country: " + country)
            preporter.info("Matching with URL: " + self._driver.get_url())
            assert_equals(self._driver.get_url(), countries_to_url_map[country],
                          "URL did't match with country code: " + country)
Example #30
0
def remove_android_app(package_name):
    preporter.info('remove app {} on emulator'.format(package_name))
    package = run_command_on_shell(
        "adb shell pm list packages | grep {}".format(package_name))
    if not package:
        preporter.info(
            'package {} is not installed on emulator'.format(package_name))
        return
    run_command_on_shell('adb uninstall {}'.format(package_name))
    preporter.info(
        'android app {} is removed from emulator'.format(package_name))
Example #31
0
 def before_suite(self):
     preporter.info("before suite")
Example #32
0
 def after_suite(self):
     preporter.info("after suite")
Example #33
0
 def after_class(self):
     preporter.info("after class")
Example #34
0
 def after_group(self):
     preporter.info("after group")
Example #35
0
 def after(self):
     preporter.info("cleaning up")
Example #36
0
 def before(self):
     preporter.info("setting expected result.")
     self.expected = 10
Example #37
0
 def before_group(self):
     preporter.info("before group")
Example #38
0
 def before(self):
     preporter.info("Test is about to start.")
     self.browser = SeleniumHelper.open_browser("chrome")
Example #39
0
 def before_class(self):
     preporter.info("before class")
Example #40
0
 def after(self):
     preporter.info("cleaning up")
     self.browser.delete_all_cookies()
     self.browser.quit()