class Public_Texts_Docs:
    def __init__(self, driver):

        self.chrome = driver
        self.driver_func = Driver_Action(driver)
        self.admin_xpath_list_func = Admin_Menu_Path()
        self.basic_func = Basic()
        # 管理画面のメニューのパスを返す
        self.admin_xpath_lists_xpath = self.admin_xpath_list_func.get_admin_menu_xpath(
        )

        # 管理画面メニュー内の新規追加や編集などのパーツのパスを返す。
        self.admin_list_parts_xpath = self.admin_xpath_list_func.get_admin_menu_list_parts_xpath(
        )

        # 管理画面内の項目に関するパス(作成した固定ページリストとか)
        self.admin_parts_xpath = self.admin_xpath_list_func.get_admin_parts()

        #ユーザー画面内の項目に関するパス
        self.public_parts_xpath = self.admin_xpath_list_func.get_public_parts()

        self.base_dir = self.basic_func.get_base_dir_path()

    def go_to_texts_list_page(self):
        self.driver_func.go_to_public_nav_menu('教材一覧ページ')

    def check_texts_docs_page(self):
        self.driver_func.scroll_down(self.chrome)

        text_xpath = '//div[@class="col-xs-12 col-md-12"]/div[@class="dwd_background mb24"][11]/a'

        text_elem = self.driver_func.get_element_by_xpath(text_xpath)
        self.driver_func.click_item(text_elem)

        self.driver_func.stop(3)
class Public_Edit_User:

    def __init__(self, driver):

        self.chrome = driver
        self.driver_func = Driver_Action( driver )
        self.admin_xpath_list_func = Admin_Menu_Path()
        self.basic_func = Basic()
        # 管理画面のメニューのパスを返す
        self.admin_xpath_lists_xpath = self.admin_xpath_list_func.get_admin_menu_xpath()

        # 管理画面メニュー内の新規追加や編集などのパーツのパスを返す。
        self.admin_list_parts_xpath = self.admin_xpath_list_func.get_admin_menu_list_parts_xpath()

        # 管理画面内の項目に関するパス(作成した固定ページリストとか)
        self.admin_parts_xpath = self.admin_xpath_list_func.get_admin_parts()

        #ユーザー画面内の項目に関するパス
        self.public_parts_xpath = self.admin_xpath_list_func.get_public_parts()

        self.base_dir = self.basic_func.get_base_dir_path()

        self.my_page_url = self.basic_func.get_my_page_url()

    def go_to_my_page( self ):
        self.chrome.get( self.my_page_url )

    def go_to_edit_page( self ):
        edit_btn_xpath = self.public_parts_xpath['edit_btn_xpath']
        edit_btn_elem = self.driver_func.get_element_by_xpath( edit_btn_xpath )
        self.driver_func.click_item( edit_btn_elem )

    def edit_user_info( self ):

        first_name_elem = self.driver_func.get_element_by_name( 'first_name' )
        last_name_elem = self.driver_func.get_element_by_name( 'last_name' )
        user_email_elem = self.driver_func.get_element_by_name( 'user_email' )
        submit_elem = self.driver_func.get_element_by_id( 'submit' )
        
        self.driver_func.clear_item_info( first_name_elem )
        self.driver_func.put_item_info( first_name_elem, 'edit_first_name_test' )

        self.driver_func.clear_item_info( last_name_elem )
        self.driver_func.put_item_info( last_name_elem, 'edit_last_name_test' )

        self.driver_func.click_item( submit_elem )
class Test_User_Normal_Register:

    def __init__(self, driver):
        self.chrome = driver
        self.driver_func = Driver_Action( driver )

    #普通に登録
    def nomarl_put_user_info_to_form( self ):


        dt_now = datetime.datetime.now()

        register_btn_path = '//input[@class="btn_design"][@value = "登録"]'

        last_name_input = self.driver_func.get_element_by_name('last_name')
        self.driver_func.clear_item_info( last_name_input )
        self.driver_func.put_item_info( last_name_input, 'test' )

        first_name_input = self.driver_func.get_element_by_name('first_name')
        self.driver_func.clear_item_info( first_name_input )
        self.driver_func.put_item_info( first_name_input, 'test' )

        user_name_input = self.driver_func.get_element_by_name('log')
        self.driver_func.clear_item_info( user_name_input )
        self.driver_func.put_item_info( user_name_input, 'test'+str( dt_now.microsecond ) )

        user_email_input = self.driver_func.get_element_by_name('user_email')
        self.driver_func.clear_item_info( user_email_input )
        self.driver_func.put_item_info( user_email_input, 'test'+str( dt_now.microsecond )+'@exaple.com' )

        password_input = self.driver_func.get_element_by_name('password')
        self.driver_func.clear_item_info( password_input )
        self.driver_func.put_item_info( password_input, 'passwordを記載' )

        register_btn = self.driver_func.get_element_by_xpath(register_btn_path)
        register_btn.submit()

    # ブラウザーを閉じる
    def quit_browser(self):
        self.chrome.quit()
Ejemplo n.º 4
0
class Public_Calendar:
    def __init__(self, driver):

        self.chrome = driver
        self.driver_func = Driver_Action(driver)
        self.admin_xpath_list_func = Admin_Menu_Path()
        self.basic_func = Basic()
        # 管理画面のメニューのパスを返す
        self.admin_xpath_lists_xpath = self.admin_xpath_list_func.get_admin_menu_xpath(
        )

        # 管理画面メニュー内の新規追加や編集などのパーツのパスを返す。
        self.admin_list_parts_xpath = self.admin_xpath_list_func.get_admin_menu_list_parts_xpath(
        )

        # 管理画面内の項目に関するパス(作成した固定ページリストとか)
        self.admin_parts_xpath = self.admin_xpath_list_func.get_admin_parts()

        #ユーザー画面内の項目に関するパス
        self.public_parts_xpath = self.admin_xpath_list_func.get_public_parts()

        self.base_dir = self.basic_func.get_base_dir_path()

        self.calendar_page_url = self.basic_func.get_calendar_page_url()

    def go_to_calendar_page(self):

        self.driver_func.move_to_page_by_link(self.chrome,
                                              self.calendar_page_url)

    def click_calendar(self, target_calendar_name):
        calendar_cell_xpath = self.public_parts_xpath[
            'calendar_cell_list_xpath']
        calendar_cells = self.driver_func.get_elements_by_xpath(
            calendar_cell_xpath)

        calendar_cell_elem = self.basic_func.get_target_element(
            calendar_cells, target_calendar_name)
        self.driver_func.click_item(calendar_cell_elem)

    def go_to_calendar_register_page(self):
        calendar_register_xpath = self.public_parts_xpath[
            'calendar_cell_register_xpath']
        calendar_register_elem = self.driver_func.get_element_by_xpath(
            calendar_register_xpath)
        self.driver_func.click_item(calendar_register_elem)

    def put_calendar_register_info(self):

        date_time1_elem = self.driver_func.get_element_by_name('date_time1')
        date_time2_elem = self.driver_func.get_element_by_name('date_time2')
        comment_elem = self.driver_func.get_element_by_name('comment')
        submit_btn_elem = self.driver_func.get_element_by_id('submit')

        self.driver_func.put_item_info(date_time1_elem, '13:00')
        self.driver_func.put_item_info(date_time2_elem, '16:00')
        self.driver_func.put_item_info(comment_elem, 'かれんだーてすと')

        self.driver_func.click_item(submit_btn_elem)

    def go_to_calendar_edit_page(self):
        calendar_edit_xpath = self.public_parts_xpath[
            'calendar_cell_edit_xpath']
        calendar_edit_elem = self.driver_func.get_element_by_xpath(
            calendar_edit_xpath)
        self.driver_func.click_item(calendar_edit_elem)

    def put_calendar_edit_info(self):

        date_time1_elem = self.driver_func.get_element_by_name('date_time1')
        date_time2_elem = self.driver_func.get_element_by_name('date_time2')
        comment_elem = self.driver_func.get_element_by_name('comment')
        submit_btn_elem = self.driver_func.get_element_by_id('submit')

        self.driver_func.clear_item_info(date_time1_elem)
        self.driver_func.put_item_info(date_time1_elem, '13:00')

        self.driver_func.clear_item_info(date_time2_elem)
        self.driver_func.put_item_info(date_time2_elem, '16:00')

        self.driver_func.clear_item_info(comment_elem)
        self.driver_func.put_item_info(comment_elem, 'かれんだーてすと')

        self.driver_func.click_item(submit_btn_elem)
Ejemplo n.º 5
0
class Test_User_Payment_Register:

    def __init__(self, driver):
        self.chrome = driver
        self.driver_func = Driver_Action( driver )

    #GuildPressのページで、PayPal決済ボタンをクリックした後にページが表示されているかチェックする関数
    def is_first_paypal_page_loaded( self ):

        try:
            self.driver_func.stop(10)
            payment_btn_xpath = '//button[@type="submit"]'
            target_click = '//a[text()="ここをクリックしてください"]'
            payment_btn = self.driver_func.get_element_by_xpath(payment_btn_xpath)
        except NoSuchElementException:
            print('no page')
            return self.is_first_paypal_page_loaded()
        else:
            print('page')
            return True

    def is_next_paypal_page_loaded( self ):

        try:
            self.driver_func.stop(10)

            login_email_elem = self.driver_func.get_element_by_name( 'login_email' )
            self.driver_func.clear_item_info( login_email_elem )
            self.driver_func.put_item_info( login_email_elem, 'paypalのメールアドレスを記載' )
        except NoSuchElementException:
            print('no is_next_paypal_page_loaded')
            return self.is_next_paypal_page_loaded()
        else:
            print('is_next_paypal_page_loaded')

            return True

    def is_third_paypal_page_loaded(self):

        try:
            self.driver_func.stop(10)
            login_password_elem = self.driver_func.get_element_by_name( 'login_password' )
            self.driver_func.clear_item_info( login_password_elem )
            self.driver_func.put_item_info( login_password_elem, 'passwordを記載' )

            btnLogin_elem = self.driver_func.get_element_by_name( 'btnLogin' )

        except NoSuchElementException:
            print('no is_third_paypal_page_loaded')
            return self.is_third_paypal_page_loaded()
        else:
            print('is_third_paypal_page_loaded')
            return True


    def is_last_paypal_page_loaded(self):

        try:
            self.driver_func.stop(10)
            confirmButtonTop_elem = self.driver_func.get_element_by_id( 'confirmButtonTop' )

        except NoSuchElementException:
            print('no is_last_paypal_page_loaded')
            return self.is_last_paypal_page_loaded()
        else:
            print('is_last_paypal_page_loaded')
            return True

    def click_new_register_page_pay_pal_btn( self ):

        pay_pal_btn_xpath = '//button[@id="paypal_btn"]'
        pay_pal_btn = self.driver_func.get_element_by_xpath(pay_pal_btn_xpath)
        pay_pal_btn.click()

        is_result = self.is_first_paypal_page_loaded()
        if( is_result == True ):
            self.driver_func.stop(15)
            payment_btn_xpath = '//button[@type="submit"]'
            payment_btn = self.driver_func.get_element_by_xpath(payment_btn_xpath)
            self.driver_func.click_item( payment_btn )

        is_thrid_result = self.is_new_paypal_page_loaded()
        if( is_thrid_result == True ):
            self.driver_func.stop(15)
            btnLogin_elem = self.driver_func.get_element_by_name( 'btnLogin' )
            self.driver_func.click_item( btnLogin_elem )

        is_last_result = self.is_last_paypal_page_loaded()
        if( is_last_result == True ):
            self.driver_func.get_element_by_id( 'confirmButtonTop' ).click()

        self.driver_func.stop(15)

    def is_new_paypal_page_loaded( self ):

        try:
            self.driver_func.stop(10)

            login_email_elem = self.driver_func.get_element_by_name( 'login_email' )
            self.driver_func.clear_item_info( login_email_elem )
            self.driver_func.put_item_info( login_email_elem, 'paypalのメールアドレスを記載' )

            login_password_elem = self.driver_func.get_element_by_name( 'login_password' )
            self.driver_func.clear_item_info( login_password_elem )
            self.driver_func.put_item_info( login_password_elem, 'passwordを記載' )

        except NoSuchElementException:
            print('no is_next_paypal_page_loaded')
            return self.is_next_paypal_page_loaded()
        else:
            print('is_next_paypal_page_loaded')

            return True

    def click_register_page_pay_pal_btn( self ):

        pay_pal_btn_xpath = '//button[@id="paypal_btn"]'
        pay_pal_btn = self.driver_func.get_element_by_xpath(pay_pal_btn_xpath)
        pay_pal_btn.click()

        is_result = self.is_first_paypal_page_loaded()
        if( is_result == True ):
            self.driver_func.stop(15)
            payment_btn_xpath = '//button[@type="submit"]'
            payment_btn = self.driver_func.get_element_by_xpath(payment_btn_xpath)
            self.driver_func.click_item( payment_btn )

        is_next_result = self.is_next_paypal_page_loaded()
        if( is_next_result == True ):
            self.driver_func.stop(15)
            next_payment_btn_xpath = '//button[@type="submit"][text()="次へ"]'
            next_payment_btn = self.driver_func.get_element_by_xpath(next_payment_btn_xpath)
            self.driver_func.click_item( next_payment_btn )

        self.driver_func.stop(15)
        result = self.check_paypal_login_email()

        if( result == True ):
            is_next_result = self.is_next_paypal_page_loaded()
            if( is_next_result == True ):
                next_payment_btn_xpath = '//button[@type="submit"][text()="次へ"]'
                next_payment_btn = self.driver_func.get_element_by_xpath(next_payment_btn_xpath)
                self.driver_func.click_item( next_payment_btn )


        is_thrid_result = self.is_third_paypal_page_loaded()
        if( is_thrid_result == True ):
            self.driver_func.stop(15)
            btnLogin_elem = self.driver_func.get_element_by_name( 'btnLogin' )
            self.driver_func.click_item( btnLogin_elem )

        is_last_result = self.is_last_paypal_page_loaded()
        if( is_last_result == True ):
            self.driver_func.get_element_by_id( 'confirmButtonTop' ).click()

        self.driver_func.stop(15)

    def check_paypal_login_email(self):
        try:
            email_input = self.driver_func.get_element_by_name('login_email')
        except NoSuchElementException:
            return False

        if( email_input.is_displayed() == True ):
            return True
        else :
            return False
Ejemplo n.º 6
0
class Lesson_Over_View_Posts:
    def __init__(self, driver):
        self.chrome = driver
        self.driver_func = Driver_Action(driver)
        self.admin_xpath_list_func = Admin_Menu_Path()
        self.basic_func = Basic()
        self.admin_xpath_lists_xpath = self.admin_xpath_list_func.get_admin_menu_xpath(
        )
        self.admin_list_parts_xpath = self.admin_xpath_list_func.get_admin_menu_list_parts_xpath(
        )
        self.admin_parts_xpath = self.admin_xpath_list_func.get_admin_parts()

    def add_lesson_over_view_page(self):
        #ポストのタイトル、テキストのディレクトリ、カテゴリー名、アイキャッチ画像
        base_dir = self.basic_func.get_base_dir_path()
        lesson_overview = {
            'first_lesson_over_view': {
                'post_title':
                '英語初級講座',
                'category_name':
                '英語初級講座',
                'text_dir':
                base_dir + '/assets/texts/beginner/english-beginner.txt',
                'img_dir':
                base_dir + '/assets/img/beginner/english-beginner-overview.png'
            },
            'second_lesson_over_view': {
                'post_title':
                '英語中級講座',
                'category_name':
                '英語中級講座',
                'text_dir':
                base_dir + '/assets/texts/normal/english-normal.txt',
                'img_dir':
                base_dir + '/assets/img/normal/english-normal-overview.png'
            },
            'third_lesson_over_view': {
                'post_title':
                '英語上級講座',
                'category_name':
                '英語上級講座',
                'text_dir':
                base_dir + '/assets/texts/advanced/english-advanced.txt',
                'img_dir':
                base_dir + '/assets/img/advanced/english-advanced-overview.png'
            }
        }

        for list_loop_name, lesson_overview_lists in lesson_overview.items():
            self.create_new_lesson_over_view_page(lesson_overview_lists)

    def create_new_lesson_over_view_page(self, lesson_overview_lists):

        #要素を取得するためのXpathのリストを準備
        lesson_list_path = self.admin_xpath_lists_xpath[
            'admin_guild_press_lesson_over_view_list_page_path']
        add_new_lesson_list_path = self.admin_list_parts_xpath['add_new_page']

        #Xpathで、各要素を取得
        publish_post_btn = self.admin_parts_xpath['publish_post_btn']
        add_new_element = self.driver_func.get_element_by_xpath(
            add_new_lesson_list_path)

        #新規追加をクリックして、移動。
        self.driver_func.click_item(add_new_element)

        self.put_contents(lesson_overview_lists)

        self.upload_img(lesson_overview_lists)

        self.upload_thumbnail(lesson_overview_lists)

        #公開ボタンを押す。
        # publish_post_btn_element = self.driver_func.get_element_by_xpath( publish_post_btn )
        # self.driver_func.click_item( publish_post_btn_element )
        self.driver_func.click_publish_btn()

        self.driver_func.stop(0.5)

        #一度他のページへ移動
        self.driver_func.move_admin_page(
            self.admin_xpath_lists_xpath['admin_main_setting_path'],
            self.admin_xpath_lists_xpath['admin_sub_setting_path'])

        self.driver_func.move_admin_page(
            self.admin_xpath_lists_xpath[
                'admin_guild_press_lesson_over_view_page_path'],
            self.admin_xpath_lists_xpath[
                'admin_guild_press_lesson_over_view_list_page_path'])

    def put_contents(self, lesson_overview_lists):
        #各要素を取得して、入力していく。
        post_title_element = self.driver_func.get_element_by_name('post_title')

        self.driver_func.put_item_info(post_title_element,
                                       lesson_overview_lists['post_title'])

        content_html = self.driver_func.get_element_by_id('content-html')
        self.driver_func.click_item(content_html)

        content_box_element = self.driver_func.get_element_by_name('content')
        content_text = self.basic_func.get_file_text(
            lesson_overview_lists['text_dir'])
        self.driver_func.put_item_info(content_box_element, content_text)

        category_box_element = self.driver_func.get_element_by_id(
            'guild_lesson_category-add-toggle')
        self.driver_func.click_item(category_box_element)

        category_input_element = self.driver_func.get_element_by_name(
            'newguild_lesson_category')
        self.driver_func.put_item_info(category_input_element,
                                       lesson_overview_lists['category_name'])

        category_submit_element = self.driver_func.get_element_by_id(
            'guild_lesson_category-add-submit')
        self.driver_func.click_item(category_submit_element)

    def upload_img(self, lesson_overview_lists):
        media_submit_btn = self.admin_parts_xpath['media_submit_btn']
        media_input_file = self.admin_parts_xpath['media_input_file']
        self.driver_func.stop(0.5)

        #メディアを入れるためにボタンをクリックする。
        media_btn_html = self.driver_func.get_element_by_id(
            'insert-media-button')
        self.driver_func.click_item(media_btn_html)

        #画像をアップロード
        img_btn_element = self.driver_func.get_element_by_xpath(
            media_input_file)
        self.driver_func.put_item_info(img_btn_element,
                                       lesson_overview_lists['img_dir'])

        #アップロードが終了して、完了ボタンが押せるかチェック。
        self.is_click_media_submit_btn()

    def upload_thumbnail(self, lesson_overview_lists):
        media_input_file = self.admin_parts_xpath['media_input_file']
        media_add_eye_catch_btn = self.admin_parts_xpath[
            'media_add_eye_catch_btn']
        media_eye_catch_submit_btn = self.admin_parts_xpath[
            'media_eye_catch_submit_btn']

        #サムネイルを入れるためにボタンをクリックする。
        media_btn_html = self.driver_func.get_element_by_xpath(
            media_add_eye_catch_btn)
        self.driver_func.click_item(media_btn_html)

        #画像をアップロード
        img_btn_element = self.driver_func.get_element_by_xpath(
            media_input_file)
        self.driver_func.put_item_info(img_btn_element,
                                       lesson_overview_lists['img_dir'])

        #アップロードした後しばらく待つ。
        self.is_click_thumbnail_submit_btn()

    def is_click_thumbnail_submit_btn(self):

        media_eye_catch_submit_btn = self.admin_parts_xpath[
            'media_eye_catch_submit_btn']

        self.driver_func.stop(0.5)
        eye_chactch_submit_element = self.driver_func.get_element_by_xpath(
            media_eye_catch_submit_btn)

        if (eye_chactch_submit_element.is_enabled()):
            print('is_click_thumbnail_submit_btn')
            self.driver_func.click_item(eye_chactch_submit_element)

        else:
            print('no is_click_thumbnail_submit_btn')
            self.is_click_thumbnail_submit_btn()

    def is_click_media_submit_btn(self):

        media_submit_btn = self.admin_parts_xpath['media_submit_btn']

        self.driver_func.stop(0.5)
        img_submit_element = self.driver_func.get_element_by_xpath(
            media_submit_btn)

        if (img_submit_element.is_enabled()):
            self.driver_func.click_item(img_submit_element)

        else:
            self.is_click_media_submit_btn()
class Admin_Add_Quiz:
    def __init__(self, driver):

        self.chrome = driver
        self.driver_func = Driver_Action(driver)
        self.admin_xpath_list_func = Admin_Menu_Path()
        self.basic_func = Basic()
        # 管理画面のメニューのパスを返す
        self.admin_xpath_lists_xpath = self.admin_xpath_list_func.get_admin_menu_xpath(
        )

        # 管理画面メニュー内の新規追加や編集などのパーツのパスを返す。
        self.admin_list_parts_xpath = self.admin_xpath_list_func.get_admin_menu_list_parts_xpath(
        )

        # 管理画面内の項目に関するパス(作成した固定ページリストとか)
        self.admin_parts_xpath = self.admin_xpath_list_func.get_admin_parts()

        #ユーザー画面内の項目に関するパス
        self.public_parts_xpath = self.admin_xpath_list_func.get_public_parts()

        self.base_dir = self.basic_func.get_base_dir_path()

    def set_quiz_to_page(self):

        lesson_details = {
            'beginner_lesson_details': {
                'first_lesson_details': {
                    'post_title': '英語文法(初級講座)',
                    'page_lock': '1',
                    'quiz_num': 6,
                    'quiz_correct_num': 5,
                    'quiz_text': self.base_dir + '/assets/texts/quiz/quiz.txt',
                    'first_quiz_answer': 'answer_1',
                    'quiz_answer': {
                        'answer_2',
                        'answer_3',
                        'answer_4',
                        'answer_5',
                        'answer_6',
                    }
                },
                'second_lesson_details': {
                    'post_title': '英語リスニング(初級講座)',
                    'page_lock': '2',
                    'quiz_num': 2,
                    'quiz_correct_num': 2,
                    'quiz_text': self.base_dir + '/assets/texts/quiz/quiz.txt',
                    'first_quiz_answer': 'answer_1',
                    'quiz_answer': {
                        'answer_2',
                    }
                },
                'third_lesson_details': {
                    'post_title': '英語リーディング(初級講座)',
                    'page_lock': '2',
                    'quiz_num': 1,
                    'quiz_correct_num': 1,
                    'quiz_text': self.base_dir + '/assets/texts/quiz/quiz.txt',
                    'first_quiz_answer': 'answer_1',
                    'quiz_answer': {}
                },
                'fourth_lesson_details': {
                    'post_title': '英語スピーキング(初級講座)',
                    'page_lock': '2',
                    'quiz_num': 4,
                    'quiz_correct_num': 2,
                    'quiz_text': self.base_dir + '/assets/texts/quiz/quiz.txt',
                    'first_quiz_answer': 'answer_1',
                    'quiz_answer': {
                        'answer_2',
                        'answer_3',
                        'answer_4',
                    }
                },
                'fifth_lesson_details': {
                    'post_title': '英語単語(初級講座)',
                    'page_lock': '2',
                    'quiz_num': 4,
                    'quiz_correct_num': 3,
                    'quiz_text': self.base_dir + '/assets/texts/quiz/quiz.txt',
                    'first_quiz_answer': 'answer_1',
                    'quiz_answer': {
                        'answer_2',
                        'answer_3',
                        'answer_4',
                    }
                }
            },
            'normal_lesson_details': {
                'first_lesson_details': {
                    'post_title': '英語文法(中級講座)',
                    'page_lock': '1',
                    'quiz_num': 2,
                    'quiz_correct_num': 1,
                    'quiz_text': self.base_dir + '/assets/texts/quiz/quiz.txt',
                    'first_quiz_answer': 'answer_1',
                    'quiz_answer': {
                        'answer_2',
                    }
                },
                'second_lesson_details': {
                    'post_title': '英語リスニング(中級講座)',
                    'page_lock': '2',
                    'quiz_num': 1,
                    'quiz_correct_num': 1,
                    'quiz_text': self.base_dir + '/assets/texts/quiz/quiz.txt',
                    'first_quiz_answer': 'answer_1',
                    'quiz_answer': {}
                },
                'third_lesson_details': {
                    'post_title': '英語リーディング(中級講座)',
                    'page_lock': '2',
                    'quiz_num': 7,
                    'quiz_correct_num': 5,
                    'quiz_text': self.base_dir + '/assets/texts/quiz/quiz.txt',
                    'first_quiz_answer': 'answer_1',
                    'quiz_answer': {
                        'answer_2',
                        'answer_3',
                        'answer_4',
                        'answer_5',
                        'answer_6',
                        'answer_7',
                    }
                },
                'fourth_lesson_details': {
                    'post_title': '英語スピーキング(中級講座)',
                    'page_lock': '2',
                    'quiz_num': 6,
                    'quiz_correct_num': 5,
                    'quiz_text': self.base_dir + '/assets/texts/quiz/quiz.txt',
                    'first_quiz_answer': 'answer_1',
                    'quiz_answer': {
                        'answer_2',
                        'answer_3',
                        'answer_4',
                        'answer_5',
                        'answer_6',
                    }
                },
                'fifth_lesson_details': {
                    'post_title': '英語単語(中級講座)',
                    'page_lock': '2',
                    'quiz_num': 9,
                    'quiz_correct_num': 8,
                    'quiz_text': self.base_dir + '/assets/texts/quiz/quiz.txt',
                    'first_quiz_answer': 'answer_1',
                    'quiz_answer': {
                        'answer_2',
                        'answer_3',
                        'answer_4',
                        'answer_5',
                        'answer_6',
                        'answer_7',
                        'answer_8',
                        'answer_9',
                    }
                }
            },
            'advanced_lesson_details': {
                'first_lesson_details': {
                    'post_title': '英語文法(上級講座)',
                    'page_lock': '1',
                    'quiz_num': 4,
                    'quiz_correct_num': 3,
                    'quiz_text': self.base_dir + '/assets/texts/quiz/quiz.txt',
                    'first_quiz_answer': 'answer_1',
                    'quiz_answer': {
                        'answer_2',
                        'answer_3',
                        'answer_4',
                    }
                },
                'second_lesson_details': {
                    'post_title': '英語リスニング(上級講座)',
                    'page_lock': '2',
                    'quiz_num': 5,
                    'quiz_correct_num': 1,
                    'quiz_text': self.base_dir + '/assets/texts/quiz/quiz.txt',
                    'first_quiz_answer': 'answer_1',
                    'quiz_answer': {
                        'answer_2',
                        'answer_3',
                        'answer_4',
                        'answer_5',
                    }
                },
                'third_lesson_details': {
                    'post_title': '英語リーディング(上級講座)',
                    'page_lock': '2',
                    'quiz_num': 1,
                    'quiz_correct_num': 1,
                    'quiz_text': self.base_dir + '/assets/texts/quiz/quiz.txt',
                    'first_quiz_answer': 'answer_1',
                    'quiz_answer': {}
                },
                'fourth_lesson_details': {
                    'post_title': '英語スピーキング(上級講座)',
                    'page_lock': '2',
                    'quiz_num': 5,
                    'quiz_correct_num': 3,
                    'quiz_text': self.base_dir + '/assets/texts/quiz/quiz.txt',
                    'first_quiz_answer': 'answer_1',
                    'quiz_answer': {
                        'answer_2',
                        'answer_3',
                        'answer_4',
                        'answer_5',
                    }
                },
                'fifth_lesson_details': {
                    'post_title': '英語単語(上級講座)',
                    'page_lock': '2',
                    'quiz_num': 5,
                    'quiz_correct_num': 4,
                    'quiz_text': self.base_dir + '/assets/texts/quiz/quiz.txt',
                    'first_quiz_answer': 'answer_1',
                    'quiz_answer': {
                        'answer_2',
                        'answer_3',
                        'answer_4',
                        'answer_5',
                    }
                }
            }
        }

        lesson_details_test = {
            'beginner_lesson_details': {
                'second_lesson_details': {
                    'post_title': '英語単語(上級講座)',
                    'page_lock': '2',
                    'quiz_num': 5,
                    'quiz_correct_num': 4,
                    'quiz_text': self.base_dir + '/assets/texts/quiz/quiz.txt',
                    'first_quiz_answer': 'answer_1',
                    'quiz_answer': {
                        'answer_2',
                        'answer_3',
                        'answer_4',
                        'answer_5',
                    }
                }
            }
        }

        page_list_xpath = self.admin_parts_xpath['page_list_xpath']
        page_list_elem = self.driver_func.get_elements_by_xpath(
            page_list_xpath)

        for details_item_name, details_item_value in lesson_details.items():
            for list_name, lesson_details_lists in details_item_value.items():
                self.add_info(lesson_details_lists)

    def reset_info(self, lesson_details_lists):
        page_list_xpath = self.admin_parts_xpath['page_list_xpath']
        page_list_elem = self.driver_func.get_elements_by_xpath(
            page_list_xpath)
        no_quiz_btn_xpath = self.admin_parts_xpath['no_quiz_btn_xpath']
        quiz_textarea_xpath = self.admin_parts_xpath['quiz_textarea_xpath']
        quiz_input_xpath = self.admin_parts_xpath['quiz_input_xpath']
        add_quiz_btn_xpath = self.admin_parts_xpath['add_quiz_btn_xpath']
        quiz_first_input_xpath = self.admin_parts_xpath[
            'quiz_first_input_xpath']
        answer_radio_xpath = self.admin_parts_xpath['answer_radio_xpath']
        first_answer_radio_xpath = self.admin_parts_xpath[
            'first_answer_radio_xpath']
        current_page_btn_xpath = self.admin_parts_xpath[
            'current_page_btn_xpath']
        update_post_btn_xpath = self.admin_parts_xpath['update_post_btn']

        target_text = lesson_details_lists['post_title']

        target_elem = self.basic_func.get_target_element(
            page_list_elem, target_text)
        self.driver_func.click_item(target_elem)

        if (lesson_details_lists['page_lock'] == '2'):
            self.driver_func.stop(1)
            guild_press_quiz_btn_elem = self.driver_func.get_element_by_xpath(
                no_quiz_btn_xpath)
            self.driver_func.click_item(guild_press_quiz_btn_elem)

        self.driver_func.scroll_top(self.chrome)

        update_post_btn_elem = self.driver_func.get_element_by_xpath(
            update_post_btn_xpath)
        self.driver_func.click_item(update_post_btn_elem)

        self.driver_func.stop(1)

        #投稿リストを表示する
        current_page_btn_elem = self.driver_func.get_element_by_xpath(
            current_page_btn_xpath)
        self.driver_func.click_item(current_page_btn_elem)

    def add_info(self, lesson_details_lists):

        page_list_xpath = self.admin_parts_xpath['page_list_xpath']
        page_list_elem = self.driver_func.get_elements_by_xpath(
            page_list_xpath)
        quiz_btn_xpath = self.admin_parts_xpath['quiz_btn_xpath']
        quiz_textarea_xpath = self.admin_parts_xpath['quiz_textarea_xpath']
        quiz_input_xpath = self.admin_parts_xpath['quiz_input_xpath']
        add_quiz_btn_xpath = self.admin_parts_xpath['add_quiz_btn_xpath']
        quiz_first_input_xpath = self.admin_parts_xpath[
            'quiz_first_input_xpath']
        answer_radio_xpath = self.admin_parts_xpath['answer_radio_xpath']
        first_answer_radio_xpath = self.admin_parts_xpath[
            'first_answer_radio_xpath']
        current_page_btn_xpath = self.admin_parts_xpath[
            'current_page_btn_xpath']
        update_post_btn_xpath = self.admin_parts_xpath['update_post_btn']

        target_text = lesson_details_lists['post_title']

        target_elem = self.basic_func.get_target_element(
            page_list_elem, target_text)
        self.driver_func.click_item(target_elem)

        if (lesson_details_lists['page_lock'] == '2'):
            self.driver_func.scroll_down(self.chrome)
            guild_press_quiz_btn_elem = self.driver_func.get_element_by_xpath(
                quiz_btn_xpath)
            self.driver_func.click_item(guild_press_quiz_btn_elem)

            for x in range(len(lesson_details_lists['quiz_answer'])):
                add_quiz_btn_elem = self.driver_func.get_element_by_xpath(
                    add_quiz_btn_xpath)
                self.driver_func.click_item(add_quiz_btn_elem)

            guild_press_quiz_textarea_elem = self.driver_func.get_element_by_xpath(
                quiz_textarea_xpath)
            content_text = self.basic_func.get_file_text(
                lesson_details_lists['quiz_text'])

            self.driver_func.put_item_info(guild_press_quiz_textarea_elem,
                                           content_text)

            quiz_input_elem = self.driver_func.get_elements_by_xpath(
                quiz_input_xpath)

            quiz_first_input_elem = self.driver_func.get_element_by_xpath(
                quiz_first_input_xpath)
            self.driver_func.put_item_info(
                quiz_first_input_elem,
                lesson_details_lists['first_quiz_answer'])

            first_answer_radio_elem = self.driver_func.get_element_by_xpath(
                first_answer_radio_xpath)

            answer_radio_elem = self.driver_func.get_elements_by_xpath(
                answer_radio_xpath)

            self.driver_func.click_item(first_answer_radio_elem)

            for i, (quiz_inputs_elem, quiz_answer) in enumerate(
                    zip(quiz_input_elem, lesson_details_lists['quiz_answer'])):
                if ((i + 1) == lesson_details_lists['quiz_correct_num']):
                    self.driver_func.click_item(answer_radio_elem[i])
                self.driver_func.put_item_info(quiz_inputs_elem, quiz_answer)

        self.driver_func.scroll_top(self.chrome)

        update_post_btn_elem = self.driver_func.get_element_by_xpath(
            update_post_btn_xpath)
        self.driver_func.click_item(update_post_btn_elem)

        self.driver_func.stop(1)

        #投稿リストを表示する
        current_page_btn_elem = self.driver_func.get_element_by_xpath(
            current_page_btn_xpath)
        self.driver_func.click_item(current_page_btn_elem)
Ejemplo n.º 8
0
class Lesson_Detail_Posts:

    def __init__(self, driver):
        self.chrome = driver
        self.driver_func = Driver_Action( driver )
        self.admin_xpath_list_func = Admin_Menu_Path()
        self.basic_func = Basic()
        self.admin_xpath_lists_xpath = self.admin_xpath_list_func.get_admin_menu_xpath()
        self.admin_list_parts_xpath = self.admin_xpath_list_func.get_admin_menu_list_parts_xpath()
        self.admin_parts_xpath = self.admin_xpath_list_func.get_admin_parts()

    def add_lesson_detail_page(self):
        #ポストのタイトル、テキストのディレクトリ、カテゴリー名、アイキャッチ画像
        base_dir = self.basic_func.get_base_dir_path()
        lesson_details = {
            'beginner_lesson_details' : {
                'first_lesson_details' : {
                    'post_title' : '英語文法(初級講座)',
                    'category_name' : '英語初級講座',
                    'text_dir' : base_dir+'/assets/texts/beginner/english-beginner-grammer.txt',
                    'img_dir' : base_dir+'/assets/img/beginner/english-beginner-grammer.png'
                },
                'second_lesson_details' : {
                    'post_title' : '英語リスニング(初級講座)',
                    'category_name' : '英語初級講座',
                    'text_dir' : base_dir+'/assets/texts/beginner/english-beginner-listening.txt',
                    'img_dir' : base_dir+'/assets/img/beginner/english-beginner-listening.png'
                },
                'third_lesson_details' : {
                    'post_title' : '英語リーディング(初級講座)',
                    'category_name' : '英語初級講座',
                    'text_dir' : base_dir+'/assets/texts/beginner/english-beginner-reading.txt',
                    'img_dir' : base_dir+'/assets/img/beginner/english-beginner-reading.png'
                },
                'fourth_lesson_details' : {
                    'post_title' : '英語スピーキング(初級講座)',
                    'category_name' : '英語初級講座',
                    'text_dir' : base_dir+'/assets/texts/beginner/english-beginner-speaking.txt',
                    'img_dir' : base_dir+'/assets/img/beginner/english-beginner-speaking.png'
                },
                'fifth_lesson_details' : {
                    'post_title' : '英語単語(初級講座)',
                    'category_name' : '英語初級講座',
                    'text_dir' : base_dir+'/assets/texts/beginner/english-beginner-words.txt',
                    'img_dir' : base_dir+'/assets/img/beginner/english-beginner-words.png'
                }
            },
            'normal_lesson_details' : {
                'first_lesson_details' : {
                    'post_title' : '英語文法(中級講座)',
                    'category_name' : '英語中級講座',
                    'text_dir' : base_dir+'/assets/texts/normal/english-normal-grammer.txt',
                    'img_dir' : base_dir+'/assets/img/normal/english-normal-grammer.png'
                },
                'second_lesson_details' : {
                    'post_title' : '英語リスニング(中級講座)',
                    'category_name' : '英語中級講座',
                    'text_dir' : base_dir+'/assets/texts/normal/english-normal-listening.txt',
                    'img_dir' : base_dir+'/assets/img/normal/english-normal-listening.png'
                },
                'third_lesson_details' : {
                    'post_title' : '英語リーディング(中級講座)',
                    'category_name' : '英語中級講座',
                    'text_dir' : base_dir+'/assets/texts/normal/english-normal-reading.txt',
                    'img_dir' : base_dir+'/assets/img/normal/english-normal-reading.png'
                },
                'fourth_lesson_details' : {
                    'post_title' : '英語スピーキング(中級講座)',
                    'category_name' : '英語中級講座',
                    'text_dir' : base_dir+'/assets/texts/normal/english-normal-speaking.txt',
                    'img_dir' : base_dir+'/assets/img/normal/english-normal-speaking.png'
                },
                'fifth_lesson_details' : {
                    'post_title' : '英語単語(中級講座)',
                    'category_name' : '英語中級講座',
                    'text_dir' : base_dir+'/assets/texts/normal/english-normal-words.txt',
                    'img_dir' : base_dir+'/assets/img/normal/english-normal-words.png'
                }
            },
            'advanced_lesson_details' : {
                'first_lesson_details' : {
                    'post_title' : '英語文法(上級講座)',
                    'category_name' : '英語上級講座',
                    'text_dir' : base_dir+'/assets/texts/advanced/english-advanced-grammer.txt',
                    'img_dir' : base_dir+'/assets/img/advanced/english-advanced-grammer.png'
                },
                'second_lesson_details' : {
                    'post_title' : '英語リスニング(上級講座)',
                    'category_name' : '英語上級講座',
                    'text_dir' : base_dir+'/assets/texts/advanced/english-advanced-listening.txt',
                    'img_dir' : base_dir+'/assets/img/advanced/english-advanced-listening.png'
                },
                'third_lesson_details' : {
                    'post_title' : '英語リーディング(上級講座)',
                    'category_name' : '英語上級講座',
                    'text_dir' : base_dir+'/assets/texts/advanced/english-advanced-reading.txt',
                    'img_dir' : base_dir+'/assets/img/advanced/english-advanced-reading.png'
                },
                'fourth_lesson_details' : {
                    'post_title' : '英語スピーキング(上級講座)',
                    'category_name' : '英語上級講座',
                    'text_dir' : base_dir+'/assets/texts/advanced/english-advanced-speaking.txt',
                    'img_dir' : base_dir+'/assets/img/advanced/english-advanced-speaking.png'
                },
                'fifth_lesson_details' : {
                    'post_title' : '英語単語(上級講座)',
                    'category_name' : '英語上級講座',
                    'text_dir' : base_dir+'/assets/texts/advanced/english-advanced-words.txt',
                    'img_dir' : base_dir+'/assets/img/advanced/english-advanced-words.png'
                }
            }
        }

        #for list_loop_name,lesson_details_lists in lesson_overview.items():

        for details_item_name, details_item_value in lesson_details.items():
            for list_name,lesson_details_lists in details_item_value.items():
                self.create_new_lesson_detail_page( lesson_details_lists )

    def create_new_lesson_detail_page( self, lesson_details_lists ):

        #要素を取得するためのXpathのリストを準備
        lesson_list_path = self.admin_xpath_lists_xpath['admin_guild_press_lesson_detail_list_page_path']
        add_new_lesson_list_path = self.admin_list_parts_xpath['add_new_page']

        #Xpathで、各要素を取得
        publish_post_btn = self.admin_parts_xpath['publish_post_btn']

        add_new_element = self.driver_func.get_element_by_xpath( add_new_lesson_list_path )

        #新規追加をクリックして、移動。
        self.driver_func.click_item(add_new_element)

        self.put_contents( lesson_details_lists )

        self.upload_img( lesson_details_lists )

        self.upload_thumbnail( lesson_details_lists )


        #公開ボタンを押す。
        self.driver_func.click_publish_btn()

        self.driver_func.stop(3)

        #一度他のページへ移動
        self.driver_func.move_admin_page( self.admin_xpath_lists_xpath['admin_main_setting_path'], self.admin_xpath_lists_xpath['admin_sub_setting_path'] )

        self.driver_func.move_admin_page( self.admin_xpath_lists_xpath['admin_guild_press_lesson_detail_page_path'], self.admin_xpath_lists_xpath['admin_guild_press_lesson_detail_list_page_path'] )

    def put_contents( self, lesson_details_lists ):
        #各要素を取得して、入力していく。
        post_title_element = self.driver_func.get_element_by_name( 'post_title' )
        self.driver_func.put_item_info( post_title_element, lesson_details_lists['post_title'] )

        #コンテンツを詰める
        content_html = self.driver_func.get_element_by_id('content-html')

        if( not content_html.is_selected() ) :
            self.driver_func.click_item( content_html )

        content_box_element = self.driver_func.get_element_by_name( 'content' )
        content_text = self.basic_func.get_file_text( lesson_details_lists['text_dir'] )
        self.driver_func.put_item_info( content_box_element, content_text )

        self.check_category_box( lesson_details_lists['category_name'] )


    def upload_img( self, lesson_details_lists ):
        media_input_file = self.admin_parts_xpath['media_input_file']

         #メディアを入れるためにボタンをクリックする。
        media_btn_html = self.driver_func.get_element_by_id('insert-media-button')
        self.driver_func.click_item( media_btn_html )

        #画像をアップロード
        img_btn_element = self.driver_func.get_element_by_xpath( media_input_file )
        self.driver_func.put_item_info( img_btn_element, lesson_details_lists['img_dir'] )


        #アップロードした後しばらく待つ。
        self.is_click_media_submit_btn()


    def is_click_media_submit_btn( self ):
        media_submit_btn = self.admin_parts_xpath['media_submit_btn']

        self.driver_func.stop(0.5)
        img_submit_element = self.driver_func.get_element_by_xpath( media_submit_btn )

        if( img_submit_element.is_enabled() ):
            self.driver_func.click_item( img_submit_element )

        else :
            self.is_click_media_submit_btn()


    def upload_thumbnail( self, lesson_details_lists ):
        media_input_file = self.admin_parts_xpath['media_input_file']
        media_add_eye_catch_btn = self.admin_parts_xpath['media_add_eye_catch_btn']
        #サムネイルを入れるためにボタンをクリックする。
        media_btn_html = self.driver_func.get_element_by_xpath( media_add_eye_catch_btn )
        self.driver_func.click_item( media_btn_html )

        #画像をアップロード
        img_btn_element = self.driver_func.get_element_by_xpath( media_input_file )
        self.driver_func.put_item_info( img_btn_element, lesson_details_lists['img_dir'] )

        #アップロードした後しばらく待つ。
        self.is_click_thumbnail_submit_btn()



    def is_click_thumbnail_submit_btn( self ):
        media_eye_catch_submit_btn = self.admin_parts_xpath['media_eye_catch_submit_btn']

        self.driver_func.stop(0.5)
        eye_chactch_submit_element = self.driver_func.get_element_by_xpath( media_eye_catch_submit_btn )

        if( eye_chactch_submit_element.is_enabled() ):
            print('is_click_thumbnail_submit_btn')
            self.driver_func.click_item( eye_chactch_submit_element )

        else :
            print('no is_click_thumbnail_submit_btn')
            self.is_click_thumbnail_submit_btn()





    def check_category_box( self, tareget_text ):

        cat_lists = '//ul[@id="guild_lesson_categorychecklist"]/li'
        cat_lists_check_box = '//ul[@id="guild_lesson_categorychecklist"]/li/label/input'

        category_list_element = self.driver_func.get_elements_by_xpath( cat_lists )
        category_box_element = self.driver_func.get_elements_by_xpath( cat_lists_check_box )

        for element, checkbox in zip( category_list_element, category_box_element ) :
            text = element.text

            if( text == tareget_text and not checkbox.is_selected() ):
                checkbox.click()
Ejemplo n.º 9
0
class Public_Member_Rank:
    def __init__(self, driver):

        self.chrome = driver
        self.driver_func = Driver_Action(driver)
        self.admin_xpath_list_func = Admin_Menu_Path()
        self.basic_func = Basic()
        # 管理画面のメニューのパスを返す
        self.admin_xpath_lists = self.admin_xpath_list_func.get_admin_menu_xpath(
        )

        # 管理画面メニュー内の新規追加や編集などのパーツのパスを返す。
        self.admin_list_parts_xpath = self.admin_xpath_list_func.get_admin_menu_list_parts_xpath(
        )

        # 管理画面内の項目に関するパス(作成した固定ページリストとか)
        self.admin_parts_xpath = self.admin_xpath_list_func.get_admin_parts()

        #ユーザー画面内の項目に関するパス
        self.public_parts_xpath = self.admin_xpath_list_func.get_public_parts()

        self.base_dir = self.basic_func.get_base_dir_path()

        self.lesson_list_page_url = self.basic_func.get_lesson_list_page()

    def go_to_lesson_list_page(self):
        self.driver_func.move_to_page_by_link(self.chrome,
                                              self.lesson_list_page_url)

    def check_element_page(self):

        self.go_to_element_lesson_list_page()

        all_lesson_title_list_xpath = self.public_parts_xpath[
            'all_lesson_title_list_xpath']
        lesson_detail_link = self.public_parts_xpath['lesson_detail_lists']

        block_page_list = ['英語リスニング(初級講座)', '英語スピーキング(初級講座)']
        for block_page_text in block_page_list:
            lesson_detail_elem = self.driver_func.get_elements_by_xpath(
                lesson_detail_link)
            all_lesson_title_lists_elem = self.driver_func.get_elements_by_xpath(
                all_lesson_title_list_xpath)

            lesson_detail_page_link = self.basic_func.get_target_link_element(
                all_lesson_title_lists_elem, lesson_detail_elem,
                block_page_text)

            self.driver_func.click_item(lesson_detail_page_link)

            self.driver_func.stop(2)

            self.go_to_lesson_list_page()
            self.go_to_element_lesson_list_page()

    def check_is_user_get_ranked(self):

        try:
            pay_pal_btn_xpath = '//button[@id="paypal_btn"]'
            pay_pal_btn = self.driver_func.get_element_by_xpath(
                pay_pal_btn_xpath)

        except NoSuchElementException:
            #特に問題ない場合はtrueを返す。
            return True
        else:
            #ボタンが存在する場合は、ユーザーが会員楽を取得できていないので、falseを返してもう一度処理させる。
            return False

    def go_to_element_lesson_list_page(self):
        all_lesson_list = self.public_parts_xpath['all_lesson_list_xpath']
        all_lesson_list_link = self.public_parts_xpath[
            'all_lesson_list_link_xpath']
        all_lesson_lists_elem = self.driver_func.get_elements_by_xpath(
            all_lesson_list)
        all_lesson_lists_link_elem = self.driver_func.get_elements_by_xpath(
            all_lesson_list_link)

        #概要ページから該当する名前順にリンクの要素を取得
        link_elem = self.basic_func.get_target_link_element(
            all_lesson_lists_elem, all_lesson_lists_link_elem, '英語初級講座')

        #リンクを取得
        lesson_detail_link = self.driver_func.get_link(link_elem)

        #リンクに飛ぶ
        self.driver_func.move_to_page_by_link(self.chrome, lesson_detail_link)

    def check_advanced_page(self):

        self.go_to_advanced_lesson_list_page()

        all_lesson_title_list_xpath = self.public_parts_xpath[
            'all_lesson_title_list_xpath']
        lesson_detail_link = self.public_parts_xpath['lesson_detail_lists']

        block_page_list = ['英語リスニング(上級講座)', '英語スピーキング(上級講座)']
        for block_page_text in block_page_list:

            lesson_detail_elem = self.driver_func.get_elements_by_xpath(
                lesson_detail_link)
            all_lesson_title_lists_elem = self.driver_func.get_elements_by_xpath(
                all_lesson_title_list_xpath)

            lesson_detail_page_link = self.basic_func.get_target_link_element(
                all_lesson_title_lists_elem, lesson_detail_elem,
                block_page_text)

            self.driver_func.click_item(lesson_detail_page_link)

            self.driver_func.stop(2)

            self.go_to_lesson_list_page()
            self.go_to_advanced_lesson_list_page()

    def go_to_advanced_lesson_list_page(self):
        all_lesson_list = self.public_parts_xpath['all_lesson_list_xpath']
        all_lesson_list_link = self.public_parts_xpath[
            'all_lesson_list_link_xpath']
        all_lesson_lists_elem = self.driver_func.get_elements_by_xpath(
            all_lesson_list)
        all_lesson_lists_link_elem = self.driver_func.get_elements_by_xpath(
            all_lesson_list_link)
        #概要ページから該当する名前順にリンクの要素を取得
        link_elem = self.basic_func.get_target_link_element(
            all_lesson_lists_elem, all_lesson_lists_link_elem, '英語上級講座')

        #リンクを取得
        lesson_detail_link = self.driver_func.get_link(link_elem)

        #リンクに飛ぶ
        self.driver_func.move_to_page_by_link(self.chrome, lesson_detail_link)

    def check_lesson_overview_block_page(self):
        all_lesson_list = self.public_parts_xpath['all_lesson_list_xpath']
        all_lesson_list_link = self.public_parts_xpath[
            'all_lesson_list_link_xpath']

        self.driver_func.stop(2)
        all_lesson_lists_elem = self.driver_func.get_elements_by_xpath(
            all_lesson_list)
        all_lesson_lists_link_elem = self.driver_func.get_elements_by_xpath(
            all_lesson_list_link)

        #概要ページから該当する名前順にリンクの要素を取得
        link_elem = self.basic_func.get_target_link_element(
            all_lesson_lists_elem, all_lesson_lists_link_elem, '英語上級講座')

        #リンクを取得
        lesson_detail_link = self.driver_func.get_link(link_elem)

        #リンクに飛ぶ
        self.driver_func.move_to_page_by_link(self.chrome, lesson_detail_link)

    def set_user_status_to_gold(self, target_user_name):
        self.go_to_user_list_page()

        user_list_path = "//form/table[@class='wp-list-table widefat fixed striped users']/tbody[@id='the-list']/tr/td[@class='username column-username has-row-actions column-primary']/strong/a"
        users_lists_path = self.driver_func.get_elements_by_xpath(
            user_list_path)

        target_user_link = self.basic_func.get_target_element(
            users_lists_path, target_user_name)

        self.driver_func.click_item(target_user_link)

        self.driver_func.scroll_down(self.chrome)

        self.select_registered_status()

        self.select_gold_rank()

        submit_btn = "//p[@class='submit']/input[@id='submit']"

        submit_btn_elem = self.driver_func.get_element_by_xpath(submit_btn)

        self.driver_func.click_item(submit_btn_elem)

    def go_to_user_list_page(self):
        admin_user_list_page_path = self.admin_xpath_lists[
            'admin_user_list_page_path']
        admin_user_list_sub_page_path = self.admin_xpath_lists[
            'admin_user_list_sub_page_path']

        # ユーザー一覧ページへ移動
        self.driver_func.move_admin_page(admin_user_list_page_path,
                                         admin_user_list_sub_page_path)

    def select_registered_status(self):
        user_register_status_path = "//div[@id='wpbody-content']/div[@id='profile-page']/form[@id='your-profile']/table[@class='form-table'][6]/tbody/tr[2]/td/select[@id='user_status']"

        user_register_status_element = self.driver_func.get_element_by_xpath(
            user_register_status_path)
        self.driver_func.select_item_by_text(user_register_status_element,
                                             "本登録")

    def select_gold_rank(self):
        select_box_rank = "//div[@id='wpcontent']/div[@id='wpbody']/div[@id='wpbody-content']/div[@id='profile-page']/form[@id='your-profile']/table[@class='form-table'][8]/tbody/tr[1]/td/select[@id='gp_user_rank']"

        rank_select_element = self.driver_func.get_element_by_xpath(
            select_box_rank)
        self.driver_func.select_item_by_text(rank_select_element, "ゴールド会員")

    def go_to_admin_top_page(self, target_url):
        self.driver_func.move_to_page_by_link(self.chrome,
                                              target_url + 'wp-admin/')
class Admin_Lesson_Lock:

    def __init__(self, driver):

        self.chrome = driver
        self.driver_func = Driver_Action( driver )
        self.admin_xpath_list_func = Admin_Menu_Path()
        self.basic_func = Basic()
        # 管理画面のメニューのパスを返す
        self.admin_xpath_lists_xpath = self.admin_xpath_list_func.get_admin_menu_xpath()

        # 管理画面メニュー内の新規追加や編集などのパーツのパスを返す。
        self.admin_list_parts_xpath = self.admin_xpath_list_func.get_admin_menu_list_parts_xpath()

        # 管理画面内の項目に関するパス(作成した固定ページリストとか)
        self.admin_parts_xpath = self.admin_xpath_list_func.get_admin_parts()

        #ユーザー画面内の項目に関するパス
        self.public_parts_xpath = self.admin_xpath_list_func.get_public_parts()

        self.base_dir = self.basic_func.get_base_dir_path()


    def set_block_page( self ):

        lesson_details = {
            'beginner_lesson_details' : {
                'first_lesson_details' : {
                    'post_title' : '英語文法(初級講座)',
                    'page_lock' : '1',
                },
                'second_lesson_details' : {
                    'post_title' : '英語リスニング(初級講座)',
                    'page_lock' : '2',
                },
                'third_lesson_details' : {
                    'post_title' : '英語リーディング(初級講座)',
                    'page_lock' : '2',
                },
                'fourth_lesson_details' : {
                    'post_title' : '英語スピーキング(初級講座)',
                    'page_lock' : '2',
                },
                'fifth_lesson_details' : {
                    'post_title' : '英語単語(初級講座)',
                    'page_lock' : '2',
                }
            },
            'normal_lesson_details' : {
                'first_lesson_details' : {
                    'post_title' : '英語文法(中級講座)',
                    'page_lock' : '1',
                },
                'second_lesson_details' : {
                    'post_title' : '英語リスニング(中級講座)',
                    'page_lock' : '1',
                },
                'third_lesson_details' : {
                    'post_title' : '英語リーディング(中級講座)',
                    'page_lock' : '2',
                },
                'fourth_lesson_details' : {
                    'post_title' : '英語スピーキング(中級講座)',
                    'page_lock' : '2',
                },
                'fifth_lesson_details' : {
                    'post_title' : '英語単語(中級講座)',
                    'page_lock' : '1',
                }
            },
            'advanced_lesson_details' : {
                'first_lesson_details' : {
                    'post_title' : '英語文法(上級講座)',
                    'page_lock' : '1',
                },
                'second_lesson_details' : {
                    'post_title' : '英語リスニング(上級講座)',
                    'page_lock' : '2',
                },
                'third_lesson_details' : {
                    'post_title' : '英語リーディング(上級講座)',
                    'page_lock' : '1',
                },
                'fourth_lesson_details' : {
                    'post_title' : '英語スピーキング(上級講座)',
                    'page_lock' : '1',
                },
                'fifth_lesson_details' : {
                    'post_title' : '英語単語(上級講座)',
                    'page_lock' : '1',
                }
            }
        }

        lesson_details_test = {
            'beginner_lesson_details' : {
                'second_lesson_details' : {
                    'post_title' : '英語リスニング(初級講座)',
                    'page_lock' : '2',
                }
            }
        }

        page_list_xpath = self.admin_parts_xpath['page_list_xpath']
        page_list_elem = self.driver_func.get_elements_by_xpath( page_list_xpath )

        for details_item_name, details_item_value in lesson_details.items():
            for list_name,lesson_details_lists in details_item_value.items():
                self.add_info( lesson_details_lists )

    def add_info( self, lesson_details_lists ):

        page_list_xpath = self.admin_parts_xpath['page_list_xpath']
        page_list_elem = self.driver_func.get_elements_by_xpath( page_list_xpath )
        page_lock_radio_xpath = self.admin_parts_xpath['page_lock_radio_xpath']
        current_page_btn_xpath = self.admin_parts_xpath['current_page_btn_xpath']
        update_post_btn_xpath = self.admin_parts_xpath['update_post_btn']

        target_text = lesson_details_lists['post_title']

        target_elem = self.basic_func.get_target_element( page_list_elem, target_text )
        self.driver_func.click_item( target_elem )


        if( lesson_details_lists['page_lock'] == '2' ):
            self.driver_func.scroll_down( self.chrome )
            guild_press_lock_page_elem = self.driver_func.get_element_by_xpath( page_lock_radio_xpath )
            self.driver_func.click_item( guild_press_lock_page_elem )

        self.driver_func.scroll_top( self.chrome )

        update_post_btn_elem = self.driver_func.get_element_by_xpath( update_post_btn_xpath )
        self.driver_func.click_item( update_post_btn_elem )

        self.driver_func.stop( 1 )

        #投稿リストを表示する
        current_page_btn_elem = self.driver_func.get_element_by_xpath( current_page_btn_xpath )
        self.driver_func.click_item( current_page_btn_elem )
Ejemplo n.º 11
0
class Many_Lesson_Detail_Posts:

    def __init__(self, driver):
        self.chrome = driver
        self.driver_func = Driver_Action( driver )
        self.admin_xpath_list_func = Admin_Menu_Path()
        self.lesson_posts_xpath_list_func = Lesson_Posts_Path()
        self.basic_func = Basic()
        self.admin_xpath_lists_xpath = self.admin_xpath_list_func.get_admin_menu_xpath()
        self.admin_list_parts_xpath = self.admin_xpath_list_func.get_admin_menu_list_parts_xpath()
        self.admin_parts_xpath = self.admin_xpath_list_func.get_admin_parts()

    def add_lesson_detail_page(self):
        #ポストのタイトル、テキストのディレクトリ、カテゴリー名、アイキャッチ画像
        base_dir = self.basic_func.get_base_dir_path()

        self.lesson_posts_xpath_list_func.create_many_lesson_posts()
        lesson_details = self.lesson_posts_xpath_list_func.get_many_lesson_posts_path()

        #for list_loop_name,lesson_details_lists in lesson_overview.items():

        for list_name,lesson_details_lists in lesson_details.items():
            self.create_new_lesson_detail_page( lesson_details_lists )

    def create_new_lesson_detail_page( self, lesson_details_lists ):

        #要素を取得するためのXpathのリストを準備
        lesson_list_path = self.admin_xpath_lists_xpath['admin_guild_press_lesson_detail_list_page_path']
        add_new_lesson_list_path = self.admin_list_parts_xpath['add_new_page']

        #Xpathで、各要素を取得
        publish_post_btn = self.admin_parts_xpath['publish_post_btn']

        add_new_element = self.driver_func.get_element_by_xpath( add_new_lesson_list_path )

        #新規追加をクリックして、移動。
        self.driver_func.click_item(add_new_element)

        self.put_contents( lesson_details_lists )

        self.upload_img( lesson_details_lists )

        self.upload_thumbnail( lesson_details_lists )


        #公開ボタンを押す。
        self.driver_func.click_publish_btn()

        self.driver_func.stop(3)

        #一度他のページへ移動
        self.driver_func.move_admin_page( self.admin_xpath_lists_xpath['admin_main_setting_path'], self.admin_xpath_lists_xpath['admin_sub_setting_path'] )

        self.driver_func.move_admin_page( self.admin_xpath_lists_xpath['admin_guild_press_lesson_detail_page_path'], self.admin_xpath_lists_xpath['admin_guild_press_lesson_detail_list_page_path'] )

    def put_contents( self, lesson_details_lists ):
        #各要素を取得して、入力していく。
        post_title_element = self.driver_func.get_element_by_name( 'post_title' )
        self.driver_func.put_item_info( post_title_element, lesson_details_lists['post_title'] )

        #コンテンツを詰める
        content_html = self.driver_func.get_element_by_id('content-html')

        if( not content_html.is_selected() ) :
            self.driver_func.click_item( content_html )

        content_box_element = self.driver_func.get_element_by_name( 'content' )
        content_text = self.basic_func.get_file_text( lesson_details_lists['text_dir'] )
        self.driver_func.put_item_info( content_box_element, content_text )

        self.check_category_box( lesson_details_lists['category_name'] )


    def upload_img( self, lesson_details_lists ):
        media_input_file = self.admin_parts_xpath['media_input_file']

         #メディアを入れるためにボタンをクリックする。
        media_btn_html = self.driver_func.get_element_by_id('insert-media-button')
        self.driver_func.click_item( media_btn_html )

        #画像をアップロード
        img_btn_element = self.driver_func.get_element_by_xpath( media_input_file )
        self.driver_func.put_item_info( img_btn_element, lesson_details_lists['img_dir'] )


        #アップロードした後しばらく待つ。
        self.is_click_media_submit_btn()


    def is_click_media_submit_btn( self ):
        media_submit_btn = self.admin_parts_xpath['media_submit_btn']

        self.driver_func.stop(0.5)
        img_submit_element = self.driver_func.get_element_by_xpath( media_submit_btn )

        if( img_submit_element.is_enabled() ):
            self.driver_func.click_item( img_submit_element )

        else :
            self.is_click_media_submit_btn()


    def upload_thumbnail( self, lesson_details_lists ):
        media_input_file = self.admin_parts_xpath['media_input_file']
        media_add_eye_catch_btn = self.admin_parts_xpath['media_add_eye_catch_btn']
        #サムネイルを入れるためにボタンをクリックする。
        media_btn_html = self.driver_func.get_element_by_xpath( media_add_eye_catch_btn )
        self.driver_func.click_item( media_btn_html )

        #画像をアップロード
        img_btn_element = self.driver_func.get_element_by_xpath( media_input_file )
        self.driver_func.put_item_info( img_btn_element, lesson_details_lists['img_dir'] )

        #アップロードした後しばらく待つ。
        self.is_click_thumbnail_submit_btn()



    def is_click_thumbnail_submit_btn( self ):
        media_eye_catch_submit_btn = self.admin_parts_xpath['media_eye_catch_submit_btn']

        self.driver_func.stop(0.5)
        eye_chactch_submit_element = self.driver_func.get_element_by_xpath( media_eye_catch_submit_btn )

        if( eye_chactch_submit_element.is_enabled() ):
            print('is_click_thumbnail_submit_btn')
            self.driver_func.click_item( eye_chactch_submit_element )

        else :
            print('no is_click_thumbnail_submit_btn')
            self.is_click_thumbnail_submit_btn()





    def check_category_box( self, tareget_text ):

        cat_lists = '//ul[@id="guild_lesson_categorychecklist"]/li'
        cat_lists_check_box = '//ul[@id="guild_lesson_categorychecklist"]/li/label/input'

        category_list_element = self.driver_func.get_elements_by_xpath( cat_lists )
        category_box_element = self.driver_func.get_elements_by_xpath( cat_lists_check_box )

        for element, checkbox in zip( category_list_element, category_box_element ) :
            text = element.text

            if( text == tareget_text and not checkbox.is_selected() ):
                checkbox.click()
Ejemplo n.º 12
0
class Admin_News:

    def __init__(self, driver):

        self.chrome = driver
        self.driver_func = Driver_Action( driver )
        self.admin_xpath_list_func = Admin_Menu_Path()
        self.basic_func = Basic()
        # 管理画面のメニューのパスを返す
        self.admin_xpath_lists_xpath = self.admin_xpath_list_func.get_admin_menu_xpath()

        # 管理画面メニュー内の新規追加や編集などのパーツのパスを返す。
        self.admin_list_parts_xpath = self.admin_xpath_list_func.get_admin_menu_list_parts_xpath()

        # 管理画面内の項目に関するパス(作成した固定ページリストとか)
        self.admin_parts_xpath = self.admin_xpath_list_func.get_admin_parts()

        #ユーザー画面内の項目に関するパス
        self.public_parts_xpath = self.admin_xpath_list_func.get_public_parts()

        self.base_dir = self.basic_func.get_base_dir_path()

    def get_normal_short_code( self, content_elem ):

        #テキストエリアのテキストを改行でリスト方にする。
        content_texts = content_elem.text.splitlines()
        last_index = len(content_texts) - 1

        content_texts[last_index] = content_texts[last_index]+'\n'+'[guild_press_news posts_num="" title=""]'
        return content_texts

    def put_content( self, content_elem, content_texts ):

        for content_text in content_texts:
            self.driver_func.put_item_info( content_elem, content_text+'\n' )

    def add_news_code( self ):
        content_elem = self.driver_func.get_element_by_name( 'content' )
        #テキストエリアのテキストを改行でリスト方にする。
        content_texts = content_elem.text.splitlines()
        last_index = len(content_texts) - 1

        content_texts[last_index] = content_texts[last_index]+'\n'+'[guild_press_news posts_num="" title=""]'
        
        self.driver_func.clear_item_info( content_elem )
        self.put_content( content_elem, content_texts )
        self.submit()

    def submit( self ):
        update_post_btn_xpath = self.admin_parts_xpath['update_post_btn']
        update_post_btn_elem = self.driver_func.get_element_by_xpath( update_post_btn_xpath )

        self.driver_func.click_item( update_post_btn_elem )

    def add_three_news_code( self ):
        content_elem = self.driver_func.get_element_by_name( 'content' )

         #テキストエリアのテキストを改行でリスト方にする。
        content_texts = content_elem.text.splitlines()
        last_index = len(content_texts) - 1

        content_texts[last_index] = content_texts[last_index].replace('posts_num=""', 'posts_num="3"', 1)

        self.driver_func.clear_item_info( content_elem )
        self.put_content( content_elem, content_texts )
        self.submit()

    def add_test_title_news_code( self ):
        content_elem = self.driver_func.get_element_by_name( 'content' )

         #テキストエリアのテキストを改行でリスト方にする。
        content_texts = content_elem.text.splitlines()
        last_index = len(content_texts) - 1

        content_texts[last_index] = content_texts[last_index].replace('title=""', 'title="selnium_test"', 1)

        self.driver_func.clear_item_info( content_elem )
        self.put_content( content_elem, content_texts )
        self.submit()
class Create_Original_Form:

    def __init__(self, driver):
        self.chrome = driver
        self.driver_func = Driver_Action( driver )

    def click_submit_btn( self ):
        submit_input = self.chrome.find_element_by_name('submit')
        submit_input.click()

    #普通に登録
    def add_original_form_inputs( self ):

        dt_now = datetime.datetime.now()

        target_element = {
                'short_text' : {
                    'add_label' : 'ショートテキスト'+str( dt_now.microsecond ), 
                    'add_option' : 'short_text'+str( dt_now.microsecond ),
                    'add_type' : 'テキスト',
                    'add_display' : '',
                    'add_required' : '',
                },
                'text_area' : {
                    'add_label' : 'テキストエリア'+str( dt_now.microsecond ),
                    'add_option' : 'text_area'+str( dt_now.microsecond ),
                    'add_type' : 'テキストエリア',
                    'add_display' : '',
                    'add_required' : '',
                },
                'check_box' : {
                    'add_label' : 'チェックボックス', 
                    'add_option' : 'check_box'+str( dt_now.microsecond ),
                    'add_type' : 'チェックボックス',
                    'add_display' : '',
                    'add_required' : '',
                    'add_checked_default' : '',
                    'add_checked_value' : '1',
                },
                'select_box' : {
                    'add_label' : 'セレクトボックス'+str( dt_now.microsecond ),
                    'add_option' : 'select_box'+str( dt_now.microsecond ),
                    'add_type' : 'セレクトボックス',
                    'add_display' : '',
                    'add_required' : '',
                    'add_dropdown_value' : ''
                }
            }
     

        check_element_lists = ['add_display', 'add_checked_default']
        skip_elements = ['add_dropdown_value', 'add_checked_value']

        for input_name,input_value in target_element.items():
            for name,set_value in input_value.items():

                try:
                    target_input_element = self.driver_func.get_element_by_name( name )
                except NoSuchElementException:
                    continue

                if( name == 'add_type' ) :
                    #セレクトボックスの処理
                    self.driver_func.set_select_item( target_input_element, set_value )

                elif( name in check_element_lists ) :
                    #チェックボックスの処理
                    self.driver_func.click_item( target_input_element )

                elif( name in skip_elements ) :
                    #スキップする処理
                    continue

                else :
                    #普通に値を入力。
                    self.driver_func.put_item_info( target_input_element, set_value )


            filed_btn = '//table/tfoot/tr/td[@class="pt20"]/input[@id="add_field"][@value="フィールド追加"]'
            submit_btn = self.driver_func.get_element_by_xpath( filed_btn )
            self.driver_func.click_item( submit_btn )
class Public_Add_Quiz:
    def __init__(self, driver):

        self.chrome = driver
        self.driver_func = Driver_Action(driver)
        self.admin_xpath_list_func = Admin_Menu_Path()
        self.basic_func = Basic()
        # 管理画面のメニューのパスを返す
        self.admin_xpath_lists_xpath = self.admin_xpath_list_func.get_admin_menu_xpath(
        )

        # 管理画面メニュー内の新規追加や編集などのパーツのパスを返す。
        self.admin_list_parts_xpath = self.admin_xpath_list_func.get_admin_menu_list_parts_xpath(
        )

        # 管理画面内の項目に関するパス(作成した固定ページリストとか)
        self.admin_parts_xpath = self.admin_xpath_list_func.get_admin_parts()

        #ユーザー画面内の項目に関するパス
        self.public_parts_xpath = self.admin_xpath_list_func.get_public_parts()

        self.base_dir = self.basic_func.get_base_dir_path()

    def go_to_lesson_list_page(self):
        self.driver_func.go_to_public_nav_menu('動画一覧ページ')

    def go_to_element_lesson_list_page(self):
        all_lesson_list = self.public_parts_xpath['all_lesson_list_xpath']
        all_lesson_list_link = self.public_parts_xpath[
            'all_lesson_list_link_xpath']

        target_lesson_lists = {'英語初級講座', '英語中級講座', '英語上級講座'}

        for target_lesson_text in target_lesson_lists:

            all_lesson_lists_link_elem = self.driver_func.get_elements_by_xpath(
                all_lesson_list_link)
            all_lesson_lists_elem = self.driver_func.get_elements_by_xpath(
                all_lesson_list)

            #概要ページから該当する名前順にリンクの要素を取得
            link_elem = self.basic_func.get_target_link_element(
                all_lesson_lists_elem, all_lesson_lists_link_elem,
                target_lesson_text)

            #リンクを取得
            lesson_detail_link = self.driver_func.get_link(link_elem)

            #リンクに飛ぶ
            self.driver_func.move_to_page_by_link(self.chrome,
                                                  lesson_detail_link)

            self.driver_func.scroll_down(self.chrome)
            self.driver_func.scroll_top(self.chrome)

            self.go_to_first_lesson()

    def go_to_first_lesson(self):

        first_lesson_link = self.public_parts_xpath['first_lesson_link_xpath']
        #概要ページのすべてのレッスンを取得する
        first_lesson_elem = self.driver_func.get_elements_by_xpath(
            first_lesson_link)

        lesson_comp_btn = self.public_parts_xpath['lesson_comp_btn_xpath']

        try:
            lesson_elem = self.driver_func.get_elements_by_xpath(
                '//div[@id="lesson-list-box"]/div[@class="lesson-list-detail-box lesson-bg-lock"]'
            )
        except Exception as e:
            lesson_count = len(first_lesson_elem)
        else:
            lesson_count = len(first_lesson_elem) + len(lesson_elem)

        #最初のレッスンをクリックする。
        self.driver_func.click_item(first_lesson_elem[0])

        self.driver_func.stop(1)

        for x in range(lesson_count):

            try:
                lesson_comp_btn_elem = self.driver_func.get_element_by_xpath(
                    lesson_comp_btn)
                self.driver_func.click_item(lesson_comp_btn_elem)
            except Exception as e:
                self.progress_quiz()
            else:
                self.progress_btn()

        self.go_to_lesson_list_page()

    #通常のボタンクリックで、次のページへ進むタイプ
    def progress_btn(self):
        lesson_next_btn = self.public_parts_xpath['lesson_next_btn_xpath']
        #次のページへ進むが最後のページにはないので、それをチェックする。
        try:
            lesson_next_btn_elem = self.driver_func.get_element_by_xpath(
                lesson_next_btn)
            self.driver_func.click_item(lesson_next_btn_elem)
            self.driver_func.stop(1)
        except NoSuchElementException:
            pass

    #クイズに答える形式で、次のページへ進むタイプ
    def progress_quiz(self):
        lesson_quiz_lists_xpath = self.public_parts_xpath[
            'lesson_quiz_lists_xpath']
        send_answer_xpath = self.public_parts_xpath['send_answer_xpath']
        next_btn_xpath = self.public_parts_xpath['next_btn_xpath']

        lesson_quiz_lists_elem = self.driver_func.get_elements_by_xpath(
            lesson_quiz_lists_xpath)
        send_answer_elem = self.driver_func.get_element_by_xpath(
            send_answer_xpath)

        for x in range(0, len(lesson_quiz_lists_elem)):
            self.driver_func.click_item(lesson_quiz_lists_elem[x])
            self.driver_func.click_item(send_answer_elem)
            self.driver_func.stop(1)
            #正解して、次へ進むボタンが表示されるまでループを繰り返す。
            try:
                next_btn_elem = self.driver_func.get_element_by_xpath(
                    next_btn_xpath)
                self.driver_func.click_item(next_btn_elem)
            except Exception as e:
                pass
            else:
                break
        """
class Public_Lesson_Lock:
    def __init__(self, driver):

        self.chrome = driver
        self.driver_func = Driver_Action(driver)
        self.admin_xpath_list_func = Admin_Menu_Path()
        self.basic_func = Basic()
        # 管理画面のメニューのパスを返す
        self.admin_xpath_lists_xpath = self.admin_xpath_list_func.get_admin_menu_xpath(
        )

        # 管理画面メニュー内の新規追加や編集などのパーツのパスを返す。
        self.admin_list_parts_xpath = self.admin_xpath_list_func.get_admin_menu_list_parts_xpath(
        )

        # 管理画面内の項目に関するパス(作成した固定ページリストとか)
        self.admin_parts_xpath = self.admin_xpath_list_func.get_admin_parts()

        #ユーザー画面内の項目に関するパス
        self.public_parts_xpath = self.admin_xpath_list_func.get_public_parts()

        self.base_dir = self.basic_func.get_base_dir_path()

    def check_element_page(self):

        self.go_to_element_lesson_list_page()

        all_lesson_title_list_xpath = self.public_parts_xpath[
            'all_lesson_title_list_xpath']
        lesson_detail_link = self.public_parts_xpath['lesson_detail_lists']

        block_page_list = ['英語リスニング(初級講座)', '英語スピーキング(初級講座)']
        for block_page_text in block_page_list:
            lesson_detail_elem = self.driver_func.get_elements_by_xpath(
                lesson_detail_link)
            all_lesson_title_lists_elem = self.driver_func.get_elements_by_xpath(
                all_lesson_title_list_xpath)

            lesson_detail_page_link = self.basic_func.get_target_link_element(
                all_lesson_title_lists_elem, lesson_detail_elem,
                block_page_text)

            self.driver_func.click_item(lesson_detail_page_link)

            self.driver_func.stop(2)

            self.go_to_lesson_list_page()
            self.go_to_element_lesson_list_page()

    def go_to_lesson_list_page(self):
        self.driver_func.go_to_public_nav_menu('動画一覧ページ')

    def go_to_element_lesson_list_page(self):
        all_lesson_list = self.public_parts_xpath['all_lesson_list_xpath']
        all_lesson_list_link = self.public_parts_xpath[
            'all_lesson_list_link_xpath']

        target_lesson_lists = {'英語初級講座', '英語中級講座', '英語上級講座'}

        for target_lesson_text in target_lesson_lists:

            all_lesson_lists_link_elem = self.driver_func.get_elements_by_xpath(
                all_lesson_list_link)
            all_lesson_lists_elem = self.driver_func.get_elements_by_xpath(
                all_lesson_list)

            #概要ページから該当する名前順にリンクの要素を取得
            link_elem = self.basic_func.get_target_link_element(
                all_lesson_lists_elem, all_lesson_lists_link_elem,
                target_lesson_text)

            #リンクを取得
            lesson_detail_link = self.driver_func.get_link(link_elem)

            #リンクに飛ぶ
            self.driver_func.move_to_page_by_link(self.chrome,
                                                  lesson_detail_link)

            self.driver_func.scroll_down(self.chrome)
            self.driver_func.scroll_top(self.chrome)

            self.go_to_first_lesson()

    def go_to_first_lesson(self):

        first_lesson_link = self.public_parts_xpath['first_lesson_link_xpath']

        #概要ページのすべてのレッスンを取得する
        first_lesson_elem = self.driver_func.get_elements_by_xpath(
            first_lesson_link)

        lesson_comp_btn = self.public_parts_xpath['lesson_comp_btn_xpath']
        lesson_next_btn = self.public_parts_xpath['lesson_next_btn_xpath']

        try:
            lesson_elem = self.driver_func.get_elements_by_xpath(
                '//div[@id="lesson-list-box"]/div[@class="lesson-list-detail-box lesson-bg-lock"]'
            )
        except Exception as e:
            lesson_count = len(first_lesson_elem)
        else:
            lesson_count = len(first_lesson_elem) + len(lesson_elem)

        #最初のレッスンをクリックする。
        self.driver_func.click_item(first_lesson_elem[0])

        self.driver_func.stop(1)

        #レッスンの総数分だけ、レッスン完了をクリックして、レッスンを完了していく。
        for i in range(lesson_count):
            lesson_comp_btn_elem = self.driver_func.get_element_by_xpath(
                lesson_comp_btn)
            self.driver_func.click_item(lesson_comp_btn_elem)

            #次のページへ進むが最後のページにはないので、それをチェックする。
            try:
                lesson_next_btn_elem = self.driver_func.get_element_by_xpath(
                    lesson_next_btn)
                self.driver_func.click_item(lesson_next_btn_elem)
            except NoSuchElementException:
                pass

        self.go_to_lesson_list_page()
Ejemplo n.º 16
0
    def check_block_page_by_paypal_regsiter(self):

        ##今度はゴールド会員として登録して表示をチェックするためにゴールド会員のページを作成
        self.go_to_paypal_setting_page()

        #新しくPayPalの設定を作成
        self.paypal_add_new_func.go_to_pay_pal_register_page()

        self.paypal_add_new_func.add_member_subscription_payment()

        payapl_short_code = self.paypal_carete_page_func.get_new_pay_pal_short_code(
        )

        #固定ページ一覧に移動
        self.go_page_list()

        self.driver_action_func.go_to_add_new_page()

        self.paypal_carete_page_func.create_member_subscription_page(
            payapl_short_code)

        #公開ボタンをクリックする。
        self.driver_action_func.click_publish_btn()

        paypal_page_link = self.driver_action_func.edit_page_link()

        new_paypal_register_driver = webdriver.Chrome(
            ChromeDriverManager().install())
        new_paypal_register_driver.get(paypal_page_link)

        ##今度はゴールド会員として登録して表示をチェックする。
        # 新しいブラウザでインスタンス作成
        paypal_register_func = Test_User_Normal_Register(
            new_paypal_register_driver)
        paypal_register_func.nomarl_put_user_info_to_form()

        payment_register_func = Test_User_Payment_Register(
            new_paypal_register_driver)
        payment_register_func.click_register_page_pay_pal_btn()
        #payment_register_func.click_new_register_page_pay_pal_btn()

        #新しく
        new_paypal_lesson_progress_func = Lesson_Progress(
            new_paypal_register_driver)
        new_paypal_lesson_progress_func.go_to_lesson_list_page()

        #ドライバーを新しくして、またインスタンス作成
        public_member_rank_func = Public_Member_Rank(
            new_paypal_register_driver)

        result = public_member_rank_func.check_is_user_get_ranked()

        if (result == False):
            another_driver_action_func = Driver_Action(
                new_paypal_register_driver)
            xpath = "//ul[@id='wp-admin-bar-top-secondary']/li[@id='wp-admin-bar-my-account']/div[@class='ab-sub-wrapper']/ul[@id='wp-admin-bar-user-actions']/li[@id='wp-admin-bar-user-info']/a[@class='ab-item']/span[@class='display-name']"
            target_user_name = another_driver_action_func.get_element_by_xpath(
                xpath).get_attribute("innerHTML")

            #admin側を動かすために、あどみん側のドライバーを渡す。
            paypal_admin_member_rank_func = Public_Member_Rank(self.chrome)

            paypal_admin_member_rank_func.set_user_status_to_gold(
                target_user_name)

            paypal_admin_member_rank_func.go_to_admin_top_page(self.target_url)

            public_member_rank_func.go_to_lesson_list_page()

        public_member_rank_func.check_lesson_overview_block_page()

        self.driver_action_func.stop(2)

        self.driver_action_func.quit(new_paypal_register_driver)
class Admin_Many_Calendar:
    def __init__(self, driver):

        self.chrome = driver
        self.driver_func = Driver_Action(driver)
        self.admin_xpath_list_func = Admin_Menu_Path()
        self.basic_func = Basic()
        # 管理画面のメニューのパスを返す
        self.admin_xpath_lists_xpath = self.admin_xpath_list_func.get_admin_menu_xpath(
        )

        # 管理画面メニュー内の新規追加や編集などのパーツのパスを返す。
        self.admin_list_parts_xpath = self.admin_xpath_list_func.get_admin_menu_list_parts_xpath(
        )

        # 管理画面内の項目に関するパス(作成した固定ページリストとか)
        self.admin_parts_xpath = self.admin_xpath_list_func.get_admin_parts()

        self.base_dir = self.basic_func.get_base_dir_path()

    def create_public_calendar_page(self):

        page_lists = self.driver_func.get_elements_by_xpath(
            self.admin_parts_xpath['page_list_xpath'])

        is_page_created = self.basic_func.check_page_is_created(
            'カレンダーページ', page_lists)

        return is_page_created

    def go_to_register_calendar_list_page(self):
        guild_press_register_calendar_elements = self.driver_func.get_elements_by_xpath(
            self.admin_parts_xpath['guild_press_tab_xpath'])

        self.driver_func.click_item(guild_press_register_calendar_elements[1])

    def go_to_register_calendar_page(self, target_calendar_xpath):

        try:
            register = self.driver_func.get_element_by_xpath(
                target_calendar_xpath)
        except Exception as e:
            return False
        else:
            self.driver_func.click_item(register)
            return True

    def go_to_calendar_email_page(self):

        guild_press_register_calendar_elements = self.driver_func.get_elements_by_xpath(
            self.admin_parts_xpath['guild_press_tab_xpath'])

        self.driver_func.click_item(guild_press_register_calendar_elements[2])

    def put_calendar_info(self):
        dt_now = datetime.datetime.now()

        calendar_title_element = self.driver_func.get_element_by_name('title')
        self.driver_func.put_item_info(calendar_title_element,
                                       'カレンダー予約' + str(dt_now.microsecond))

        calendar_max_element = self.driver_func.get_element_by_name('max_num')
        self.driver_func.put_item_info(calendar_max_element, '4')

        calendar_date_time1_element = self.driver_func.get_element_by_name(
            'date_time1')
        self.driver_func.put_item_info(calendar_date_time1_element, '10:00')

        calendar_date_time2_element = self.driver_func.get_element_by_name(
            'date_time2')
        self.driver_func.put_item_info(calendar_date_time2_element, '19:00')

        submit_btn_element = self.driver_func.get_element_by_name('submit')
        self.driver_func.click_item(submit_btn_element)

        return 'カレンダー予約' + str(dt_now.microsecond)

    def put_calendar_email_info(self):

        self.put_calendar_email_user_info()

        self.put_calendar_email_admin_info()

        submit_btn_element = self.driver_func.get_element_by_name('submit')
        self.driver_func.click_item(submit_btn_element)

    def put_calendar_email_user_info(self):

        guild_press_personal_from_name = self.driver_func.get_element_by_name(
            'guild_press_personal_from_name')
        self.driver_func.clear_item_info(guild_press_personal_from_name)
        self.driver_func.put_item_info(guild_press_personal_from_name,
                                       'ユーザー側カレンダーテスト')

        guild_press_personal_from_email = self.driver_func.get_element_by_name(
            'guild_press_personal_from_email')
        self.driver_func.clear_item_info(guild_press_personal_from_email)
        self.driver_func.put_item_info(guild_press_personal_from_email,
                                       'メールアドレス記載')

        guild_press_personal_from_cc_email = self.driver_func.get_element_by_name(
            'guild_press_personal_CC_email')
        self.driver_func.clear_item_info(guild_press_personal_from_cc_email)
        self.driver_func.put_item_info(guild_press_personal_from_cc_email,
                                       'メールアドレス記載')

        guild_press_personal_from_bcc_email = self.driver_func.get_element_by_name(
            'guild_press_personal_BCC_email')
        self.driver_func.clear_item_info(guild_press_personal_from_bcc_email)
        self.driver_func.put_item_info(guild_press_personal_from_bcc_email,
                                       'メールアドレス記載')

        guild_press_personal_from_subject_email = self.driver_func.get_element_by_name(
            'guild_press_personal_from_subject')
        self.driver_func.clear_item_info(
            guild_press_personal_from_subject_email)
        self.driver_func.put_item_info(guild_press_personal_from_subject_email,
                                       'メールテスト(ユーザー側)')

        guild_press_personal_from_text_email = self.driver_func.get_element_by_name(
            'guild_press_personal_email_message')
        self.driver_func.clear_item_info(guild_press_personal_from_text_email)
        content_text = self.basic_func.get_file_text(
            self.base_dir + '/assets/texts/calendar/calendar_email_user.txt')
        self.driver_func.put_item_info(guild_press_personal_from_text_email,
                                       content_text)

    def put_calendar_email_admin_info(self):

        guild_press_admin_from_text_name = self.driver_func.get_element_by_name(
            'guild_press_admin_from_name')
        self.driver_func.clear_item_info(guild_press_admin_from_text_name)
        self.driver_func.put_item_info(guild_press_admin_from_text_name,
                                       'ユーザー側カレンダーテスト')

        guild_press_admin_from_email = self.driver_func.get_element_by_name(
            'guild_press_admin_from_email')
        self.driver_func.clear_item_info(guild_press_admin_from_email)
        self.driver_func.put_item_info(guild_press_admin_from_email,
                                       'メールアドレス記載')

        guild_press_admin_from_cc_email = self.driver_func.get_element_by_name(
            'guild_press_admin_CC_email')
        self.driver_func.clear_item_info(guild_press_admin_from_cc_email)
        self.driver_func.put_item_info(guild_press_admin_from_cc_email,
                                       'メールアドレス記載')

        guild_press_admin_from_bcc_email = self.driver_func.get_element_by_name(
            'guild_press_admin_BCC_email')
        self.driver_func.clear_item_info(guild_press_admin_from_bcc_email)
        self.driver_func.put_item_info(guild_press_admin_from_bcc_email,
                                       'メールアドレス記載')

        guild_press_admin_from_subject_email = self.driver_func.get_element_by_name(
            'guild_press_admin_from_subject')
        self.driver_func.clear_item_info(guild_press_admin_from_subject_email)
        self.driver_func.put_item_info(guild_press_admin_from_subject_email,
                                       'ユーザーイベント登録メール(管理者側)')

        guild_press_admin_from_admin_email = self.driver_func.get_element_by_name(
            'guild_press_admin_email_message')
        self.driver_func.clear_item_info(guild_press_admin_from_admin_email)
        content_text = self.basic_func.get_file_text(
            self.base_dir + '/assets/texts/calendar/calendar_email_admin.txt')
        self.driver_func.put_item_info(guild_press_admin_from_admin_email,
                                       content_text)

    def edit_calendar_info(self, target_title):
        dt_now = datetime.datetime.now()

        calendar_title_element = self.driver_func.get_element_by_name('title')
        self.driver_func.clear_item_info(calendar_title_element)
        self.driver_func.put_item_info(calendar_title_element, target_title)

        calendar_max_element = self.driver_func.get_element_by_name('max_num')
        self.driver_func.clear_item_info(calendar_max_element)
        self.driver_func.put_item_info(calendar_max_element, '5')

        calendar_date_time1_element = self.driver_func.get_element_by_name(
            'date_time1')
        self.driver_func.clear_item_info(calendar_date_time1_element)
        self.driver_func.put_item_info(calendar_date_time1_element, '12:00')

        calendar_date_time2_element = self.driver_func.get_element_by_name(
            'date_time2')
        self.driver_func.clear_item_info(calendar_date_time2_element)
        self.driver_func.put_item_info(calendar_date_time2_element, '22:00')

        submit_btn_element = self.driver_func.get_element_by_name('submit')
        self.driver_func.click_item(submit_btn_element)

    #put_calendar_infoで作ったやつを編集するために、リンクを探してクリックする。
    def edit_calendar_info_page(self, target_title):
        guild_press_register_calendar_elements = self.driver_func.get_elements_by_xpath(
            '//div[@class="reservation-view"]/a[@class="calendar-title"]')
        for calendar_title_element in guild_press_register_calendar_elements:

            if (target_title == calendar_title_element.text):
                self.driver_func.click_item(calendar_title_element)
                self.edit_calendar_info(target_title)
Ejemplo n.º 18
0
class Many_Lesson_Progress:
    def __init__(self, driver):

        self.chrome = driver
        self.driver_func = Driver_Action(driver)
        self.admin_xpath_list_func = Admin_Menu_Path()
        self.lesson_progress_xpath_list_func = Lesson_Progress_Path()
        self.basic_func = Basic()
        # 管理画面のメニューのパスを返す
        self.admin_xpath_lists_xpath = self.admin_xpath_list_func.get_admin_menu_xpath(
        )

        # 管理画面メニュー内の新規追加や編集などのパーツのパスを返す。
        self.admin_list_parts_xpath = self.admin_xpath_list_func.get_admin_menu_list_parts_xpath(
        )

        # 管理画面内の項目に関するパス(作成した固定ページリストとか)
        self.admin_parts_xpath = self.admin_xpath_list_func.get_admin_parts()

        #ユーザー側の画面のメニューとか、動画一覧などのパーツ
        self.public_parts_xpath = self.admin_xpath_list_func.get_public_parts()

        self.base_dir = self.basic_func.get_base_dir_path()

        self.lesson_list_page_url = self.basic_func.get_lesson_list_page()

    def go_to_lesson_list_page(self):
        print('go_to_lesson_list_page')
        self.driver_func.move_to_page_by_link(self.chrome,
                                              self.lesson_list_page_url)

    def progress_each_lesson(self):

        all_lesson_list = self.public_parts_xpath['all_lesson_list_xpath']
        all_lesson_list_link = self.public_parts_xpath[
            'all_lesson_list_link_xpath']

        first_lesson_link = self.public_parts_xpath['first_lesson_link_xpath']

        lesson_comp_btn = self.public_parts_xpath['lesson_comp_btn_xpath']
        lesson_next_btn = self.public_parts_xpath['lesson_next_btn_xpath']

        self.lesson_progress_xpath_list_func.create_many_lesson_posts()
        target_lesson_lists = self.lesson_progress_xpath_list_func.get_many_target_lesson_lists_path(
        )

        for target_lesson_text in target_lesson_lists:

            self.driver_func.stop(1)
            all_lesson_lists_elem = self.driver_func.get_elements_by_xpath(
                all_lesson_list)
            all_lesson_lists_link_elem = self.driver_func.get_elements_by_xpath(
                all_lesson_list_link)
            #概要ページから該当する名前順にリンクの要素を取得
            link_elem = self.basic_func.get_target_link_element(
                all_lesson_lists_elem, all_lesson_lists_link_elem,
                target_lesson_text)

            #リンクを取得
            lesson_detail_link = self.driver_func.get_link(link_elem)

            #リンクに飛ぶ
            self.driver_func.move_to_page_by_link(self.chrome,
                                                  lesson_detail_link)

            #概要ページのすべてのレッスンを取得する
            first_lesson_elem = self.driver_func.get_elements_by_xpath(
                first_lesson_link)

            #最初のレッスンをクリックする。
            self.driver_func.click_item(first_lesson_elem[0])

            self.driver_func.stop(1)

            #レッスンの総数分だけ、レッスン完了をクリックして、レッスンを完了していく。
            for i in range(len(first_lesson_elem)):
                lesson_comp_btn_elem = self.driver_func.get_element_by_xpath(
                    lesson_comp_btn)
                self.driver_func.click_item(lesson_comp_btn_elem)

                #次のページへ進むが最後のページにはないので、それをチェックする。
                try:
                    lesson_next_btn_elem = self.driver_func.get_element_by_xpath(
                        lesson_next_btn)
                    self.driver_func.click_item(lesson_next_btn_elem)
                except NoSuchElementException:
                    print('none')

            self.driver_func.move_to_page_by_link(self.chrome,
                                                  self.lesson_list_page_url)
class Admin_Texts_Docs:
    def __init__(self, driver):

        self.chrome = driver
        self.driver_func = Driver_Action(driver)
        self.admin_xpath_list_func = Admin_Menu_Path()
        self.basic_func = Basic()
        # 管理画面のメニューのパスを返す
        self.admin_xpath_lists_xpath = self.admin_xpath_list_func.get_admin_menu_xpath(
        )

        # 管理画面メニュー内の新規追加や編集などのパーツのパスを返す。
        self.admin_list_parts_xpath = self.admin_xpath_list_func.get_admin_menu_list_parts_xpath(
        )

        # 管理画面内の項目に関するパス(作成した固定ページリストとか)
        self.admin_parts_xpath = self.admin_xpath_list_func.get_admin_parts()

        #ユーザー画面内の項目に関するパス
        self.public_parts_xpath = self.admin_xpath_list_func.get_public_parts()

        self.base_dir = self.basic_func.get_base_dir_path()

    def add_texts_docs_info(self):

        texts_docs_lists = {
            'beginner_texts_docs': {
                'first_texts_docs': {
                    'text_title': '英語文法(初級講座)教材',
                    'category_name': '英語初級講座',
                    'img_dir':
                    self.base_dir + '/assets/texts_docs/english-grammer.pdf',
                    'page_block': '2'
                },
                'second_texts_docs': {
                    'text_title': '英語リスニング(初級講座)教材',
                    'category_name': '英語初級講座',
                    'img_dir':
                    self.base_dir + '/assets/texts_docs/english-listening.pdf',
                    'page_block': '1'
                },
                'third_texts_docs': {
                    'text_title': '英語リーディング(初級講座)教材',
                    'category_name': '英語初級講座',
                    'img_dir':
                    self.base_dir + '/assets/texts_docs/english-reading.pdf',
                    'page_block': '2'
                },
                'fourth_texts_docs': {
                    'text_title': '英語スピーキング(初級講座)教材',
                    'category_name': '英語初級講座',
                    'img_dir':
                    self.base_dir + '/assets/texts_docs/english-speaking.pdf',
                    'page_block': '2'
                },
                'fifth_texts_docs': {
                    'text_title': '英語単語(初級講座)教材',
                    'category_name': '英語初級講座',
                    'img_dir':
                    self.base_dir + '/assets/texts_docs/english-words.pdf',
                    'page_block': '1'
                }
            },
            'normal_texts_docs': {
                'first_texts_docs': {
                    'text_title': '英語文法(中級講座)教材',
                    'category_name': '英語中級講座',
                    'img_dir':
                    self.base_dir + '/assets/texts_docs/english-grammer.pdf',
                    'page_block': '2'
                },
                'second_texts_docs': {
                    'text_title': '英語リスニング(中級講座)教材',
                    'category_name': '英語中級講座',
                    'img_dir':
                    self.base_dir + '/assets/texts_docs/english-listening.pdf',
                    'page_block': '1'
                },
                'third_texts_docs': {
                    'text_title': '英語リーディング(中級講座)教材',
                    'category_name': '英語中級講座',
                    'img_dir':
                    self.base_dir + '/assets/texts_docs/english-reading.pdf',
                    'page_block': '2'
                },
                'fourth_texts_docs': {
                    'text_title': '英語スピーキング(中級講座)教材',
                    'category_name': '英語中級講座',
                    'img_dir':
                    self.base_dir + '/assets/texts_docs/english-speaking.pdf',
                    'page_block': '2'
                },
                'fifth_texts_docs': {
                    'text_title': '英語単語(中級講座)教材',
                    'category_name': '英語中級講座',
                    'img_dir':
                    self.base_dir + '/assets/texts_docs/english-words.pdf',
                    'page_block': '1'
                }
            },
            'advanced_texts_docs': {
                'first_texts_docs': {
                    'text_title': '英語文法(上級講座)教材',
                    'category_name': '英語上級講座',
                    'img_dir':
                    self.base_dir + '/assets/texts_docs/english-grammer.pdf',
                    'page_block': '2'
                },
                'second_texts_docs': {
                    'text_title': '英語リスニング(上級講座)教材',
                    'category_name': '英語上級講座',
                    'img_dir':
                    self.base_dir + '/assets/texts_docs/english-listening.pdf',
                    'page_block': '1'
                },
                'third_texts_docs': {
                    'text_title': '英語リーディング(上級講座)教材',
                    'category_name': '英語上級講座',
                    'img_dir':
                    self.base_dir + '/assets/texts_docs/english-reading.pdf',
                    'page_block': '2'
                },
                'fourth_texts_docs': {
                    'text_title': '英語スピーキング(上級講座)教材',
                    'category_name': '英語上級講座',
                    'img_dir':
                    self.base_dir + '/assets/texts_docs/english-speaking.pdf',
                    'page_block': '2'
                },
                'fifth_texts_docs': {
                    'text_title': '英語単語(上級講座)教材',
                    'category_name': '英語上級講座',
                    'img_dir':
                    self.base_dir + '/assets/texts_docs/english-words.pdf',
                    'page_block': '1'
                }
            }
        }

        texts_docs_lists_test = {
            'beginner_texts_docs': {
                'first_texts_docs': {
                    'text_title': '英語文法(初級講座)教材',
                    'category_name': '英語初級講座',
                    'img_dir':
                    self.base_dir + '/assets/texts_docs/english-grammer.pdf',
                    'page_block': '2'
                },
            }
        }

        for texts_docs_lists_name, texts_docs_lists_value in texts_docs_lists.items(
        ):
            for list_name, text_docs_lists in texts_docs_lists_value.items():
                self.add_info(text_docs_lists)

    def add_info(self, text_docs_lists):

        new_btn_xpath = self.admin_list_parts_xpath['add_new_texts_page']
        submit_btn_xpath = self.admin_parts_xpath[
            'guild_press_text_docs_submit_xpath']

        new_btn_elem = self.driver_func.get_element_by_xpath(new_btn_xpath)
        self.driver_func.click_item(new_btn_elem)

        post_title_elem = self.driver_func.get_element_by_name('gp_post_title')
        self.driver_func.put_item_info(post_title_elem,
                                       text_docs_lists['text_title'])

        self.upload_texts_docs(text_docs_lists)

        self.add_category(text_docs_lists)

        submit_btn_element = self.driver_func.get_element_by_xpath(
            submit_btn_xpath)
        self.driver_func.click_item(submit_btn_element)

    def add_category(self, text_docs_lists):
        radio_btn_xpath = self.admin_parts_xpath[
            'guild_press_text_docs_rank_block_xpath']
        check_box_xpath = self.admin_parts_xpath[
            'guild_press_text_docs_rank_check_box_xpath']
        label_xpath = self.admin_parts_xpath[
            'guild_press_text_docs_rank_label_xpath']

        texts_docs_btn_elem = self.driver_func.get_element_by_name(
            'gp_lesson_category')
        self.driver_func.set_select_item(texts_docs_btn_elem,
                                         text_docs_lists['category_name'])

        if (text_docs_lists['page_block'] == '2'):
            guild_press_page_block_elem = self.driver_func.get_element_by_xpath(
                radio_btn_xpath)
            self.driver_func.click_item(guild_press_page_block_elem)

            block_check_elem = self.driver_func.get_elements_by_xpath(
                check_box_xpath)
            label_elem = self.driver_func.get_elements_by_xpath(label_xpath)

            link_elem = self.basic_func.get_target_link_element(
                label_elem, block_check_elem, 'ゴールド会員')
            self.driver_func.click_item(link_elem)

        elif (text_docs_lists['page_block'] == '1'):
            pass

    def upload_texts_docs(self, text_docs_lists):

        texts_docs_btn_elem = self.driver_func.get_element_by_name('csv')
        self.driver_func.click_item(texts_docs_btn_elem)

        media_input_file = self.admin_parts_xpath['media_input_file']
        #画像をアップロード
        img_btn_element = self.driver_func.get_element_by_xpath(
            media_input_file)
        self.driver_func.put_item_info(img_btn_element,
                                       text_docs_lists['img_dir'])

        #教材のアップロードが完了できているかチェックする、
        self.is_click_media_submit_btn()

    def is_click_media_submit_btn(self):
        texts_docs_submit_btn = self.admin_parts_xpath['texts_docs_submit_btn']

        self.driver_func.stop(2)
        img_submit_element = self.driver_func.get_element_by_xpath(
            texts_docs_submit_btn)

        if (img_submit_element.is_enabled()):
            self.driver_func.click_item(img_submit_element)

        else:
            self.is_click_media_submit_btn()

    def get_dwd_show_shortcode(self):
        show_short_code_xpath = self.admin_parts_xpath[
            'guild_press_text_docs_show_shortcode_xpath']
        dwd_short_code_xpath = self.admin_parts_xpath[
            'guild_press_text_docs_dwd_shortcode_xpath']

        show_short_elem = self.driver_func.get_element_by_xpath(
            show_short_code_xpath)
        dwd_short_elem = self.driver_func.get_element_by_xpath(
            dwd_short_code_xpath)

        short_codes = {
            'show_shortcode': show_short_elem.text,
            'dwd_shortcode': dwd_short_elem.text,
        }

        return short_codes

    def put_short_codes_to_lesson_detail(self, texts_docs_shortcodes):

        show_shortcode = texts_docs_shortcodes['show_shortcode']
        dwd_shortcode = texts_docs_shortcodes['dwd_shortcode']

        first_lesson_detail_xpath = self.admin_parts_xpath[
            'guild_press_first_lesson_detail']
        first_lesson_detail_elem = self.driver_func.get_element_by_xpath(
            first_lesson_detail_xpath)

        self.driver_func.click_item(first_lesson_detail_elem)

        content_elem = self.driver_func.get_element_by_name('content')

        #テキストエリアのテキストを改行でリスト方にする。
        content_texts = content_elem.text.splitlines()
        last_index = len(content_texts) - 1

        content_texts[
            last_index] = show_shortcode + '\n' + dwd_shortcode + '\n' + content_texts[
                last_index]

        self.driver_func.clear_item_info(content_elem)

        for content_text in content_texts:
            self.driver_func.put_item_info(content_elem, content_text + '\n')

        # update_post_btn_xpath = self.admin_parts_xpath['update_post_btn']
        # update_post_btn_elem = self.driver_func.get_element_by_xpath( update_post_btn_xpath )
        # self.driver_func.click_item( update_post_btn_elem )

        self.driver_func.click_update_btn()

        #貼り付けたショートコードの確認
        self.go_to_short_codes_page()

    def go_to_short_codes_page(self):

        post_permalink_xpath = self.admin_parts_xpath['post_permalink']
        post_permalink_elem = self.driver_func.get_element_by_xpath(
            post_permalink_xpath)
        self.driver_func.click_item(post_permalink_elem)

        # スクールダウンして表示を確認する。
        self.driver_func.scroll_down(self.chrome)

        dwd_btn_xpath = self.public_parts_xpath['dwd_btn_xpath']
        dwd_btn_elem = self.driver_func.get_element_by_xpath(dwd_btn_xpath)

        self.driver_func.click_item(dwd_btn_elem)