2024.03.27(수)
개발물의 안쪽은 침투하지 않고 사용자 관점에서 테스트하는 것
.side
)을 다운로드해서 Command-Line Runner를 이용해 실행할 수 있다!npm install -g selenium-side-runner
npm install -g chromedriver # (또는 edgedriver, geckodriver 등)
selenium-side-runner <시나리오를 담은 .side 파일>
selenium-side-runner --server <서버 URL> <시나리오를 담은 .side 파일>
# Generated by Selenium IDE
import pytest
import time
import json
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.support import expected_conditions
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
class TestUntitled():
def setup_method(self, method):
self.driver = webdriver.Chrome()
self.vars = {}
def teardown_method(self, method):
self.driver.quit()
def test_untitled(self):
self.driver.get("http://localhost:30030/")
self.driver.set_window_size(1454, 866)
self.driver.find_element(By.LINK_TEXT, "무료로 시작하기").click()
self.driver.find_element(By.ID, "email").click()
self.driver.find_element(By.ID, "email").send_keys("test@gmail.com")
self.driver.find_element(By.ID, "password").click()
self.driver.find_element(By.ID, "password").send_keys("1234")
self.driver.find_element(By.CSS_SELECTOR, "button").click()
self.driver.find_element(By.CSS_SELECTOR, ".sc-brSamD:nth-child(2) > p").click()
test_
로 시작하는 메서드가 테스트 케이스가 된다.def test_untitled(self):
self.driver.get("http://localhost:30030/")
self.driver.set_window_size(1454, 866)
self.driver.find_element(By.LINK_TEXT, "무료로 시작하기").click()
self.driver.find_element(By.ID, "email").click()
self.driver.find_element(By.ID, "email").send_keys("test@gmail.com")
self.driver.find_element(By.ID, "password").click()
self.driver.find_element(By.ID, "password").send_keys("1234")
self.driver.find_element(By.CSS_SELECTOR, "button").click()
self.driver.implicitly_wait(2) # 로그인 요청이 성공하여 logout 버튼이 렌더링될 때까지 임의로 2초 대기
self.driver.find_element(By.XPATH, "//p[contains(.,\'로그아웃\')]").click()
self.driver.close()
test_e2e.py
# Generated by Selenium IDE
# Run test by "python -m pytest -v"
import pytest
import time
import json
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.support import expected_conditions
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
BASE_URL = "http://localhost:30030"
CORRECT_USER = {"email": "test@gmail.com", "password": "1234"}
WRONG_USER = {"email": "wrong@gmail.com", "password": "wrong"}
class BaseTestClass:
def setup_method(self, method):
options = webdriver.ChromeOptions()
options.add_argument("-headless=new")
self.driver = webdriver.Chrome(options=options)
self.wait = WebDriverWait(self.driver, timeout=2)
self.vars = {}
def teardown_method(self, method):
self.driver.quit()
def login(self, user):
self.driver.get(BASE_URL + "/")
self.driver.find_element(By.LINK_TEXT, "무료로 시작하기").click()
self.driver.find_element(By.ID, "email").click()
self.driver.find_element(By.ID, "email").send_keys(user["email"])
self.driver.find_element(By.ID, "password").click()
self.driver.find_element(By.ID, "password").send_keys(user["password"])
self.driver.find_element(By.XPATH, "//button[contains(.,'로그인')]").click()
def logout(self):
self.driver.find_element(By.XPATH, "//p[contains(.,'로그아웃')]").click()
class TestLoginLogout(BaseTestClass):
def test_login_fail(self):
self.login(WRONG_USER)
alert = self.wait.until(expected_conditions.alert_is_present())
assert alert.text == "로그인에 실패했습니다."
def test_login_logout(self):
self.login(CORRECT_USER)
self.driver.implicitly_wait(2)
self.logout()
class TestNotesView(BaseTestClass):
def test_notes_view(self):
self.login(CORRECT_USER)
self.driver.implicitly_wait(2)
assert (
self.driver.find_element(
By.CSS_SELECTOR, "#root > div > div.side-bar > div.user > p"
).text
== "test@gmail.com"
)
self.driver.find_element(By.XPATH, "//a[last()]/p").click()
self.logout()