class PayPal_User_Register_Controller: def __init__(self, driver, target_url): self.chrome = driver self.target_url = target_url self.admin_xpath_list_func = Admin_Menu_Path() self.basic_func = Basic() self.driver_action_func = Driver_Action(driver) self.paypal_add_new_func = Pay_Pal_Add_New_One(driver) self.paypal_carete_page_func = Pay_Pal_Create_Page(driver) # 管理画面のメニューのパスを返す 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( ) def start(self): #PayPal設定ページに移動 self.go_to_paypal_setting_page() #PayPalボタン作成画面に移動 self.paypal_add_new_func.go_to_pay_pal_register_page() #継続課金のボタン作成 self.paypal_add_new_func.add_normal_subscription_payment() payapl_short_code = self.paypal_carete_page_func.get_new_pay_pal_short_code( ) #固定ページ一覧に移動 self.go_to_page_list() #新規追加ページへ移動 self.driver_action_func.go_to_add_new_page() #ペイパルのページを作成 self.paypal_carete_page_func.create_normal_subscription_page( payapl_short_code) #公開ボタンをクリックする。 self.driver_action_func.click_publish_btn() #ペイパルのテスト self.test_pay_pal_regsiter() #トップページへ移動 self.go_to_admin_top_page() def test_pay_pal_regsiter(self): 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() self.driver_action_func.quit(new_paypal_register_driver) def go_to_paypal_setting_page(self): admin_guild_press_page_path = self.admin_xpath_lists[ 'admin_guild_press_page_path'] admin_guild_press_paypal_page_path = self.admin_xpath_lists[ 'admin_guild_press_paypal_page_path'] self.driver_action_func.move_admin_page( admin_guild_press_page_path, admin_guild_press_paypal_page_path) def go_to_admin_top_page(self): self.driver_action_func.move_to_page_by_link( self.chrome, self.target_url + 'wp-admin/') def go_to_page_list(self): admin_page_path = self.admin_xpath_lists['admin_page_path'] admin_list_page_path = self.admin_xpath_lists['admin_list_page_path'] self.driver_action_func.move_admin_page(admin_page_path, admin_list_page_path)
class Admin_Calendar_Controller: def __init__(self, driver, target_url): self.chrome = driver self.target_url = target_url self.admin_xpath_list_func = Admin_Menu_Path() self.basic_func = Basic() self.driver_action_func = Driver_Action(driver) self.admin_calendar_func = Admin_Calendar(driver) self.init_settings_func = Init_Settings(driver) self.calendar_title = '' # 管理画面のメニューのパスを返す 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( ) def start(self): #固定ページ一覧へ移動 self.go_to_page_list() #カレンダーの固定ページが作成されているチェックする。 is_page_created = self.admin_calendar_func.create_public_calendar_page( ) if not is_page_created: #カレンダーページ作成 self.driver_action_func.go_to_add_new_page() self.init_settings_func.create_new_guild_press_shortcode_page( 'カレンダーページ', '[guild_press_calender]') self.driver_action_func.click_publish_btn() # カレンダー一覧ページへ移動する。 self.go_to_calendar_page() # カレンダー登録ページへ移動する self.admin_calendar_func.go_to_register_calendar_page() #カレンダー登録ページへカレンダー情報を入力. self.calendar_title = self.admin_calendar_func.put_calendar_info() #カレンダー編集ページへ移動する self.admin_calendar_func.edit_calendar_info_page(self.calendar_title) # カレンダーメール編集ページへ移動する。 self.admin_calendar_func.go_to_calendar_email_page() # カレンダーメールの内容を入力する。 self.admin_calendar_func.put_calendar_email_info() #トップページへ戻る self.go_to_admin_top_page() def get_calendar_title(self): return self.calendar_title def go_to_page_list(self): admin_page_path = self.admin_xpath_lists['admin_page_path'] admin_list_page_path = self.admin_xpath_lists['admin_list_page_path'] self.driver_action_func.move_admin_page(admin_page_path, admin_list_page_path) def go_to_calendar_page(self): lesson_detail_page_path = self.admin_xpath_lists[ 'admin_guild_press_lesson_detail_page_path'] calendar_page_path = self.admin_xpath_lists[ 'admin_guild_press_lesson_calendar_page_path'] self.driver_action_func.move_admin_page(lesson_detail_page_path, calendar_page_path) def go_to_admin_top_page(self): self.driver_action_func.move_to_page_by_link( self.chrome, self.target_url + 'wp-admin/')
class Member_Rank_OverView_Controller: def __init__(self, driver, target_url): self.chrome = driver self.target_url = target_url self.admin_xpath_list_func = Admin_Menu_Path() self.basic_func = Basic() self.driver_action_func = Driver_Action(driver) self.admin_member_rank_func = Admin_Member_Rank(driver) self.user_register_func = User_Register_Setting(driver) self.paypal_add_new_func = Pay_Pal_Add_New_One(driver) self.paypal_carete_page_func = Pay_Pal_Create_Page(driver) # 管理画面のメニューのパスを返す 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( ) def start(self): #固定ページ一覧に移動 self.go_to_member_rank_page() #会員ランクを設定していく self.admin_member_rank_func.add_admin_rank() ##レッスン概要ページにブロックを設定する。 #GuildPressレッスン一覧新規追加ページへ移動 self.go_to_lesson_over_view_page() #会員ランクのブロックを追加していく。 self.admin_member_rank_func.add_block_setting_overview_page() ##別のタブを立ち上げて、普通にユーザー登録をして、表示を確認する。 self.check_block_page_by_normal_regsiter() ##今度はゴールド会員として登録して表示をチェックするためにゴールド会員のページを作成 self.check_block_page_by_paypal_regsiter() #トップページへ戻る self.go_to_admin_top_page() ##一連のチェックを終えたら、ページのブロックを解除する。 self.reset_block_page() #トップページへ戻る self.go_to_admin_top_page() 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) def reset_block_page(self): self.go_page_list() self.go_to_lesson_over_view_page() self.admin_member_rank_func.reset_block_setting_overview_page() def check_block_page_by_normal_regsiter(self): #固定ページ一覧に移動 self.go_page_list() #固定ページの中から、新規登録ページに移動する。 self.go_to_new_register_page() new_link = self.user_register_func.get_new_register_page_link() # 普通にbasicに新しく開く処理をするとなぜか、新しくひらいたクロームが落ちてしまうのでここで普通に新しく作成。 new_normal_register_driver = webdriver.Chrome( ChromeDriverManager().install()) new_normal_register_driver.get(new_link) # 新しいブラウザでインスタンス作成 normal_register_func = Test_User_Normal_Register( new_normal_register_driver) # ユーザー情報を入れて、新しくユーザーを登録 normal_register_func.nomarl_put_user_info_to_form() lesson_progress_func = Lesson_Progress(new_normal_register_driver) #動画一覧ページに移動して、そのリンクの要素を取得 lesson_progress_func.go_to_lesson_list_page() #ドライバーを新しくして、またインスタンス作成 public_member_rank_func = Public_Member_Rank( new_normal_register_driver) public_member_rank_func.check_lesson_overview_block_page() self.driver_action_func.stop(2) self.driver_action_func.quit(new_normal_register_driver) def go_to_paypal_setting_page(self): admin_guild_press_page_path = self.admin_xpath_lists[ 'admin_guild_press_page_path'] admin_guild_press_paypal_page_path = self.admin_xpath_lists[ 'admin_guild_press_paypal_page_path'] self.driver_action_func.move_admin_page( admin_guild_press_page_path, admin_guild_press_paypal_page_path) def go_to_new_register_page(self): admin_new_regsiter_page_path = self.admin_xpath_lists[ 'admin_new_regsiter_page_path'] self.driver_action_func.single_move_admin_page( admin_new_regsiter_page_path) def go_page_list(self): admin_page_path = self.admin_xpath_lists['admin_page_path'] admin_list_page_path = self.admin_xpath_lists['admin_list_page_path'] self.driver_action_func.move_admin_page(admin_page_path, admin_list_page_path) def go_to_lesson_over_view_page(self): lesson_over_view_page_path = self.admin_xpath_lists[ 'admin_guild_press_lesson_over_view_page_path'] lesson_over_view_list_page_path = self.admin_xpath_lists[ 'admin_guild_press_lesson_over_view_list_page_path'] self.driver_action_func.move_admin_page( lesson_over_view_page_path, lesson_over_view_list_page_path) def go_to_member_rank_page(self): admin_guild_press_page_path = self.admin_xpath_lists[ 'admin_guild_press_page_path'] admin_guild_press_member_rank_page_path = self.admin_xpath_lists[ 'admin_guild_press_member_rank_page_path'] self.driver_action_func.move_admin_page( admin_guild_press_page_path, admin_guild_press_member_rank_page_path) def go_to_admin_top_page(self): self.driver_action_func.move_to_page_by_link( self.chrome, self.target_url + 'wp-admin/')
class Init_Set_Controller: def __init__(self, driver, target_url): self.chrome = driver self.target_url = target_url self.admin_xpath_list_func = Admin_Menu_Path() self.basic_func = Basic() self.driver_action_func = Driver_Action(driver) self.init_settings_func = Init_Settings(driver) self.user_register_setting_func = User_Register_Setting(driver) # 管理画面のメニューのパスを返す 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( ) def get_page_list(self): page_lists = { '新規登録ページ': '[guild_press_user_register]', 'マイぺージ': '[guild_press_my_page]', 'ログインページ': '[guild_press_login_page]', 'ユーザー情報編集ページ': '[guild_press_edit_user_info]', '動画一覧ページ': '[guild_press_all_lesson]', '教材一覧ページ': '[guild_press_list_texts_docs]', } return page_lists def start(self): admin_main_setting_path = self.admin_xpath_lists[ 'admin_main_setting_path'] admin_sub_setting_path = self.admin_xpath_lists[ 'admin_sub_setting_path'] page_lists = self.get_page_list() for page_title, page_shortcode in page_lists.items(): #固定ページリストへ移動 self.go_to_page_list() #ページの作成 self.driver_action_func.go_to_add_new_page() self.init_settings_func.create_new_guild_press_shortcode_page( page_title, page_shortcode) #公開ボタンをクリック self.driver_action_func.click_publish_btn() self.driver_action_func.stop(3) #一度トップページへ移動 self.go_to_admin_top_page() #設定の保存 self.init_settings_func.move_to_guild_press_setting_page() self.init_settings_func.set_up_guild_press_settings() #一般設定に移動 self.driver_action_func.move_admin_page(admin_main_setting_path, admin_sub_setting_path) #一般設定がちゃんとされているかチェックする。 self.user_register_setting_func.check_membership_setting() #トップページへ移動 self.go_to_admin_top_page() def go_to_admin_top_page(self): self.driver_action_func.move_to_page_by_link( self.chrome, self.target_url + 'wp-admin/') def go_to_page_list(self): admin_page_path = self.admin_xpath_lists['admin_page_path'] admin_list_page_path = self.admin_xpath_lists['admin_list_page_path'] self.driver_action_func.move_admin_page(admin_page_path, admin_list_page_path)
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 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()
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()