|
| 1 | +use fantoccini::{Client, Locator}; |
| 2 | +use perseus::wait_for_checkpoint; |
| 3 | + |
| 4 | +#[perseus::test] |
| 5 | +async fn main(c: &mut Client) -> Result<(), fantoccini::error::CmdError> { |
| 6 | + c.goto("http://localhost:8080").await?; |
| 7 | + wait_for_checkpoint!("begin", 0, c); |
| 8 | + let url = c.current_url().await?; |
| 9 | + assert!(url.as_ref().starts_with("http://localhost:8080")); |
| 10 | + |
| 11 | + // The greeting was passed through using build state |
| 12 | + wait_for_checkpoint!("initial_state_present", 0, c); |
| 13 | + wait_for_checkpoint!("page_visible", 0, c); |
| 14 | + let greeting = c.find(Locator::Css("p")).await?.text().await?; |
| 15 | + assert_eq!(greeting, "Hello World!"); |
| 16 | + // For some reason, retrieving the inner HTML or text of a `<title>` doens't |
| 17 | + // work |
| 18 | + let title = c.find(Locator::Css("title")).await?.html(false).await?; |
| 19 | + assert!(title.contains("Index Page")); |
| 20 | + |
| 21 | + // Go to `/about` |
| 22 | + c.find(Locator::Id("about-link")).await?.click().await?; |
| 23 | + let url = c.current_url().await?; |
| 24 | + assert!(url.as_ref().starts_with("http://localhost:8080/about")); |
| 25 | + wait_for_checkpoint!("initial_state_not_present", 0, c); |
| 26 | + wait_for_checkpoint!("page_visible", 1, c); |
| 27 | + // Make sure the hardcoded text there exists |
| 28 | + let text = c.find(Locator::Css("p")).await?.text().await?; |
| 29 | + assert_eq!(text, "About."); |
| 30 | + let title = c.find(Locator::Css("title")).await?.html(false).await?; |
| 31 | + assert!(title.contains("About Page")); |
| 32 | + // Make sure we get initial state if we refresh |
| 33 | + c.refresh().await?; |
| 34 | + wait_for_checkpoint!("initial_state_present", 0, c); |
| 35 | + |
| 36 | + Ok(()) |
| 37 | +} |
0 commit comments