diff --git a/kdb-bot/test/ui_tests/src/ui_tests_shared/command_selectors_enum.py b/kdb-bot/test/ui_tests/src/ui_tests_shared/command_selectors_enum.py index ceb3d6b0..40b5aa20 100644 --- a/kdb-bot/test/ui_tests/src/ui_tests_shared/command_selectors_enum.py +++ b/kdb-bot/test/ui_tests/src/ui_tests_shared/command_selectors_enum.py @@ -4,8 +4,10 @@ from enum import Enum class CommandSelectorsEnum(Enum): cmd_chat = '/html/body/div[1]/div[2]/div/div[1]/div/div[2]/div/div[1]/div/div/div[3]/div[2]/main/form/div/div[1]/div/div[3]/div/div[2]/div' cmd_chat_input = '/html/body/div[1]/div[2]/div/div[1]/div/div[2]/div/div[1]/div/div/div[3]/div/main/form/div/div[2]/div/div[2]/div/div' + msg_input = '/html/body/div[1]/div[2]/div/div[1]/div/div[2]/div/div[1]/div/div/div[3]/div[2]/main/form/div/div[1]/div/div[3]/div/div/div' ping = '//*[ contains (text(), ‘Krümmelmonster-test’ ) ]' info = '//*[ contains (text(), ‘Krümmelmonster-test’ ) ]' help = '//*[ contains (text(), ‘Krümmelmonster-test’ ) ]' afk = '//*[ contains (text(), ‘Krümmelmonster-test’ ) ]' + purge = '//*[ contains (text(), ‘Krümmelmonster-test’ ) ]' diff --git a/kdb-bot/test/ui_tests_shared/command_test_case_with_app.py b/kdb-bot/test/ui_tests_shared/command_test_case_with_app.py index d2abe048..ae5a88d4 100644 --- a/kdb-bot/test/ui_tests_shared/command_test_case_with_app.py +++ b/kdb-bot/test/ui_tests_shared/command_test_case_with_app.py @@ -28,9 +28,22 @@ class CommandTestCaseWithApp(TestCaseWithApp): cls._t = cls._services.get_service(TranslatePipe) @classmethod - def send_command(cls, cmd: str, selector: CommandSelectorsEnum): - UI.driver.get(cls._test_settings.cmd_url) + def send_message(cls, msg: str): + if UI.driver.current_url != cls._test_settings.cmd_url: + UI.driver.get(cls._test_settings.cmd_url) + time.sleep(2) + + cmd_element_ident = (By.XPATH, CommandSelectorsEnum.cmd_chat.value) + cmd_element = UI.driver.find_element(*cmd_element_ident) + cmd_element.send_keys(msg) time.sleep(2) + UI.driver.find_element(By.XPATH, CommandSelectorsEnum.msg_input.value).send_keys(Keys.ENTER) + + @classmethod + def send_command(cls, cmd: str, selector: CommandSelectorsEnum): + if UI.driver.current_url != cls._test_settings.cmd_url: + UI.driver.get(cls._test_settings.cmd_url) + time.sleep(2) cmd_element_ident = (By.XPATH, CommandSelectorsEnum.cmd_chat.value) cmd_element = UI.driver.find_element(*cmd_element_ident) diff --git a/kdb-bot/test/ui_tests_shared/decorators.py b/kdb-bot/test/ui_tests_shared/decorators.py index 67bcb6a1..712437fe 100644 --- a/kdb-bot/test/ui_tests_shared/decorators.py +++ b/kdb-bot/test/ui_tests_shared/decorators.py @@ -4,7 +4,7 @@ import asyncio class Async: @classmethod - def test(cls, coro): + def async_func(cls, coro): def wrapper(*args, **kwargs): try: return asyncio.run(coro(*args, **kwargs)) diff --git a/kdb-bot/test/ui_tests_tests/commands/common/afk_command_test_case.py b/kdb-bot/test/ui_tests_tests/commands/common/afk_command_test_case.py index 66f8a776..5f5bd51e 100644 --- a/kdb-bot/test/ui_tests_tests/commands/common/afk_command_test_case.py +++ b/kdb-bot/test/ui_tests_tests/commands/common/afk_command_test_case.py @@ -12,7 +12,7 @@ from ui_tests_shared.ui import UI class AFKCommandTestCase(CommandTestCaseWithApp): - @Async.test + @Async.async_func async def test_error_message(self): correct_response = self._t.transform('modules.base.afk_command_channel_missing_message') self.assertIsNotNone(correct_response) @@ -24,7 +24,7 @@ class AFKCommandTestCase(CommandTestCaseWithApp): response = await self._bot.wait_for('message', check=check) self.assertEqual(response.content, correct_response) - @Async.test + @Async.async_func async def test_move(self): # correct_response = self._t.transform('modules.base.pong') # self.assertIsNotNone(correct_response) @@ -40,3 +40,4 @@ class AFKCommandTestCase(CommandTestCaseWithApp): self.assertIsNotNone(response.channel) self.assertEqual(response.channel.id, 910199452915093594) # self.assertEqual(response.content, correct_response) + UI.driver.find_element(By.XPATH, '/html/body/div[1]/div[2]/div/div[1]/div/div[2]/div/div[1]/div/div/div[1]/section/div[1]/div/div[1]/div[2]/button').click() diff --git a/kdb-bot/test/ui_tests_tests/commands/common/help_command_test_case.py b/kdb-bot/test/ui_tests_tests/commands/common/help_command_test_case.py index 72594086..844b4109 100644 --- a/kdb-bot/test/ui_tests_tests/commands/common/help_command_test_case.py +++ b/kdb-bot/test/ui_tests_tests/commands/common/help_command_test_case.py @@ -7,7 +7,7 @@ from ui_tests_shared.decorators import Async class HelpCommandTestCase(CommandTestCaseWithApp): - @Async.test + @Async.async_func async def test_help(self): correct_response = 'https://git.sh-edraft.de/sh-edraft.de/kd_discord_bot/wiki/Befehle' self.send_command('help', CommandSelectorsEnum.help) diff --git a/kdb-bot/test/ui_tests_tests/commands/common/info_command_test_case.py b/kdb-bot/test/ui_tests_tests/commands/common/info_command_test_case.py index 865d54d0..02b100dc 100644 --- a/kdb-bot/test/ui_tests_tests/commands/common/info_command_test_case.py +++ b/kdb-bot/test/ui_tests_tests/commands/common/info_command_test_case.py @@ -34,7 +34,7 @@ class InfoCommandTestCase(CommandTestCaseWithApp): embed.add_field(name=self._t.transform('modules.base.info.fields.modules'), value='\n'.join(modules), inline=False) return embed - @Async.test + @Async.async_func async def test_info(self): correct_response = self.get_embed() self.send_command('info', CommandSelectorsEnum.info) diff --git a/kdb-bot/test/ui_tests_tests/commands/common/ping_command_test_case.py b/kdb-bot/test/ui_tests_tests/commands/common/ping_command_test_case.py index efc6617f..a66213d4 100644 --- a/kdb-bot/test/ui_tests_tests/commands/common/ping_command_test_case.py +++ b/kdb-bot/test/ui_tests_tests/commands/common/ping_command_test_case.py @@ -7,7 +7,7 @@ from ui_tests_shared.decorators import Async class PingCommandTestCase(CommandTestCaseWithApp): - @Async.test + @Async.async_func async def test_ping(self): correct_response = self._t.transform('modules.base.pong') self.assertIsNotNone(correct_response) diff --git a/kdb-bot/test/ui_tests_tests/commands/common/purge_command_test_case.py b/kdb-bot/test/ui_tests_tests/commands/common/purge_command_test_case.py new file mode 100644 index 00000000..76106c3c --- /dev/null +++ b/kdb-bot/test/ui_tests_tests/commands/common/purge_command_test_case.py @@ -0,0 +1,31 @@ +import asyncio +import time + +import discord + +from ui_tests.src.ui_tests_shared.command_selectors_enum import CommandSelectorsEnum +from ui_tests_shared.command_test_case_with_app import CommandTestCaseWithApp +from ui_tests_shared.decorators import Async + + +class PurgeCommandTestCase(CommandTestCaseWithApp): + + def setUp(self): + self.send_message('test nachricht 1') + self.send_message('test nachricht 2') + self.send_message('test nachricht 3') + self.send_message('test nachricht 4') + + def test_purge(self): + correct_response = self._t.transform('modules.moderator.purge_message') + self.assertIsNotNone(correct_response) + self.send_command('purge', CommandSelectorsEnum.purge) + + def check(m: discord.Message): + return m.content == correct_response and m.author.id == self._test_settings.bot_id + + response = asyncio.run(self._bot.wait_for('message', check=check)) + self.assertEqual(response.content, correct_response) + time.sleep(20) + channel = self._bot.get_channel(911578680998895687) + self.assertEqual(channel.message_count, 0)