Skip to content

Commit

Permalink
[241120] kbl 앱 popup close 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
sc303030 committed Nov 20, 2024
1 parent f84b357 commit 7d4f459
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 67 deletions.
15 changes: 1 addition & 14 deletions app/Pages/base_page.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,11 @@
from base_test import BaseTest
from typing import Tuple, Any
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait


class BasePage(BaseTest):
"""The basis for all pages."""

IMPLICIT_WAIT_TIME = 10
TIMEOUT = 30

class BasePage:
def __init__(self, driver: Any):
"""
base constructor.
Sets driver, implicit wait, and timeout.
"""
super().__init__()
self.driver = driver
self.driver.implicitly_wait(self.IMPLICIT_WAIT_TIME)
self.timeout = self.TIMEOUT

def click(self, by_locator: Tuple[str, str], timeout: int = 10):
return (
Expand Down
32 changes: 10 additions & 22 deletions app/Pages/home_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,13 @@


class HomePage(BasePage):
button_1 = (AppiumBy.ACCESSIBILITY_ID, "button_1")
button_1_touch = (AppiumBy.ACCESSIBILITY_ID, "touch!")
button_2 = (AppiumBy.ACCESSIBILITY_ID, "button_2")
text_edit = (AppiumBy.XPATH, "//android.widget.EditText")
check_box = (AppiumBy.XPATH, "//android.widget.CheckBox")
switch_button = (AppiumBy.XPATH, "//android.widget.Switch")

def click_button_1(self):
self.click(self.button_1)

def click_button_2(self):
self.click(self.button_2)

def input_text_edit(self, text: str):
self.click(self.text_edit)
self.send_keys(self.text_edit, text)

def click_check_box(self):
self.click(self.check_box)

def click_switch_button(self):
self.click(self.switch_button)
def __init__(self, driver):
super().__init__(driver)
self.popup_close_button_locator = (AppiumBy.XPATH, "//android.webkit.WebView")

def close_popup_if_present(self):
try:
popup_close_button = self.get_element(self.popup_close_button_locator)
popup_close_button.click()
except:
pass
11 changes: 5 additions & 6 deletions app/TestBase/base_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

class BaseTest(unittest.TestCase):
IMPLICIT_WAIT_TIME = 10
TIMEOUT = 30

def setUp(self):
desired_caps = {}
Expand All @@ -22,14 +21,14 @@ def setUp(self):
desired_caps["platformName"] = "Android"
desired_caps["deviceName"] = "emulator-5554"
desired_caps["automationName"] = "uiautomator2"
desired_caps["app"] = (
f"{os.path.dirname(os.path.dirname(BASE_DIR))}/{os.getenv('APP_DIR')}"
)
desired_caps["app"] = f"{os.getenv('APP_DIR')}"
desired_caps["autoGrantPermissions"] = True

self.driver = webdriver.Remote(
url, options=UiAutomator2Options().load_capabilities(desired_caps)
)
self.driver.implicitly_wait(self.IMPLICIT_WAIT_TIME)

def tearDown(self):
if self.driver:
pass
# self.driver.quit()
self.driver.quit()
30 changes: 5 additions & 25 deletions app/Tests/main_test.py
Original file line number Diff line number Diff line change
@@ -1,29 +1,9 @@
import time
import unittest

from app.Pages.home_page import HomePage
from app.TestBase.base_test import BaseTest
from app.Pages.home_page import HomePage


class TestMain(BaseTest):
def setUp(self):
super().setUp()
self.home_page = HomePage(self.driver)

def test_홈_페이지_각종_버튼을_클릭한다(self):
self.assert_button1_클릭하면_버튼_라벨이_touch_로_변경된다()
self.home_page.click_button_2()
self.home_page.input_text_edit("자동화 테스트")
self.home_page.click_check_box()
self.home_page.click_switch_button()
time.sleep(5)

# 잠시 확인을 위해
def assert_button1_클릭하면_버튼_라벨이_touch_로_변경된다(self):
self.home_page.click_button_1()
time.sleep(1)
self.home_page.get_element(self.home_page.button_1_touch)

class MainTest(BaseTest):
def test_verify_example_element(self):
home_page = HomePage(self.driver)

if __name__ == "__main__":
unittest.main()
home_page.close_popup_if_present()

0 comments on commit 7d4f459

Please sign in to comment.