コード例 #1
0
class DashBoard(BasePage):

    log = cl.customLogger(logging.DEBUG)

    def __init__(self, driver):
        super().__init__(driver)
        self.driver = driver

    # User Account Locators -------------------------------------

    useraccount_menulink = "userAcctTab_MainMenu"
    my_account_submenu = "//li[@id='dd-my-account']/ul/li/a[contains(text(),'My Account')]"
    library_submenu = "//li[@id='dd-my-account']/ul/li[2]/a[contains(text(),'Library')]"
    contact_submenu = "//li[@id='dd-my-account']/ul/li[3]/a[contains(text(),'Contacts')]"
    signout_submenu = "//div[@class='content-wrapper']//ul[@class='nav-submenu']//li[5]"

    # Survey List-------------------------------------------------

    survey_list = "//div[@class='dw-container survey-list']"
    first_survey = "//ul[@class='survey-items-list']/li[1]"
    edit_options = "//*[@id='row_3']/div/div/div[2]/ul/li[1]/div/ul[2]/div[1]/li[1]/div[2]/a/div[2]"

    # Validate ---------------------------------------

    login_link = "//li/a[contains(text(),'LOG IN')]"

    # Clicker Methods ----------------------------------

    def click_useraccount_menu(self):
        self.element_click(self.useraccount_menulink)

    def click_myaccount_submenu(self):
        self.element_click(self.my_account_submenu, "xpath")

    def click_libraryv_submenu(self):
        self.element_click(self.library_submenu, "xpath")

    def click_contact_submenu(self):
        self.element_click(self.contact_submenu, "xpath")

    def click_signout_submenu(self):
        self.element_click(self.signout_submenu, "xpath")

    def click_edit_option(self):
        self.element_click(self.edit_options, "xpath")

    # Move to Method ----------------------------------

    def move_to_firstsurvey(self):
        self.hover_on_element(self.first_survey, "xpath")

    # Actions Method ----------------------------------

    def signout_account(self):
        self.click_useraccount_menu()
        self.click_signout_submenu()

    def verify_signout(self):
        result = self.is_elementpresent(self.login_link, "xpath")
        return result
コード例 #2
0
class SignUpPage(BasePage):
    log = cl.customLogger(logging.DEBUG)

    def __init__(self, driver):
        super().__init__(driver)
        self.driver = driver

    #  Locators
    signup_link = "//a[contains(text(),'SIGN UP')]"
    user_name = "username"
    user_password = "******"
    user_email = "email"
    user_firstname = "first_name"
    user_lastname = "last_name"
    createaccount_button = "//button[contains(text(),'CREATE ACCOUNT')]"

    # Clicker Methods ----------------------------------
    def click_signup_link(self):
        self.element_click(self.signup_link, "xpath")

    def click_createaccount(self):
        self.element_click(self.createaccount_button, "xpath")

    # Setter Mehods ----------------------------------
    def set_username(self, username):
        self.set_send_keys(username, self.user_name)

    def set_userpassword(self, password):
        self.set_send_keys(password, self.user_password)

    def set_useremail(self, email):
        self.set_send_keys(email, self.user_email)

    def set_userfirst_name(self, fname):
        self.set_send_keys(fname, self.user_firstname)

    def set_userlast_name(self, lname):
        self.set_send_keys(lname, self.user_lastname)

    # Actions Method ----------------------------------
    def user_signup(self, username, password, email, fname, lname):
        self.click_signup_link()
        self.set_username(username)
        self.set_userpassword(password)
        self.set_useremail(email)
        self.set_userfirst_name(fname)
        self.set_userlast_name(lname)
        self.click_createaccount()
コード例 #3
0
class WebDriver:

    log = cl.customLogger(logging.DEBUG)

    def __init__(self, driver):
        self.driver = driver

    def get_bytype(self, locator_type):
        locatortype = locator_type.lower()
        if locatortype == "id":
            return By.ID
        elif locatortype == "name":
            return By.NAME
        elif locatortype == "xpath":
            return By.XPATH
        elif locatortype == "css":
            return By.CSS_SELECTOR
        elif locatortype == "classname":
            return By.CLASS_NAME
        elif locatortype == "linktext":
            return By.LINK_TEXT
        else:
            self.log.info("Locator type " + locatortype +
                          " not correct/supported")
        return False

    def get_element(self, locator, locator_type="id"):
        element = None
        try:
            locatortype = locator_type.lower()
            by_type = self.get_bytype(locatortype)
            element = self.driver.find_element(by_type, locator)
            self.log.info("Element Found")
        except:
            self.log.info("Element not found")
        return element

    def element_click(self, locator, locator_type="id"):
        try:
            element = self.wait_until_element_to_be_clickable(
                locator, locator_type)
            element.click()
            self.log.info("Clicked on element with locator: " + locator +
                          " locatorType: " + locator_type)
        except:
            self.log.info("Cannot click on the element with locator: " +
                          locator + " locatorType: " + locator_type)
            print_stack()

    def set_send_keys(self, data, locator, locator_type="id"):
        try:
            element = self.wait_until_element_located(locator, locator_type)
            # element = self.get_element(locator, locator_type)
            element.clear()
            element.send_keys(data)
            self.log.info("Send data on element with locator: " + locator +
                          " locatorType: " + locator_type)
        except:
            self.log.info("Cannot send data on the element with locator: " +
                          locator + " locatorType: " + locator_type)

    def get_title(self):
        return self.driver.title

    def is_elementpresent(self, locator, locator_type="id"):
        try:
            element = self.get_element(locator, locator_type)
            if element is not None:
                self.log.info("Element is present with locator: " + locator +
                              " locatorType: " + locator_type)
                return True
            else:
                self.log.info("Element is not present with locator: " +
                              locator + " locatorType: " + locator_type)
                return False
        except:
            self.log.info("Element not found")
            return False

    def is_elements_presence_check(self, locator, locator_type="id"):
        try:
            element_list = self.get_element(locator_type, locator)
            if len(element_list) > 0:
                self.log.info("Elements are present with locator: " + locator +
                              " locatorType: " + locator_type)
                return True
            else:
                self.log.info("Elements are not present with locator: " +
                              locator + " locatorType: " + locator_type)
                return False
        except:
            return False

    def get_current_url(self):
        url = self.driver.current_url
        return url

    def get_text(self, locator, locator_type='id'):
        try:
            element = self.get_element(locator, locator_type)
            msg = element.text()
            msg = str(msg)
            self.log.info("Element is present with locator: " + locator +
                          " locatorType: " + locator_type)
            return msg
        except:
            self.log.info("Element is not present with locator: " + locator +
                          " locatorType: " + locator_type)

    def wait_until_element_to_be_clickable(self, locator, locator_type='id'):
        try:
            wait = WebDriverWait(self.driver, 30, poll_frequency=0.5)
            element = wait.until(
                EC.element_to_be_clickable((locator_type, locator)))
            self.log.info("Element is present with locator: " + locator +
                          " locatorType: " + locator_type)
            return element
        except:
            self.log.info("Element is not present with locator: " + locator +
                          " locatorType: " + locator_type)

    def wait_until_element_located(self, locator, locator_type='id'):
        try:
            wait = WebDriverWait(self.driver, 30, poll_frequency=0.5)
            element = wait.until(
                EC.presence_of_element_located((locator_type, locator)))
            self.log.info("Element is present with locator: " + locator +
                          " locatorType: " + locator_type)
            return element
        except:
            self.log.info("Element is not present with locator: " + locator +
                          " locatorType: " + locator_type)

    def set_dropdown_value(self, input_data, locator, locator_type='id'):
        try:
            ac = ActionChains(self.driver)
            ac.click(self.get_element(locator, locator_type)).send_keys(
                input_data, Keys.RETURN).perform()
            self.log.info("Element is present with locator: " + locator +
                          " locatorType: " + locator_type)
        except:
            self.log.info("Element is not present with locator: " + locator +
                          " locatorType: " + locator_type)

    def select_value_by_index(self, index_number, locator, locator_type='id'):
        try:
            element = Select(self.get_element(locator, locator_type))
            element.select_by_index(index_number)
            self.log.info("Element is present with locator: " + locator +
                          " locatorType: " + locator_type)
        except:
            self.log.info("Element is not present with locator: " + locator +
                          " locatorType: " + locator_type)

    def select_by_value(self, value_name, locator, locator_type='id'):
        try:
            element = Select(self.get_element(locator, locator_type))
            element.select_by_value(value_name)
            self.log.info("Element is present with locator: " + locator +
                          " locatorType: " + locator_type)
        except:
            self.log.info("Element is not present with locator: " + locator +
                          " locatorType: " + locator_type)

    def select_by_visible_text(self, visible_text, locator, locator_type='id'):
        try:
            element = Select(
                self.wait_until_element_located(locator, locator_type))
            element.select_by_visible_text(visible_text)
            self.log.info("Element is present with locator: " + locator +
                          " locatorType: " + locator_type)
        except:
            self.log.info("Element is not present with locator: " + locator +
                          " locatorType: " + locator_type)

    def set_inputvalue_by_action(self, input_data, locator, locator_type='id'):
        try:
            ac = ActionChains(self.driver)
            ac.move_to_element(
                self.wait_until_element_located(
                    locator, locator_type)).send_keys(input_data)
            self.log.info("Element is present with locator: " + locator +
                          " locatorType: " + locator_type)
        except:
            self.log.info("Element is not present with locator: " + locator +
                          " locatorType: " + locator_type)

    def hover_on_element(self, locator, locator_type='id'):
        try:
            ac = ActionChains(self.driver)
            ac.move_to_element(
                self.wait_until_element_located(locator,
                                                locator_type)).perform()
            self.log.info("Element is present with locator: " + locator +
                          " locatorType: " + locator_type)
        except:
            self.log.info("Element is not present with locator: " + locator +
                          " locatorType: " + locator_type)

    def set_multi_options(self, input_data, locator, locator_type='id'):
        try:
            ac = ActionChains(self.driver)
            ac.click(self.get_element(locator, locator_type)).send_keys(
                input_data, Keys.TAB).perform()
            self.log.info("Element is present with locator: " + locator +
                          " locatorType: " + locator_type)
        except:
            self.log.info("Element is present with locator: " + locator +
                          " locatorType: " + locator_type)
コード例 #4
0
class SurveyDesignPage(BasePage):

    log = cl.customLogger(logging.DEBUG)

    def __init__(self, driver):
        super().__init__(driver)
        self.driver = driver

    #  Locators ------------------------------------

    logo_btn = "//span[@class = 'add-logo-btn wds-button" \
               " wds-button--sm wds-button--icon-left wds-button--ghost-filled']"
    from_pc = "//a[@tab-target='from-computer']"
    from_lib = "//a[@tab-target='from-library']"
    import_link = "//span[@class = 'qq-upload-button-selector browse-for-file import-link']"
    ques_bank = "//li[@title='Question Bank']"
    builder = "//li[@title='Builder']"
    themes = "//li[@title='Themes']"
    logic = "//li[@title='Logic']"
    options = "//li[@title='Options']"
    title_container = "//div[@class = 'survey-title-table-wrapper']"

    # Edit Survey Title ----------------------------

    e_survey_title = "surveyTitle"
    e_survey_category = "surveyCategory"
    e_survey_save = "//form[@id='surveyTitleForm']/div" \
                    "/a[@class='wds-button wds-button--sm save']"
    e_survey_cancel = "//form[@id='surveyTitleForm']/div" \
                      "/a[@class='wds-button wds-button--sm wds-button--ghost-filled cancel']"

    # Add Question Locators ------------------------

    question = "//div[@class='rte sm-input sm-input--stretch" \
               " mce-content-body mce-edit-focus']"
    change_fieldtype = "changeQType"
    single_text = "//a[@data-action='SingleTextboxQuestion']"
    multiple_choice = "//a[@data-action='MultipleChoiceQuestion']"
    checkbox = "//a[@data-action='CheckboxQuestion']"
    matrix = "//a[@data-action='MatrixQuestion']"
    matrix_filed = "//div[@class='rteToolbarContainer empty']" \
                   "/div[@data-rte='answer' and contains(@id,'newChoice')]"
    matrix_column = "//div[@class='rteToolbarContainer empty']/div[@data-rte=" \
                    "'column' and contains(@id,'newChoice')]"
    comment_box = "//a[@data-action='CommentBoxQuestion']"
    date_time = "//a[@data-action='DateTimeQuestion']"
    dropdown = "//a[@data-action='DropdownQuestion']"
    dropdown_select_type = "//div[@id='editQuestionContent']//select" \
                           "[@id='answerBankCategorySelect']"
    option_input_field = "//div[@class='rteToolbarContainer empty']/div[contains" \
                         "(@id,'newChoice')]"
    star_rating = "//a[@data-action='StarRatingQuestion']"
    multiple_textbox = "//a[@data-action='MultipleTextboxQuestion']"
    add_next_question = "//*[@id='editQuestion']/section[2]/div[3]/div/div/a[1]"
    add_next_question_mwindow = "//div[@id='editQuestionContent']/following-sibling" \
                                "::div/div/div/a[contains(text(),'NEXT QUESTION')]"
    preview_survey = "previewSurvey"
    send_survey = "sendSurvey"

    # Clicker Methods ---------------------------------

    def click_on_title_container(self):
        self.element_click(self.title_container, "xpath")

    def click_on_save_edit_survey_btn(self):
        self.element_click(self.e_survey_save, "xpath")

    def click_on_cancle_edit_survey_btn(self):
        self.element_click(self.e_survey_cancel, "xpath")

    def click_change_fieldtype(self):
        self.element_click(self.change_fieldtype)

    def click_single_text_opt(self):
        self.element_click(self.single_text, "xpath")

    def click_date_opt(self):
        self.element_click(self.date_time, "xpath")

    def click_multiple_choice_opt(self):
        self.element_click(self.multiple_choice, "xpath")

    def click_checkbox_opt(self):
        self.element_click(self.checkbox, "xpath")

    def click_matrix_opt(self):
        self.element_click(self.matrix, "xpath")

    def click_comment_box_opt(self):
        self.element_click(self.comment_box, "xpath")

    def click_dropdown_opt(self):
        self.element_click(self.dropdown, "xpath")

    def click_star_rating_opt(self):
        self.element_click(self.star_rating, "xpath")

    def click_add_new_question(self):
        self.element_click(self.add_next_question, "xpath")

    def click_add_new_question_in_detail(self):
        self.element_click(self.add_next_question_mwindow, "xpath")

    def click_multi_textboxe(self):
        self.element_click(self.multiple_textbox, "xpath")

    def click_next_preview_survey(self):
        self.element_click(self.preview_survey)

    # Setter Mehods ----------------------------------

    def set_esurvey_title(self, title):
        self.set_send_keys(title, self.e_survey_title)

    def set_ecategory(self, visible_text):
        self.select_by_visible_text(visible_text, self.e_survey_category)

    def set_question(self, question):
        self.set_send_keys(question, self.question, "xpath")

    def set_dropdown_field_value(self, value):
        self.set_multi_options(value, self.option_input_field, "xpath")

    def set_value_in_dropdown(self, visible_text):
        self.select_by_visible_text(visible_text, self.dropdown_select_type,
                                    "xpath")

    def set_checkboxes_field_value(self, value):
        self.set_multi_options(value, self.option_input_field, "xpath")

    def set_matrix_field_value(self, value):
        self.set_multi_options(value, self.matrix_filed, "xpath")

    def set_matrix_column_value(self, value):
        self.set_multi_options(value, self.matrix_column, "xpath")

    def set_multi_line_label(self, label):
        self.set_multi_options(label, self.option_input_field, "xpath")

    # Actions ----------------------------------------------

    def edit_survey_title(self, survey_title):
        self.click_on_title_container()
        self.set_esurvey_title(survey_title)
        self.click_on_save_edit_survey_btn()

    def edit_survey_category(self, survey_category):
        self.click_on_title_container()
        self.set_ecategory(survey_category)
        self.click_on_save_edit_survey_btn()

    def add_field_type(self, field_type="text_box"):
        self.click_change_fieldtype()
        if field_type == "text_box":
            self.click_single_text_opt()
        elif field_type == "drop_down":
            self.click_dropdown_opt()
        elif field_type == "date":
            self.click_date_opt()
        elif field_type == "star_rating":
            self.click_star_rating_opt()
        elif field_type == "drop_down_select":
            self.click_dropdown_opt()
        elif field_type == "checkboxes":
            self.click_checkbox_opt()
        elif field_type == "matrix_rating":
            self.click_matrix_opt()
        elif field_type == "multi_textbox":
            self.click_multi_textboxe()
        elif field_type == "radio":
            self.click_multiple_choice_opt()
        elif field_type == "text_area":
            self.click_comment_box_opt()
        else:
            print("invalid Field type : " + field_type)

    def add_question_with_single_text_option(self, question_title):
        self.add_field_type("text_box")
        # self.click_add_new_question()
        self.set_question(question_title)
        self.click_add_new_question_in_detail()

    def add_question_with_dropdown_option(self, question_title, *args):
        self.set_question(question_title)
        self.add_field_type("drop_down")
        for arg in args:
            self.set_dropdown_field_value(arg)
        self.click_add_new_question_in_detail()

    def add_question_with_date_option(self, question_title):
        self.set_question(question_title)
        self.add_field_type("date")
        self.click_add_new_question_in_detail()

    def add_question_with_rating_option(self, question_title):
        self.set_question(question_title)
        self.add_field_type("star_rating")
        self.click_add_new_question_in_detail()

    def add_question_with_drop_by_selected_vale_option(self, question_title,
                                                       visible_text):
        self.set_question(question_title)
        self.add_field_type("drop_down_select")
        self.set_value_in_dropdown(visible_text)
        self.click_add_new_question_in_detail()

    def add_question_with_checkboxes_option(self, question_title, *args):
        self.set_question(question_title)
        self.add_field_type("checkboxes")
        for arg in args:
            self.set_checkboxes_field_value(arg)
        self.click_add_new_question_in_detail()

    def add_question_with_matrix_rating_option(self, question_title, value1,
                                               value2, value3, *column):
        self.set_question(question_title)
        self.add_field_type("matrix_rating")
        self.set_matrix_field_value(value1)
        self.set_matrix_field_value(value2)
        self.set_matrix_field_value(value3)
        for col in column:
            self.set_matrix_column_value(col)
        self.click_add_new_question_in_detail()

    def add_question_with_multi_textbox_option(self, question_title, *label):
        self.set_question(question_title)
        self.add_field_type("multi_textbox")
        for lab in label:
            self.set_multi_line_label(lab)
        self.click_add_new_question_in_detail()

    def add_question_with_radio_option(self, question_title, visible_text):
        self.set_question(question_title)
        self.add_field_type("radio")
        self.set_value_in_dropdown(visible_text)
        self.click_add_new_question_in_detail()

    def add_question_with_text_area_option(self, question_title):
        self.set_question(question_title)
        self.add_field_type("text_area")
        self.click_add_new_question_in_detail()

    def previewsurvey(self):
        self.click_next_preview_survey()
コード例 #5
0
class LoginPage(BasePage):
    log = cl.customLogger(logging.DEBUG)

    def __init__(self, driver):
        super().__init__(driver)
        self.driver = driver

    #  Locators -------------------------------------
    login_link = "//li/a[contains(text(),'LOG IN')]"
    user_name = "username"
    user_password = "******"
    login_button = "//button[contains(text(),'LOG IN')]"
    home_page = "svg_logo"

    # Validate ---------------------------------------
    useraccount_menulink = "userAcctTab_MainMenu"
    invalid_user_error_ele = "//div[@class='error-message']/ul/li[1]"
    blank_username_error_ele = "//input[@id='username']/following-sibling::div"
    blank_password_error_ele = "//input[@id='password']/following-sibling::div"

    # Clicker Methods ----------------------------------

    def click_loginlink(self):
        self.element_click(self.login_link, "xpath")

    def click_loginbutton(self):
        self.element_click(self.login_button, "xpath")

    # Setter Mehods ----------------------------------

    def set_username(self, username):
        self.set_send_keys(username, self.user_name)

    def set_userpassword(self, password):
        self.set_send_keys(password, self.user_password)

    # Actions Method ----------------------------------

    def user_login(self, username, password):
        self.click_loginlink()
        self.set_username(username)
        self.set_userpassword(password)
        self.click_loginbutton()

    def verify_login(self):
        result = self.is_elementpresent(self.useraccount_menulink)
        return result

    def verify_loginfail_error(self):
        result = self.is_elementpresent(self.invalid_user_error_ele, 'xpath')
        return result

    def verify_username_error(self):
        result = self.is_elementpresent(self.blank_username_error_ele, 'xpath')
        return result

    def verify_password_error(self):
        result = self.is_elementpresent(self.blank_password_error_ele, 'xpath')
        return result

    def get_url(self):
        url = self.get_current_url()
        return url

    def click_on_url(self, url):
        self.driver.get(url)

    def verify_password_error_msg(self):
        msg = self.get_text(self.blank_password_error_ele, 'xpath')
        return msg

    def verify_username_error_msg(self):
        msg = self.get_text(self.blank_username_error_ele, "xpath")
        msg = str(msg)
        return msg
コード例 #6
0
class CreateSurveyPage(BasePage):
    log = cl.customLogger(logging.DEBUG)

    def __init__(self, driver):
        super().__init__(driver)
        self.driver = driver

    #  Locators ------------------------------------
    move_to_survey_page_btn = "//a[@class='create-survey alt btn SL_split']"
    survey_title = "surveyTitle"
    survey_category = "//div[contains(text(),'Survey category')]"
    create_survey_btn = "//button[contains(text(),'CREATE SURVEY')]"
    create_from_scratch = 'scratch'
    mwindow_close = "//div[@class = 'modal-view scratch-modal-view']"
    mwindow_survey_title = "//div/input[@id='surveyTitle']"
    mwindow_survey_category = "//span/div[contains(text(),'Survey category')]"
    mwindow_create_survey_btn = "//div/button[contains(text(),'CREATE SURVEY')]"

    # Clicker Methods ----------------------------------

    def click_move_to_survey_page_btn(self):
        self.element_click(self.move_to_survey_page_btn, "xpath")

    def click_create_from_scratch(self):
        self.element_click(self.create_from_scratch)

    def click_create_survey_btn(self):
        self.element_click(self.create_survey_btn, "xpath")

    def click_create_survey_window_close(self):
        self.element_click(self.mwindow_close, "xpath")

    def click_mwindow_create_survey_btn(self):
        self.element_click(self.mwindow_create_survey_btn, "xpath")

    # Setter Mehods ----------------------------------

    def set_survey_title(self, surveytitle):
        self.set_send_keys(surveytitle, self.survey_title)

    def set_survey_category(self, surveycategory):
        self.set_dropdown_value(surveycategory, self.survey_category, "xpath")

    def set_mwindow_survey_title(self, mw_survey_title):
        self.set_send_keys(mw_survey_title, self.mwindow_survey_title, "xpath")

    def set_mwindow_survey_category(self, mw_survey_category):
        self.set_dropdown_value(mw_survey_category,
                                self.mwindow_survey_category, "xpath")

    # Actions Method ----------------------------------

    def create_survey(self, survey_title, survey_category):
        self.click_move_to_survey_page_btn()
        result = self.is_elementpresent(self.create_from_scratch)
        if result == True:
            self.click_create_from_scratch()
            self.wait_until_element_to_be_clickable(self.mwindow_survey_title,
                                                    "xpath")
            self.set_mwindow_survey_title(survey_title)
            self.wait_until_element_to_be_clickable(
                self.mwindow_survey_category, "xpath")
            self.set_mwindow_survey_category(survey_category)
            self.click_mwindow_create_survey_btn()
        else:
            self.click_move_to_survey_page_btn()
            self.wait_until_element_to_be_clickable(self.survey_title)
            self.set_survey_title(survey_title)
            self.wait_until_element_to_be_clickable(self.survey_category,
                                                    "xpath")
            self.set_survey_category(survey_category)
            self.click_mwindow_create_survey_btn()