Compare commits
2 Commits
77d723b9da
...
117e1aeda8
Author | SHA1 | Date | |
---|---|---|---|
117e1aeda8 | |||
7260ed0164 |
3
.gitignore
vendored
3
.gitignore
vendored
@ -143,4 +143,5 @@ PythonImportHelper-v2-Completion.json
|
|||||||
deploy/
|
deploy/
|
||||||
|
|
||||||
# idea
|
# idea
|
||||||
.idea/
|
.idea/
|
||||||
|
selenium-data/
|
@ -20,6 +20,8 @@
|
|||||||
"TestSettings": {
|
"TestSettings": {
|
||||||
"LoginUrl": "https://discord.com/login",
|
"LoginUrl": "https://discord.com/login",
|
||||||
"MePageUrl": "https://discord.com/channels/@me",
|
"MePageUrl": "https://discord.com/channels/@me",
|
||||||
"CmdURL": "https://discord.com/channels/910199451145076828/911578636899987526"
|
"CmdURL": "https://discord.com/channels/910199451145076828/911578636899987526",
|
||||||
|
"GuildId": 910199451145076828,
|
||||||
|
"BotId": 998159802393964594
|
||||||
}
|
}
|
||||||
}
|
}
|
1
kdb-bot/test/ui_tests/src/ui_tests_shared/__init__.py
Normal file
1
kdb-bot/test/ui_tests/src/ui_tests_shared/__init__.py
Normal file
@ -0,0 +1 @@
|
|||||||
|
# imports
|
@ -0,0 +1,11 @@
|
|||||||
|
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'
|
||||||
|
|
||||||
|
ping = '//*[ contains (text(), ‘Krümmelmonster-test’ ) ]'
|
||||||
|
info = '//*[ contains (text(), ‘Krümmelmonster-test’ ) ]'
|
||||||
|
help = '//*[ contains (text(), ‘Krümmelmonster-test’ ) ]'
|
||||||
|
afk = '//*[ contains (text(), ‘Krümmelmonster-test’ ) ]'
|
@ -10,6 +10,7 @@ from selenium.webdriver.remote.webelement import WebElement
|
|||||||
from selenium.webdriver.support import expected_conditions
|
from selenium.webdriver.support import expected_conditions
|
||||||
from selenium.webdriver.support.wait import WebDriverWait
|
from selenium.webdriver.support.wait import WebDriverWait
|
||||||
|
|
||||||
|
from ui_tests.src.ui_tests_shared.command_selectors_enum import CommandSelectorsEnum
|
||||||
from ui_tests_shared.test_case_with_app import TestCaseWithApp
|
from ui_tests_shared.test_case_with_app import TestCaseWithApp
|
||||||
from ui_tests_shared.ui import UI
|
from ui_tests_shared.ui import UI
|
||||||
|
|
||||||
@ -27,11 +28,11 @@ class CommandTestCaseWithApp(TestCaseWithApp):
|
|||||||
cls._t = cls._services.get_service(TranslatePipe)
|
cls._t = cls._services.get_service(TranslatePipe)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def send_command(cls, cmd: str):
|
def send_command(cls, cmd: str, selector: CommandSelectorsEnum):
|
||||||
UI.driver.get(cls._test_settings.cmd_url)
|
UI.driver.get(cls._test_settings.cmd_url)
|
||||||
time.sleep(2)
|
time.sleep(2)
|
||||||
|
|
||||||
cmd_element_ident = (By.XPATH, '/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_element_ident = (By.XPATH, CommandSelectorsEnum.cmd_chat.value)
|
||||||
cmd_element = UI.driver.find_element(*cmd_element_ident)
|
cmd_element = UI.driver.find_element(*cmd_element_ident)
|
||||||
cmd_element.send_keys(f'/{cmd}')
|
cmd_element.send_keys(f'/{cmd}')
|
||||||
time.sleep(2)
|
time.sleep(2)
|
||||||
@ -40,9 +41,8 @@ class CommandTestCaseWithApp(TestCaseWithApp):
|
|||||||
WebDriverWait(UI.driver, 20, ignored_exceptions=ignored_exceptions).until(
|
WebDriverWait(UI.driver, 20, ignored_exceptions=ignored_exceptions).until(
|
||||||
expected_conditions.presence_of_element_located((
|
expected_conditions.presence_of_element_located((
|
||||||
By.XPATH,
|
By.XPATH,
|
||||||
'/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[2]/div/div/div[5]'
|
selector.value
|
||||||
))
|
))
|
||||||
).click()
|
).click()
|
||||||
time.sleep(2)
|
time.sleep(2)
|
||||||
UI.driver.find_element(By.XPATH, '/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').send_keys(
|
UI.driver.find_element(By.XPATH, CommandSelectorsEnum.cmd_chat_input.value).send_keys(Keys.ENTER)
|
||||||
Keys.ENTER)
|
|
||||||
|
@ -12,6 +12,8 @@ class TestSettings(ConfigurationModelABC):
|
|||||||
self._login_url = ''
|
self._login_url = ''
|
||||||
self._me_page_url = ''
|
self._me_page_url = ''
|
||||||
self._cmd_url = ''
|
self._cmd_url = ''
|
||||||
|
self._guild_id = 0
|
||||||
|
self._bot_id = 0
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def login_url(self) -> str:
|
def login_url(self) -> str:
|
||||||
@ -25,11 +27,21 @@ class TestSettings(ConfigurationModelABC):
|
|||||||
def cmd_url(self) -> str:
|
def cmd_url(self) -> str:
|
||||||
return self._cmd_url
|
return self._cmd_url
|
||||||
|
|
||||||
|
@property
|
||||||
|
def guild_id(self) -> int:
|
||||||
|
return self._guild_id
|
||||||
|
|
||||||
|
@property
|
||||||
|
def bot_id(self) -> int:
|
||||||
|
return self._bot_id
|
||||||
|
|
||||||
def from_dict(self, settings: dict):
|
def from_dict(self, settings: dict):
|
||||||
try:
|
try:
|
||||||
self._login_url = settings['LoginUrl']
|
self._login_url = settings['LoginUrl']
|
||||||
self._me_page_url = settings['MePageUrl']
|
self._me_page_url = settings['MePageUrl']
|
||||||
self._cmd_url = settings['CmdURL']
|
self._cmd_url = settings['CmdURL']
|
||||||
|
self._guild_id = settings['GuildId']
|
||||||
|
self._bot_id = settings['BotId']
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
Console.error(f'[ ERROR ] [ {__name__} ]: Reading error in {type(self).__name__} settings')
|
Console.error(f'[ ERROR ] [ {__name__} ]: Reading error in {type(self).__name__} settings')
|
||||||
Console.error(f'[ EXCEPTION ] [ {__name__} ]: {e} -> {traceback.format_exc()}')
|
Console.error(f'[ EXCEPTION ] [ {__name__} ]: {e} -> {traceback.format_exc()}')
|
||||||
|
@ -19,8 +19,15 @@ class UI:
|
|||||||
_test_settings: Optional[TestSettings] = None
|
_test_settings: Optional[TestSettings] = None
|
||||||
|
|
||||||
options = webdriver.ChromeOptions()
|
options = webdriver.ChromeOptions()
|
||||||
|
options.add_argument("user-data-dir=selenium-data")
|
||||||
options.add_experimental_option('useAutomationExtension', False)
|
options.add_experimental_option('useAutomationExtension', False)
|
||||||
options.add_experimental_option("excludeSwitches", ["enable-automation"])
|
options.add_experimental_option("excludeSwitches", ["enable-automation"])
|
||||||
|
options.add_experimental_option("prefs", {
|
||||||
|
"profile.default_content_setting_values.media_stream_mic": 1,
|
||||||
|
"profile.default_content_setting_values.media_stream_camera": 1,
|
||||||
|
"profile.default_content_setting_values.geolocation": 1,
|
||||||
|
"profile.default_content_setting_values.notifications": 1
|
||||||
|
})
|
||||||
driver = webdriver.Chrome(options=options)
|
driver = webdriver.Chrome(options=options)
|
||||||
|
|
||||||
_is_logged_in = False
|
_is_logged_in = False
|
||||||
@ -38,7 +45,12 @@ class UI:
|
|||||||
|
|
||||||
cls.driver.get(cls._test_settings.login_url)
|
cls.driver.get(cls._test_settings.login_url)
|
||||||
|
|
||||||
WebDriverWait(cls.driver, 20).until(expected_conditions.presence_of_element_located((By.NAME, 'email')))
|
try:
|
||||||
|
WebDriverWait(cls.driver, 10).until(expected_conditions.url_matches(cls._test_settings.me_page_url))
|
||||||
|
cls._is_logged_in = True
|
||||||
|
return
|
||||||
|
except Exception as e:
|
||||||
|
WebDriverWait(cls.driver, 20).until(expected_conditions.presence_of_element_located((By.NAME, 'email')))
|
||||||
|
|
||||||
mail_element = cls.driver.find_element(By.NAME, 'email')
|
mail_element = cls.driver.find_element(By.NAME, 'email')
|
||||||
mail_element.clear()
|
mail_element.clear()
|
||||||
|
@ -0,0 +1,42 @@
|
|||||||
|
import time
|
||||||
|
|
||||||
|
import discord
|
||||||
|
from discord import VoiceState
|
||||||
|
from selenium.webdriver.common.by import By
|
||||||
|
|
||||||
|
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
|
||||||
|
from ui_tests_shared.ui import UI
|
||||||
|
|
||||||
|
|
||||||
|
class AFKCommandTestCase(CommandTestCaseWithApp):
|
||||||
|
|
||||||
|
@Async.test
|
||||||
|
async def test_error_message(self):
|
||||||
|
correct_response = self._t.transform('modules.base.afk_command_channel_missing_message')
|
||||||
|
self.assertIsNotNone(correct_response)
|
||||||
|
self.send_command('afk', CommandSelectorsEnum.afk)
|
||||||
|
|
||||||
|
def check(m: discord.Message):
|
||||||
|
return m.content == correct_response and m.author.id == self._test_settings.bot_id
|
||||||
|
|
||||||
|
response = await self._bot.wait_for('message', check=check)
|
||||||
|
self.assertEqual(response.content, correct_response)
|
||||||
|
|
||||||
|
@Async.test
|
||||||
|
async def test_move(self):
|
||||||
|
# correct_response = self._t.transform('modules.base.pong')
|
||||||
|
# self.assertIsNotNone(correct_response)
|
||||||
|
UI.driver.find_element(By.XPATH, '//*[@id="channels"]/ul/li[20]/div/div/div/a').click()
|
||||||
|
time.sleep(1)
|
||||||
|
|
||||||
|
self.send_command('afk', CommandSelectorsEnum.afk)
|
||||||
|
|
||||||
|
def check(member: discord.Member, before: discord.VoiceState, after: discord.VoiceState):
|
||||||
|
return member.id == self._bot.user.id
|
||||||
|
|
||||||
|
response: VoiceState = await self._bot.wait_for('voice_state_update', check=check)
|
||||||
|
self.assertIsNotNone(response.channel)
|
||||||
|
self.assertEqual(response.channel.id, 910199452915093594)
|
||||||
|
# self.assertEqual(response.content, correct_response)
|
@ -1,18 +1,19 @@
|
|||||||
import discord
|
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.command_test_case_with_app import CommandTestCaseWithApp
|
||||||
from ui_tests_shared.decorators import Async
|
from ui_tests_shared.decorators import Async
|
||||||
|
|
||||||
|
|
||||||
class HelpTestCase(CommandTestCaseWithApp):
|
class HelpCommandTestCase(CommandTestCaseWithApp):
|
||||||
|
|
||||||
@Async.test
|
@Async.test
|
||||||
async def test_help(self):
|
async def test_help(self):
|
||||||
correct_response = 'https://git.sh-edraft.de/sh-edraft.de/kd_discord_bot/wiki/Befehle'
|
correct_response = 'https://git.sh-edraft.de/sh-edraft.de/kd_discord_bot/wiki/Befehle'
|
||||||
self.send_command('help')
|
self.send_command('help', CommandSelectorsEnum.help)
|
||||||
|
|
||||||
def check(m: discord.Message):
|
def check(m: discord.Message):
|
||||||
return m.content == correct_response and m.author.id == 998159802393964594
|
return m.content == correct_response and m.author.id == self._test_settings.bot_id
|
||||||
|
|
||||||
response = await self._bot.wait_for('message', check=check)
|
response = await self._bot.wait_for('message', check=check)
|
||||||
self.assertEqual(response.content, correct_response)
|
self.assertEqual(response.content, correct_response)
|
@ -0,0 +1,49 @@
|
|||||||
|
from datetime import datetime
|
||||||
|
import discord
|
||||||
|
|
||||||
|
import bot
|
||||||
|
from bot_core.abc.client_utils_service_abc import ClientUtilsServiceABC
|
||||||
|
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 InfoCommandTestCase(CommandTestCaseWithApp):
|
||||||
|
|
||||||
|
def get_embed(self) -> discord.Embed:
|
||||||
|
client_utils: ClientUtilsServiceABC = self._services.get_service(ClientUtilsServiceABC)
|
||||||
|
client = client_utils.get_client(self._bot.user.id, self._test_settings.guild_id)
|
||||||
|
embed = discord.Embed(
|
||||||
|
title=self._t.transform('modules.base.info.title'),
|
||||||
|
description=self._t.transform('modules.base.info.description'),
|
||||||
|
color=int('ef9d0d', 16)
|
||||||
|
)
|
||||||
|
|
||||||
|
embed.add_field(name=self._t.transform('modules.base.info.fields.version'), value=bot.__version__)
|
||||||
|
start_time = self._config.get_configuration('Bot_StartTime')
|
||||||
|
ontime = round((datetime.now() - datetime.strptime(start_time, '%Y-%m-%d %H:%M:%S.%f')).total_seconds() / 3600, 2)
|
||||||
|
embed.add_field(name=self._t.transform('modules.base.info.fields.ontime'), value=f'{ontime}h')
|
||||||
|
embed.add_field(name=self._t.transform('modules.base.info.fields.sent_message_count'), value=client.sent_message_count, inline=False)
|
||||||
|
embed.add_field(name=self._t.transform('modules.base.info.fields.received_message_count'), value=client.received_message_count)
|
||||||
|
embed.add_field(name=self._t.transform('modules.base.info.fields.deleted_message_count'), value=client.deleted_message_count, inline=False)
|
||||||
|
embed.add_field(name=self._t.transform('modules.base.info.fields.received_command_count'), value=client.received_command_count)
|
||||||
|
embed.add_field(name=self._t.transform('modules.base.info.fields.moved_users_count'), value=client.moved_users_count)
|
||||||
|
from bot.module_list import ModuleList
|
||||||
|
modules = ModuleList.get_modules()
|
||||||
|
modules = modules.select(lambda x: x.__name__.replace('Module', ''))
|
||||||
|
embed.add_field(name=self._t.transform('modules.base.info.fields.modules'), value='\n'.join(modules), inline=False)
|
||||||
|
return embed
|
||||||
|
|
||||||
|
@Async.test
|
||||||
|
async def test_info(self):
|
||||||
|
correct_response = self.get_embed()
|
||||||
|
self.send_command('info', CommandSelectorsEnum.info)
|
||||||
|
|
||||||
|
def check(m: discord.Message):
|
||||||
|
return m.embeds[0] == correct_response and m.author.id == self._test_settings.bot_id
|
||||||
|
|
||||||
|
response: discord.Message = await self._bot.wait_for('message', check=check)
|
||||||
|
self.assertEqual(len(response.embeds), 1)
|
||||||
|
|
||||||
|
self.assertEqual(response.embeds[0], correct_response)
|
||||||
|
await self._bot.close()
|
@ -1,19 +1,20 @@
|
|||||||
import discord
|
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.command_test_case_with_app import CommandTestCaseWithApp
|
||||||
from ui_tests_shared.decorators import Async
|
from ui_tests_shared.decorators import Async
|
||||||
|
|
||||||
|
|
||||||
class PingTestCase(CommandTestCaseWithApp):
|
class PingCommandTestCase(CommandTestCaseWithApp):
|
||||||
|
|
||||||
@Async.test
|
@Async.test
|
||||||
async def test_ping(self):
|
async def test_ping(self):
|
||||||
correct_response = self._t.transform('modules.base.pong')
|
correct_response = self._t.transform('modules.base.pong')
|
||||||
self.assertIsNotNone(correct_response)
|
self.assertIsNotNone(correct_response)
|
||||||
self.send_command('ping')
|
self.send_command('ping', CommandSelectorsEnum.ping)
|
||||||
|
|
||||||
def check(m: discord.Message):
|
def check(m: discord.Message):
|
||||||
return m.content == correct_response and m.author.id == 998159802393964594
|
return m.content == correct_response and m.author.id == self._test_settings.bot_id
|
||||||
|
|
||||||
response = await self._bot.wait_for('message', check=check)
|
response = await self._bot.wait_for('message', check=check)
|
||||||
self.assertEqual(response.content, correct_response)
|
self.assertEqual(response.content, correct_response)
|
Loading…
Reference in New Issue
Block a user