Last active
March 31, 2016 17:15
-
-
Save whywaita/93372934dea0703207a1 to your computer and use it in GitHub Desktop.
for GitLab 8.5. use ICT Trouble Shooting Contest 5. in detail (http://icttoracon.net/tech-blog/2016/03/31/question11/) (japanese)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from selenium import webdriver | |
from selenium.webdriver.common.keys import Keys | |
# GitLabのベースURL | |
#url = ["http://localhost:8001", | |
# "http://localhost:8002"] | |
url = ["http://localhost:8001"] | |
# チームのID | |
team_ids = [0,1] | |
# WebDriver使う準備 | |
firefox_profile = webdriver.FirefoxProfile() | |
firefox_profile.set_preference("browser.fixup.alternate.enabled",False) # localhostでテストしてる時に www.localhost.com に変換されたので | |
driver = webdriver.Firefox(firefox_profile=firefox_profile) # プロファイル読み込み | |
driver.implicitly_wait(1) # 要素見つかるまで待つ | |
for team_id in team_ids: | |
# GitLabページを開く | |
driver.get(url[team_id] + "/users/sign_in") | |
# 初回ログイン | |
elem_user = driver.find_elements_by_id('user_login')[0] | |
elem_password = driver.find_element_by_name('user[password]') | |
elem_user.send_keys("root") | |
elem_password.send_keys("5iveL!fe") | |
elem_password.send_keys(Keys.RETURN) | |
# もしパスワード変更する必要があれば変更 | |
if( len(driver.find_elements_by_name('user[current_password]')) != 0 ): | |
driver.find_element_by_name('user[current_password]').send_keys("5iveL!fe") | |
driver.find_element_by_name('user[password]').send_keys("5iveL!fe") | |
elem_password_cur = driver.find_element_by_name('user[password_confirmation]').send_keys("5iveL!fe") | |
driver.find_element_by_name('commit').send_keys(Keys.RETURN) | |
# 再ログイン | |
elem_user = driver.find_elements_by_name('user[login]')[0] | |
elem_user.send_keys("root") | |
elem_password = driver.find_element_by_name('user[password]') | |
elem_password.send_keys("5iveL!fe") | |
elem_password.send_keys(Keys.RETURN) | |
if ( len(driver.find_elements_by_name('user[login]')) != 0 ): | |
# 再ログイン | |
elem_user = driver.find_elements_by_name('user[login]')[0] | |
elem_user.send_keys("root") | |
elem_password = driver.find_element_by_name('user[password]') | |
elem_password.send_keys("5iveL!fe") | |
elem_password.send_keys(Keys.RETURN) | |
# adminページへ | |
driver.get(url[team_id] + "/admin/application_settings") | |
# home_page_url 設定 | |
elem_home_page_url = driver.find_element_by_name('application_setting[home_page_url]') | |
elem_home_page_url.send_keys(Keys.BACK_SPACE * 100) | |
elem_home_page_url.send_keys("http://icttoracon.net") | |
elem_home_page_url.send_keys(Keys.RETURN) | |
# ログアウト | |
sign_out = driver.find_elements_by_xpath('/html/body/header/div/div/div/ul/li[6]/a')[0] | |
sign_out.click() | |
driver.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment