From 18d9ef80b040c19835e94d470f656500af864364 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Mon, 28 Dec 2020 16:43:53 +0000 Subject: [PATCH] wip screenshots etc. Signed-off-by: Ian Jackson --- wdriver.rs | 56 ++++++++++++++++++++++++++++++------------- wdriver/wdt-simple.rs | 11 +++------ 2 files changed, 42 insertions(+), 25 deletions(-) diff --git a/wdriver.rs b/wdriver.rs index cd3e8fae..8f09b62a 100644 --- a/wdriver.rs +++ b/wdriver.rs @@ -24,6 +24,7 @@ pub use t4::WebDriverCommands; pub use std::env; pub use std::fs; pub use std::collections::hash_map::HashMap; +pub use std::convert::TryInto; pub use std::io::{BufRead, BufReader, ErrorKind, Write}; pub use std::net::TcpStream; pub use std::ops::Deref; @@ -121,9 +122,11 @@ pub struct DirSubst { pub src: String, } +#[derive(Clone,Debug)] pub struct RawSubst(HashMap); -pub struct ExtendedSubst<'b, B: Subst, X: Subst>(&'b B, X); +#[derive(Clone,Debug)] +pub struct ExtendedSubst(B, X); impl<'i, T: AsRef + 'i, @@ -138,10 +141,11 @@ impl<'i, } } -pub trait Subst : Sized { +pub trait Subst : Clone + Sized { fn get(&self, kw: &str) -> Option; + fn also>(&self, xl: L) -> ExtendedSubst { - ExtendedSubst(self, xl.into()) + ExtendedSubst(self.clone(), xl.into()) } #[throws(AE)] @@ -182,7 +186,7 @@ impl Subst for RawSubst { } } -impl<'b, B:Subst, X:Subst> Subst for ExtendedSubst<'b, B, X> { +impl Subst for ExtendedSubst { fn get(&self, kw: &str) -> Option { self.1.get(kw).or_else(|| self.0.get(kw)) } @@ -524,7 +528,7 @@ _ = "error" # rocket impl DirSubst { #[throws(AE)] - fn otter>(&self, args: &[S]) { + pub fn otter>(&self, args: &[S]) { let ds = self; let exe = ds.subst(&"@target@/debug/otter")?; (||{ @@ -553,18 +557,6 @@ pub fn prepare_game(ds: &DirSubst) { --reset-table @specs@/test.table.toml \ server::dummy @specs@/demo.game.toml \ ")?).context("reset table")?; - - for u in StaticUser::iter() { - let nick: &str = u.into(); - let token = u.get_str("Token").expect("StaticUser missing Token"); - ds.otter(&ds - .also([("nick", nick), - ("token", token)].iter()) - .ss("--super \ - --account server:@nick@ \ - --fixed-token @token@ \ - join-game server::dummy")?)? - } } #[throws(AE)] @@ -594,6 +586,7 @@ fn prepare_thirtyfour() -> (T4d, ScreenShotCount) { (driver, count) } +#[derive(Debug)] pub struct Window { name: String, } @@ -767,3 +760,32 @@ pub fn setup(exe_module_path: &str) -> Setup { final_hook } } + +impl Setup { + #[throws(AE)] + pub fn setup_static_users(&mut self) -> Vec { + #[throws(AE)] + fn mk(su: &mut Setup, u: StaticUser) -> Window { + let nick: &str = u.into(); + let token = u.get_str("Token").expect("StaticUser missing Token"); + let subst = su.ds.also([("nick", nick), + ("token", token)].iter()); + su.ds.otter(&subst + .ss("--super \ + --account server:@nick@ \ + --fixed-token @token@ \ + join-game server::dummy")?)?; + let w = su.new_window(nick)?; + let url = subst.subst(&"@url@/?@token@")?; + su.w(&w)?.get(url)?; + su.w(&w)?.screenshot("initial")?; + w + } + StaticUser::iter().map( + |u| mk(self, u) + .with_context(|| format!("{:?}", u)) + .context("make static user") + ) + .collect::,AE>>()? + } +} diff --git a/wdriver/wdt-simple.rs b/wdriver/wdt-simple.rs index 986dda81..1d2fad00 100644 --- a/wdriver/wdt-simple.rs +++ b/wdriver/wdt-simple.rs @@ -7,12 +7,7 @@ use otter_webdriver_tests::*; #[throws(AE)] fn main(){ let mut su = setup(module_path!()).always_context("setup")?; - - let w1 = su.new_window("alice")?; - let url = su.ds.subst(&"@url@/?zonk")?; - su.w(&w1)?.get(url)?; - su.w(&w1)?.screenshot("testalice")?; - - debug!("ok"); - info!("hi! {:#?}", &su.ds); + let [alice, bob] : [Window; 2] = + su.setup_static_users()?.try_into().unwrap(); + debug!("ok {:?} {:?}", alice, bob); } -- 2.30.2