Skip to content

Instantly share code, notes, and snippets.

@kamiazya
Created February 19, 2018 09:49
Show Gist options
  • Save kamiazya/1e1f9e173a1b65be011a2302f5eefb96 to your computer and use it in GitHub Desktop.
Save kamiazya/1e1f9e173a1b65be011a2302f5eefb96 to your computer and use it in GitHub Desktop.
Docker on Seleniumでいい感じのUIテスト環境

Selenium によるデバッグ

ダッシュボード

VNC

Mac

Chrome

Finderでサーバーに接続からvnc://localhost:5090に接続。

パスワードはsecret

FireFix

Finderでサーバーに接続からvnc://localhost:5091に接続。

パスワードはsecret

import unittest
import pprint
from selenium import webdriver
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
from selenium.webdriver.common.keys import Keys
import time
from faker import Factory
class UserMemberTest(unittest.TestCase):
def setUp(self):
#ブラウザ起動
# self.browser = webdriver.Chrome()
self.browser = webdriver.Remote(
command_executor='http://localhost:4444/wd/hub',
desired_capabilities=DesiredCapabilities.CHROME,
# desired_capabilities=DesiredCapabilities.FIREFOX,
)
#停止
time.sleep(4)
def tearDown(self):
self.browser.quit()
def test_add_user_random(self):
for i in range(4):
# メンバー登録画面
self.browser.get("http://{{service_name}}/users/register")
# Facker
f = Factory.create('ja_JP')
# 待機
time.sleep(1)
# テストデータ
userLastNameData = f.last_name_female()
userFirstNameData = f.first_name_female()
userLastNameKanaData = f.last_kana_name()
userFirstNameKanaData = f.first_kana_name_female()
userPasswordData = f.password(length=10, special_chars=False, digits=True, upper_case=True, lower_case=True)
userMailData = f.email()
userPostCodeData = f.zipcode()
userAddressData = f.address()
userTelData = f.phone_number()
# Input
userLastNameInput = self.browser.find_element_by_id("UserLastName")
userFirstNameInput = self.browser.find_element_by_id("UserFirstName")
userLastNameKanaInput = self.browser.find_element_by_id("UserLastNameKana")
userFirstNameKanaInput = self.browser.find_element_by_id("UserFirstNameKana")
userPasswordInput = self.browser.find_element_by_id("UserPassword")
userMailInput = self.browser.find_element_by_id("UserMail")
userPostCodeInput = self.browser.find_element_by_id("UserPostCode")
userAddressInput = self.browser.find_element_by_id("UserAddress")
userTelInput = self.browser.find_element_by_id("UserTel")
# テストデータを入れる
userLastNameInput.send_keys(userLastNameData)
userFirstNameInput.send_keys(userFirstNameData)
userLastNameKanaInput.send_keys(userLastNameKanaData)
userFirstNameKanaInput.send_keys(userFirstNameKanaData)
userPasswordInput.send_keys(userPasswordData)
userMailInput.send_keys(userMailData)
userPostCodeInput.send_keys(userPostCodeData)
userAddressInput.send_keys(userAddressData)
userTelInput.send_keys(userTelData)
# 待機
time.sleep(1)
# Submit
submit = self.browser.find_element_by_id("Submit")
submit.click()
# 待機
time.sleep(3)
# 登録データを表示
pprint.pprint({
"userLastNameData": userLastNameData,
"userFirstNameData": userFirstNameData,
"userLastNameKanaData": userLastNameKanaData,
"userFirstNameKanaData": userFirstNameKanaData,
"userPasswordData": userPasswordData,
"userMailData": userMailData,
"userPostCodeData": userPostCodeData,
"userAddressData": userAddressData,
"userTelData": userTelData,
})
# 登録された後、正しいURLに遷移するか
self.assertEqual(self.browser.current_url, "http://{{service_name}}/my-page")
if __name__ == '__main__':
unittest.main(verbosity=2)
version: '2'
services:
firefox:
image: selenium/node-firefox-debug:3.9.1-actinium
volumes:
- /dev/shm:/dev/shm
depends_on:
- hub
ports:
- 5901:5900
environment:
HUB_HOST: hub
networks:
- default
chrome:
image: selenium/node-chrome-debug:3.9.1-actinium
volumes:
- /dev/shm:/dev/shm
depends_on:
- hub
ports:
- 5900:5900
environment:
HUB_HOST: hub
networks:
- default
hub:
image: selenium/hub:3.9.1-actinium
ports:
- 4444:4444
networks:
default:
external:
name: develop_default
@kamiazya
Copy link
Author

docker-compose.yml

volumes:
  - /dev/shm:/dev/shm

は、メモリが足りないときのため。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment