From b389890703f0dce2ab7c39f1b23e5abf8bcf272f Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Thu, 31 Dec 2020 00:51:56 +0000 Subject: [PATCH] wip pos thing Signed-off-by: Ian Jackson --- wdriver.rs | 18 +++++++++++++++--- wdriver/wdt-simple.rs | 9 ++++----- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/wdriver.rs b/wdriver.rs index 5665af38..836ec68c 100644 --- a/wdriver.rs +++ b/wdriver.rs @@ -44,9 +44,10 @@ pub use std::time; pub use otter::commands::{MgmtCommand, MgmtResponse}; pub use otter::commands::{MgmtGameInstruction, MgmtGameResponse}; pub use otter::commands::{MgmtGameUpdateMode}; -pub use otter::gamestate::Generation; +pub use otter::gamestate::{self, Generation}; pub use otter::global::InstanceName; pub use otter::mgmtchannel::MgmtChannel; +pub use otter::spec::{Coord, Pos, PosC}; pub type T4d = t4::WebDriver; pub type WDE = t4::error::WebDriverError; @@ -737,7 +738,7 @@ impl Debug for WindowGuard<'_> { impl<'g> WindowGuard<'g> { #[throws(AE)] - fn find_piece(&'g self, pieceid: &'g str) -> PieceElement<'g> { + pub fn find_piece(&'g self, pieceid: &'g str) -> PieceElement<'g> { let id = format!("use{}", pieceid); let elem = self.su.driver.find_element(By::Id(&id))?; PieceElement { @@ -765,7 +766,18 @@ impl<'g> Deref for PieceElement<'g> { impl<'g> PieceElement<'g> { #[throws(AE)] - fn pos(&self) -> WebPos { + pub fn posg(&self) -> Pos { + (||{ + let x = self.get_attribute("x")?.ok_or(anyhow!("x"))?.parse()?; + let y = self.get_attribute("x")?.ok_or(anyhow!("y"))?.parse()?; + Ok::<_,AE>(PosC([x,y])) + })() + .with_context(|| self.pieceid.to_owned()) + .context("read position of piece out of x,y attributes")? + } + + #[throws(AE)] + pub fn pos(&self) -> WebPos { (||{ Ok::<_,AE>( todo!() ) })() diff --git a/wdriver/wdt-simple.rs b/wdriver/wdt-simple.rs index 99df7246..b615bd02 100644 --- a/wdriver/wdt-simple.rs +++ b/wdriver/wdt-simple.rs @@ -19,18 +19,17 @@ fn main(){ { let mut w = su.w(&alice)?; w.synch()?; - let p1 = w.find_element(By::Id("use1.1"))?; + let p1 = w.find_piece("1.1")?; let p2 = w.find_element(By::Id("use2.1"))?; dbg!(p1.rect()?, p1.tag_name(), p1.class_name(), p1.id(), - p1.text(), + p1.get_attribute("x"), + p1.get_attribute("y"), + p1.posg(), ); - dbg!(p2.rect()?); - dbg!(w.find_element(By::Id("use3.1"))?.rect()?); - dbg!(w.find_element(By::Id("use4.1"))?.rect()?); w.action_chain() .move_to_element_center(&p1) -- 2.30.2