digitalclocktest.py   digitalclocktest.py 
#!/usr/bin/env python3 #!/usr/bin/env python3
# SPDX-License-Identifier: MIT # SPDX-License-Identifier: MIT
# SPDX-FileCopyrightText: 2021-2022 Harald Sitter <sitter@kde.org> # SPDX-FileCopyrightText: 2021-2022 Harald Sitter <sitter@kde.org>
# SPDX-FileCopyrightText: 2023 Marco Martin <mart@kde.org> # SPDX-FileCopyrightText: 2023 Marco Martin <mart@kde.org>
import unittest import unittest
from datetime import date
from typing import Final
from appium import webdriver from appium import webdriver
from appium.options.common.base import AppiumOptions
from appium.webdriver.common.appiumby import AppiumBy from appium.webdriver.common.appiumby import AppiumBy
from selenium.webdriver.support.ui import WebDriverWait
from datetime import date
from dateutil.relativedelta import relativedelta from dateutil.relativedelta import relativedelta
import time from selenium.webdriver.support.ui import WebDriverWait
WIDGET_ID: Final = "org.kde.plasma.digitalclock"
class DigitalClockTests(unittest.TestCase): class DigitalClockTests(unittest.TestCase):
@classmethod @classmethod
def setUpClass(self): def setUpClass(cls):
desired_caps = {} options = AppiumOptions()
desired_caps["app"] = "plasmawindowed -p org.kde.plasma.nano org.kd options.set_capability("app", f"plasmawindowed -p org.kde.plasma.na
e.plasma.digitalclock" no {WIDGET_ID}")
desired_caps["timeouts"] = {'implicit': 10000} options.set_capability("timeouts", {'implicit': 10000})
self.driver = webdriver.Remote( cls.driver = webdriver.Remote(command_executor='http://127.0.0.1:47
command_executor='http://127.0.0.1:4723', 23', options=options)
desired_capabilities=desired_caps)
self.driver.implicitly_wait = 10
# Open Applet # Open Applet
self.driver.find_element(by=AppiumBy.ACCESSIBILITY_ID, value="expan dApplet").click() cls.driver.find_element(by=AppiumBy.ACCESSIBILITY_ID, value="expand Applet").click()
def setUp(self): def setUp(self):
self.driver.find_element(by=AppiumBy.NAME, value="Today").click() self.driver.find_element(by=AppiumBy.NAME, value="Today").click()
self.assertEqual(self.compareMonthLabel(date.today()), True) self.assertEqual(self.compareMonthLabel(date.today()), True)
def tearDown(self): def tearDown(self):
if not self._outcome.result.wasSuccessful(): if not self._outcome.result.wasSuccessful():
self.driver.get_screenshot_as_file("failed_test_shot_{}.png".fo rmat(self.id())) self.driver.get_screenshot_as_file(f"failed_test_shot_digitalcl ocktest_{self.id()}.png")
@classmethod @classmethod
def tearDownClass(self): def tearDownClass(cls) -> None:
self.driver.quit() """
Make sure to terminate the driver again, lest it dangles.
"""
cls.driver.quit()
def assertResult(self, actual, expected): def assertResult(self, actual, expected):
wait = WebDriverWait(self.driver, 20) wait = WebDriverWait(self.driver, 20)
wait.until(lambda x: self.getresults() == expected) wait.until(lambda x: self.getresults() == expected)
self.assertEqual(self.getresults(), expected) self.assertEqual(self.getresults(), expected)
def compareMonthLabel(self, dateToTest): def compareMonthLabel(self, dateToTest):
monthLabel = self.driver.find_element(by=AppiumBy.ACCESSIBILITY_ID, value="monthHeader") monthLabel = self.driver.find_element(by=AppiumBy.ACCESSIBILITY_ID, value="monthHeader")
today = date.today() today = date.today()
monthString = "" monthString = ""
skipping to change at line 75 skipping to change at line 80
lastMonthDate = date.today() - relativedelta(months=1) lastMonthDate = date.today() - relativedelta(months=1)
self.driver.find_element(by=AppiumBy.NAME, value="Previous Month"). click() self.driver.find_element(by=AppiumBy.NAME, value="Previous Month"). click()
wait = WebDriverWait(self.driver, 50) wait = WebDriverWait(self.driver, 50)
wait.until(lambda x: self.compareMonthLabel(lastMonthDate)) wait.until(lambda x: self.compareMonthLabel(lastMonthDate))
self.assertEqual(self.compareMonthLabel(lastMonthDate), True) self.assertEqual(self.compareMonthLabel(lastMonthDate), True)
def test_months_view(self): def test_months_view(self):
dateAugust = date.today() dateAugust = date.today()
dateAugust = dateAugust.replace(month = 8); dateAugust = dateAugust.replace(month=8)
self.driver.find_element(by=AppiumBy.NAME, value="Months").click() self.driver.find_element(by=AppiumBy.NAME, value="Months").click()
self.driver.find_element(by=AppiumBy.ACCESSIBILITY_ID, value="calen darCell-{}-{}".format(dateAugust.year, dateAugust.month)).click() self.driver.find_element(by=AppiumBy.ACCESSIBILITY_ID, value="calen darCell-{}-{}".format(dateAugust.year, dateAugust.month)).click()
wait = WebDriverWait(self.driver, 50) wait = WebDriverWait(self.driver, 50)
wait.until(lambda x: self.compareMonthLabel(dateAugust)) wait.until(lambda x: self.compareMonthLabel(dateAugust))
self.assertEqual(self.compareMonthLabel(dateAugust), True) self.assertEqual(self.compareMonthLabel(dateAugust), True)
def test_years_view(self): def test_years_view(self):
dateFuture = date.today() + relativedelta(years = 2) dateFuture = date.today() + relativedelta(years=2)
self.driver.find_element(by=AppiumBy.NAME, value="Years").click() self.driver.find_element(by=AppiumBy.NAME, value="Years").click()
self.driver.find_element(by=AppiumBy.ACCESSIBILITY_ID, value="calen darCell-{}".format(dateFuture.year)).click() self.driver.find_element(by=AppiumBy.ACCESSIBILITY_ID, value="calen darCell-{}".format(dateFuture.year)).click()
wait = WebDriverWait(self.driver, 50) wait = WebDriverWait(self.driver, 50)
wait.until(lambda x: self.compareMonthLabel(dateFuture)) wait.until(lambda x: self.compareMonthLabel(dateFuture))
self.assertEqual(self.compareMonthLabel(dateFuture), True) self.assertEqual(self.compareMonthLabel(dateFuture), True)
if __name__ == '__main__': if __name__ == '__main__':
suite = unittest.TestLoader().loadTestsFromTestCase(DigitalClockTests) suite = unittest.TestLoader().loadTestsFromTestCase(DigitalClockTests)
 End of changes. 11 change blocks. 
18 lines changed or deleted 24 lines changed or added

This html diff was produced by rfcdiff 1.41. The latest version is available from http://tools.ietf.org/tools/rfcdiff/