test: Fix selenium tests.

This commit is contained in:
tecnovert
2023-11-09 22:28:01 +02:00
parent 05e6edd5df
commit 22cd3cf9f1
10 changed files with 119 additions and 75 deletions

View File

@@ -1,27 +1,25 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# Copyright (c) 2022 tecnovert
# Copyright (c) 2022-2023 tecnovert
# Distributed under the MIT software license, see the accompanying
# file LICENSE or http://www.opensource.org/licenses/mit-license.php.
import json
import time
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support.select import Select
from selenium.webdriver.support import expected_conditions as EC
from util import get_driver
def test_html():
def test_settings(driver):
base_url = 'http://localhost:12701'
node2_url = 'http://localhost:12702'
driver = webdriver.Chrome(service=Service('/opt/chromedriver96'))
url = base_url + '/settings'
driver.get(url)
driver.find_element(By.ID, 'general-tab').click()
@@ -48,8 +46,8 @@ def test_html():
btn_apply_general.click()
time.sleep(1)
settings_path = '/tmp/test_persistent/client0/basicswap.json'
with open(settings_path) as fs:
settings_path_0 = '/tmp/test_persistent/client0/basicswap.json'
with open(settings_path_0) as fs:
settings = json.load(fs)
assert (settings['debug'] is False)
@@ -65,14 +63,14 @@ def test_html():
difficult_text = '`~!@#$%^&*()-_=+[{}]\\|;:\'",<>./? '
el = driver.find_element(By.NAME, 'chartapikey')
el.clear()
el.send_keys(difficult_text)
btn_apply_chart = wait.until(EC.element_to_be_clickable((By.NAME, 'apply_chart')))
btn_apply_chart.click()
time.sleep(1)
settings_path = '/tmp/test_persistent/client0/basicswap.json'
with open(settings_path) as fs:
with open(settings_path_0) as fs:
settings = json.load(fs)
assert (settings['show_chart'] is False)
@@ -90,16 +88,55 @@ def test_html():
el = driver.find_element(By.NAME, 'chartapikey')
assert el.get_property('value') == hex_text
settings_path = '/tmp/test_persistent/client0/basicswap.json'
with open(settings_path) as fs:
with open(settings_path_0) as fs:
settings = json.load(fs)
assert (settings.get('chart_api_key') == hex_text)
driver.close()
# Apply XMR settings with blank nodes list
driver.find_element(By.ID, 'coins-tab').click()
btn_apply_monero = wait.until(EC.element_to_be_clickable((By.NAME, 'apply_monero')))
el = driver.find_element(By.NAME, 'remotedaemonurls_monero')
el.clear()
btn_apply_monero.click()
time.sleep(1)
print('Done.')
with open(settings_path_0) as fs:
settings = json.load(fs)
assert ('remote_daemon_urls' not in settings['chainclients']['monero'])
btn_apply_monero = wait.until(EC.element_to_be_clickable((By.NAME, 'apply_monero')))
el = driver.find_element(By.NAME, 'remotedaemonurls_monero')
el.clear()
el.send_keys('node.xmr.to:18081\nnode1.xmr.to:18082')
btn_apply_monero.click()
time.sleep(1)
with open(settings_path_0) as fs:
settings = json.load(fs)
remotedaemonurls = settings['chainclients']['monero']['remote_daemon_urls']
assert (len(remotedaemonurls) == 2)
btn_apply_monero = wait.until(EC.element_to_be_clickable((By.NAME, 'apply_monero')))
el = driver.find_element(By.NAME, 'remotedaemonurls_monero')
el.clear()
btn_apply_monero.click()
time.sleep(1)
with open(settings_path_0) as fs:
settings = json.load(fs)
assert ('remote_daemon_urls' not in settings['chainclients']['monero'])
print('Test Passed!')
def run_tests():
driver = get_driver()
try:
test_settings(driver)
finally:
driver.close()
if __name__ == '__main__':
test_html()
run_tests()