basicswap/tests/basicswap/selenium/test_offer.py

153 lines
4.7 KiB
Python
Raw Normal View History

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# Copyright (c) 2023-2024 tecnovert
2024-11-15 15:21:20 +00:00
# Copyright (c) 2024 The Basicswap developers
# Distributed under the MIT software license, see the accompanying
# file LICENSE or http://www.opensource.org/licenses/mit-license.php.
2023-07-29 13:30:41 +00:00
import json
import time
2023-07-29 13:30:41 +00:00
from urllib.request import urlopen
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import Select
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
2023-11-09 20:28:01 +00:00
from util import get_driver
2023-11-09 20:28:01 +00:00
def test_offer(driver):
2024-11-15 15:21:20 +00:00
node1_url = "http://localhost:12701"
2024-11-15 15:21:20 +00:00
driver.get(node1_url + "/newoffer")
time.sleep(1)
2024-11-15 15:21:20 +00:00
select = Select(driver.find_element(By.ID, "coin_from"))
select.select_by_visible_text("Bitcoin")
select = Select(driver.find_element(By.ID, "coin_to"))
select.select_by_visible_text("Monero")
2024-11-15 15:21:20 +00:00
amt_from = driver.find_element(By.NAME, "amt_from")
amt_to = driver.find_element(By.NAME, "amt_to")
rate = driver.find_element(By.ID, "rate")
amt_from.send_keys("1")
amt_to.send_keys("2")
amt_from.click()
time.sleep(0.5)
2024-11-15 15:21:20 +00:00
rate_value = rate.get_attribute("value")
assert float(rate_value) == 2.0
rate.clear()
2024-11-15 15:21:20 +00:00
rate.send_keys("3")
amt_from.click()
time.sleep(0.5)
2024-11-15 15:21:20 +00:00
amt_to_value = amt_to.get_attribute("value")
assert float(amt_to_value) == 3.0
amt_from.clear()
2024-11-15 15:21:20 +00:00
amt_from.send_keys("2")
amt_to.click()
time.sleep(0.5)
2024-11-15 15:21:20 +00:00
amt_to_value = amt_to.get_attribute("value")
assert float(amt_to_value) == 6.0
amt_from.clear()
amt_to.clear()
rate.clear()
2024-11-15 15:21:20 +00:00
amt_to.send_keys("2")
rate.send_keys("2")
amt_to.click()
time.sleep(0.2)
2024-11-15 15:21:20 +00:00
amt_from_value = amt_from.get_attribute("value")
assert float(amt_from_value) == 1.0
driver.find_element(By.NAME, "continue").click()
WebDriverWait(driver, 20).until(
EC.element_to_be_clickable((By.NAME, "check_offer"))
).click()
WebDriverWait(driver, 20).until(
EC.element_to_be_clickable((By.NAME, "submit_offer"))
).click()
2023-07-29 13:30:41 +00:00
time.sleep(1)
offer_link = driver.find_element(By.XPATH, "//a[contains(text(),'Sent Offer')]")
2024-11-15 15:21:20 +00:00
offer1_id = offer_link.text.split(" ")[2]
2023-07-29 13:30:41 +00:00
2024-11-15 15:21:20 +00:00
driver.get(node1_url + "/newoffer")
2023-07-29 13:30:41 +00:00
time.sleep(1)
2024-11-15 15:21:20 +00:00
select = Select(driver.find_element(By.ID, "coin_from"))
select.select_by_visible_text("Particl")
select = Select(driver.find_element(By.ID, "coin_to"))
select.select_by_visible_text("Monero")
driver.find_element(By.NAME, "amt_from").send_keys("3")
driver.find_element(By.NAME, "amt_to").send_keys("4")
driver.find_element(By.NAME, "continue").click()
WebDriverWait(driver, 20).until(
EC.element_to_be_clickable((By.NAME, "check_offer"))
).click()
WebDriverWait(driver, 20).until(
EC.element_to_be_clickable((By.NAME, "submit_offer"))
).click()
2023-07-29 13:30:41 +00:00
time.sleep(1)
offer_link = driver.find_element(By.XPATH, "//a[contains(text(),'Sent Offer')]")
2024-11-15 15:21:20 +00:00
offer2_id = offer_link.text.split(" ")[2]
driver.get(node1_url + "/offer/" + offer1_id)
WebDriverWait(driver, 20).until(
EC.element_to_be_clickable((By.NAME, "repeat_offer"))
).click()
WebDriverWait(driver, 20).until(
EC.element_to_be_clickable((By.NAME, "check_offer"))
).click()
WebDriverWait(driver, 20).until(
EC.element_to_be_clickable((By.NAME, "submit_offer"))
).click()
2023-07-29 13:30:41 +00:00
time.sleep(1)
offer_link = driver.find_element(By.XPATH, "//a[contains(text(),'Sent Offer')]")
2024-11-15 15:21:20 +00:00
offer3_id = offer_link.text.split(" ")[2]
2023-07-29 13:30:41 +00:00
2024-11-15 15:21:20 +00:00
offer3_json = json.loads(urlopen(node1_url + "/json/offers/" + offer3_id).read())[0]
assert offer3_json["coin_from"] == "Bitcoin"
assert offer3_json["coin_to"] == "Monero"
2023-07-29 13:30:41 +00:00
2024-11-15 15:21:20 +00:00
driver.get(node1_url + "/offer/" + offer2_id)
WebDriverWait(driver, 20).until(
EC.element_to_be_clickable((By.NAME, "repeat_offer"))
).click()
2023-07-29 13:30:41 +00:00
time.sleep(1) # Add time for setupCustomSelect to fire
2024-11-15 15:21:20 +00:00
WebDriverWait(driver, 20).until(
EC.element_to_be_clickable((By.NAME, "check_offer"))
).click()
WebDriverWait(driver, 20).until(
EC.element_to_be_clickable((By.NAME, "submit_offer"))
).click()
2023-07-29 13:30:41 +00:00
time.sleep(1)
offer_link = driver.find_element(By.XPATH, "//a[contains(text(),'Sent Offer')]")
2024-11-15 15:21:20 +00:00
offer4_id = offer_link.text.split(" ")[2]
2023-07-29 13:30:41 +00:00
2024-11-15 15:21:20 +00:00
offer4_json = json.loads(urlopen(node1_url + "/json/offers/" + offer4_id).read())[0]
assert offer4_json["coin_from"] == "Particl"
assert offer4_json["coin_to"] == "Monero"
2024-11-15 15:21:20 +00:00
print("Test Passed!")
2023-11-09 20:28:01 +00:00
2023-11-09 20:28:01 +00:00
def run_tests():
driver = get_driver()
try:
test_offer(driver)
finally:
driver.close()
2024-11-15 15:21:20 +00:00
if __name__ == "__main__":
2023-11-09 20:28:01 +00:00
run_tests()