mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-10-29 00:49:42 +08:00
test(UI-tests): allow ignoring connector tests at runtime (#1766)
Co-authored-by: Anji Reddy <anji.reddy@juspay.in>
This commit is contained in:
@ -247,6 +247,7 @@ async fn should_make_adyen_paypal_payment(web_driver: WebDriver) -> Result<(), W
|
||||
web_driver,
|
||||
&format!("{CHEKOUT_BASE_URL}/saved/202"),
|
||||
vec![
|
||||
Event::Trigger(Trigger::Click(By::Id("payment-submit-btn"))),
|
||||
Event::Assert(Assert::IsPresent("Google")),
|
||||
Event::Assert(Assert::ContainsAny(
|
||||
Selector::QueryParamStr,
|
||||
|
||||
@ -36,6 +36,11 @@ async fn should_make_paypal_payment(web_driver: WebDriver) -> Result<(), WebDriv
|
||||
web_driver,
|
||||
&format!("{CHEKOUT_BASE_URL}/saved/156"),
|
||||
vec![
|
||||
Event::EitherOr(
|
||||
Assert::IsElePresent(By::Css(".reviewButton")),
|
||||
vec![Event::Trigger(Trigger::Click(By::Css(".reviewButton")))],
|
||||
vec![Event::Trigger(Trigger::Click(By::Id("payment-submit-btn")))],
|
||||
),
|
||||
Event::Assert(Assert::IsPresent("status")),
|
||||
Event::Assert(Assert::IsPresent("processing")), // This connector status will be processing for one day
|
||||
],
|
||||
|
||||
@ -33,6 +33,7 @@ async fn should_make_globalpay_paypal_payment(driver: WebDriver) -> Result<(), W
|
||||
driver,
|
||||
&format!("{CHEKOUT_BASE_URL}/saved/46"),
|
||||
vec![
|
||||
Event::Trigger(Trigger::Click(By::Id("payment-submit-btn"))),
|
||||
Event::Assert(Assert::IsPresent("Google")),
|
||||
Event::Assert(Assert::ContainsAny(
|
||||
Selector::QueryParamStr,
|
||||
|
||||
@ -60,6 +60,7 @@ async fn should_make_nuvei_pypl_payment(c: WebDriver) -> Result<(), WebDriverErr
|
||||
c,
|
||||
&format!("{CHEKOUT_BASE_URL}/saved/5"),
|
||||
vec![
|
||||
Event::Trigger(Trigger::Click(By::Id("payment-submit-btn"))),
|
||||
Event::Assert(Assert::IsPresent("Google")),
|
||||
Event::Assert(Assert::ContainsAny(
|
||||
Selector::QueryParamStr,
|
||||
|
||||
@ -19,6 +19,7 @@ async fn should_make_paypal_paypal_wallet_payment(
|
||||
web_driver,
|
||||
&format!("{CHEKOUT_BASE_URL}/saved/21"),
|
||||
vec![
|
||||
Event::Trigger(Trigger::Click(By::Css(".reviewButton"))),
|
||||
Event::Assert(Assert::IsPresent("How Search works")),
|
||||
Event::Assert(Assert::ContainsAny(
|
||||
Selector::QueryParamStr,
|
||||
|
||||
@ -1,6 +1,13 @@
|
||||
use std::{collections::HashMap, env, io::Read, path::MAIN_SEPARATOR, time::Duration};
|
||||
use std::{
|
||||
collections::{HashMap, HashSet},
|
||||
env,
|
||||
io::Read,
|
||||
path::MAIN_SEPARATOR,
|
||||
time::Duration,
|
||||
};
|
||||
|
||||
use async_trait::async_trait;
|
||||
use serde_json::json;
|
||||
use thirtyfour::{components::SelectElement, prelude::*, WebDriver};
|
||||
|
||||
use crate::connector_auth;
|
||||
@ -54,26 +61,10 @@ pub static CHEKOUT_BASE_URL: &str = "https://hs-payments-test.netlify.app";
|
||||
#[async_trait]
|
||||
pub trait SeleniumTest {
|
||||
fn get_saved_testcases(&self) -> serde_json::Value {
|
||||
let env_value = env::var("CONNECTOR_TESTS_FILE_PATH").ok();
|
||||
if env_value.is_none() {
|
||||
return serde_json::json!("");
|
||||
}
|
||||
let path = env_value.unwrap();
|
||||
let mut file = &std::fs::File::open(path).expect("Failed to open file");
|
||||
let mut contents = String::new();
|
||||
file.read_to_string(&mut contents)
|
||||
.expect("Failed to read file");
|
||||
|
||||
// Parse the JSON data
|
||||
serde_json::from_str(&contents).expect("Failed to parse JSON")
|
||||
get_saved_testcases()
|
||||
}
|
||||
fn get_configs(&self) -> connector_auth::ConnectorAuthentication {
|
||||
let path = env::var("CONNECTOR_AUTH_FILE_PATH")
|
||||
.expect("connector authentication file path not set");
|
||||
toml::from_str(
|
||||
&std::fs::read_to_string(path).expect("connector authentication config file not found"),
|
||||
)
|
||||
.expect("Failed to read connector authentication config file")
|
||||
get_configs()
|
||||
}
|
||||
async fn retry_click(
|
||||
&self,
|
||||
@ -496,8 +487,15 @@ pub trait SeleniumTest {
|
||||
) -> Result<(), WebDriverError> {
|
||||
let pypl_url = url.to_string();
|
||||
// To support failure retries
|
||||
self.execute_paypal_steps(web_driver.clone(), &pypl_url, actions.clone())
|
||||
.await
|
||||
let result = self
|
||||
.execute_paypal_steps(web_driver.clone(), &pypl_url, actions.clone())
|
||||
.await;
|
||||
if result.is_err() {
|
||||
self.execute_paypal_steps(web_driver.clone(), &pypl_url, actions.clone())
|
||||
.await
|
||||
} else {
|
||||
result
|
||||
}
|
||||
}
|
||||
async fn execute_paypal_steps(
|
||||
&self,
|
||||
@ -528,24 +526,21 @@ pub trait SeleniumTest {
|
||||
.unwrap(),
|
||||
);
|
||||
let mut pypl_actions = vec![
|
||||
Event::EitherOr(
|
||||
Assert::IsPresent("Forgot email?"),
|
||||
Event::Trigger(Trigger::Sleep(8)),
|
||||
Event::RunIf(
|
||||
Assert::IsPresentNow("Enter your email address to get started"),
|
||||
vec![
|
||||
Event::Trigger(Trigger::SendKeys(By::Id("email"), email)),
|
||||
Event::Trigger(Trigger::Click(By::Id("btnNext"))),
|
||||
Event::Trigger(Trigger::SendKeys(By::Id("password"), pass)),
|
||||
Event::Trigger(Trigger::Click(By::Id("btnLogin"))),
|
||||
],
|
||||
),
|
||||
Event::RunIf(
|
||||
Assert::IsPresentNow("Password"),
|
||||
vec![
|
||||
Event::Trigger(Trigger::SendKeys(By::Id("password"), pass)),
|
||||
Event::Trigger(Trigger::Click(By::Id("btnLogin"))),
|
||||
],
|
||||
),
|
||||
Event::EitherOr(
|
||||
Assert::IsPresent("See Offers and Apply for PayPal Credit"),
|
||||
vec![Event::Trigger(Trigger::Click(By::Css(".reviewButton")))],
|
||||
vec![Event::Trigger(Trigger::Click(By::Id("payment-submit-btn")))],
|
||||
),
|
||||
];
|
||||
pypl_actions.extend(actions);
|
||||
self.complete_actions(&web_driver, pypl_actions).await
|
||||
@ -592,7 +587,7 @@ pub trait SeleniumTest {
|
||||
Assert::IsPresent("Please enter your password"),
|
||||
vec![
|
||||
Event::Trigger(Trigger::SendKeys(By::Css("input[name='password']"), pass)),
|
||||
Event::Trigger(Trigger::Click(By::Css("button.a_l.a_i.a_n.a_m"))),
|
||||
Event::Trigger(Trigger::Click(By::Css("button[type='submit']"))),
|
||||
],
|
||||
vec![
|
||||
Event::Trigger(Trigger::SendKeys(
|
||||
@ -618,6 +613,10 @@ async fn is_text_present_now(driver: &WebDriver, key: &str) -> WebDriverResult<b
|
||||
xpath.push_str(key);
|
||||
xpath.push_str("')]");
|
||||
let result = driver.find(By::XPath(&xpath)).await?;
|
||||
let display: &str = &result.css_value("display").await?;
|
||||
if display.is_empty() || display == "none" {
|
||||
return Err(WebDriverError::CustomError("Element is hidden".to_string()));
|
||||
}
|
||||
result.is_present().await
|
||||
}
|
||||
async fn is_text_present(driver: &WebDriver, key: &str) -> WebDriverResult<bool> {
|
||||
@ -673,10 +672,26 @@ macro_rules! tester_inner {
|
||||
}};
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! function {
|
||||
() => {{
|
||||
fn f() {}
|
||||
fn type_name_of<T>(_: T) -> &'static str {
|
||||
std::any::type_name::<T>()
|
||||
}
|
||||
let name = type_name_of(f);
|
||||
&name[..name.len() - 3]
|
||||
}};
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! tester {
|
||||
($f:ident) => {{
|
||||
use $crate::tester_inner;
|
||||
use $crate::{function, tester_inner};
|
||||
let test_name = format!("{:?}", function!());
|
||||
if (should_ignore_test(&test_name)) {
|
||||
return;
|
||||
}
|
||||
let browser = get_browser();
|
||||
let url = make_url(&browser);
|
||||
let caps = make_capabilities(&browser);
|
||||
@ -684,6 +699,44 @@ macro_rules! tester {
|
||||
}};
|
||||
}
|
||||
|
||||
fn get_saved_testcases() -> serde_json::Value {
|
||||
let env_value = env::var("CONNECTOR_TESTS_FILE_PATH").ok();
|
||||
if env_value.is_none() {
|
||||
return serde_json::json!("");
|
||||
}
|
||||
let path = env_value.unwrap();
|
||||
let mut file = &std::fs::File::open(path).expect("Failed to open file");
|
||||
let mut contents = String::new();
|
||||
file.read_to_string(&mut contents)
|
||||
.expect("Failed to read file");
|
||||
|
||||
// Parse the JSON data
|
||||
serde_json::from_str(&contents).expect("Failed to parse JSON")
|
||||
}
|
||||
fn get_configs() -> connector_auth::ConnectorAuthentication {
|
||||
let path =
|
||||
env::var("CONNECTOR_AUTH_FILE_PATH").expect("connector authentication file path not set");
|
||||
toml::from_str(
|
||||
&std::fs::read_to_string(path).expect("connector authentication config file not found"),
|
||||
)
|
||||
.expect("Failed to read connector authentication config file")
|
||||
}
|
||||
|
||||
pub fn should_ignore_test(name: &str) -> bool {
|
||||
let conf = get_saved_testcases()
|
||||
.get("tests_to_ignore")
|
||||
.unwrap_or(&json!([]))
|
||||
.clone();
|
||||
let tests_to_ignore: HashSet<String> =
|
||||
serde_json::from_value(conf).unwrap_or_else(|_| HashSet::new());
|
||||
// let tests_to_ignore = conf.automation_configs.unwrap().tests_to_ignore.unwrap_or_else(|| HashSet::new());
|
||||
let modules: Vec<_> = name.split("::").collect();
|
||||
let file_match = format!("{}::*", <&str>::clone(&modules[1]));
|
||||
let module_name = modules[1..3].join("::");
|
||||
// Ignore if it matches patterns like nuvei_ui::*, nuvei_ui::should_make_nuvei_eps_payment_test
|
||||
tests_to_ignore.contains(&file_match) || tests_to_ignore.contains(&module_name)
|
||||
}
|
||||
|
||||
pub fn get_browser() -> String {
|
||||
"firefox".to_string()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user