use http::Method; use http::StatusCode; use raspa::request::{Request, RequestBase}; use raspa::selector::{Selector, SelectorBase}; use serde_json::Value; // use std::collections::HashMap; #[test] fn plain_text_selector() { let html = "
good bye
simple text " .to_string(); let sel = Selector::from_html(html); assert_eq!(sel.css("h1")[0].html(), "good bye
simple textgood bye
simple text " .to_string(); let sel = Selector::from_html(html); assert_eq!( sel.xpath_once("//div/a[1]").unwrap().content(), "first text" ); assert_eq!(sel.xpath("//*[@id='text']")[0].content(), "good bye"); assert_eq!( sel.xpath("//a[contains(@href, 'localhost')]")[0] .attr("href") .unwrap(), "http://localhost" ); assert_eq!( sel.xpath_once("//div[@class='container']/a[3]") .unwrap() .content(), "non link" ); } #[test] fn simple_json_test() { let req = Request::new("https://httpbin.org/json").unwrap(); let resp: Value = req.launch().to_json().expect("cannot parse json"); assert_eq!(resp["slideshow"]["title"], "Sample Slide Show"); } #[test] fn simple_post_request() { let resp: Value = Request::new("https://httpbin.org/post") .unwrap() .method(Method::POST) .launch() .to_json() .expect("cannot parse json"); assert_eq!(resp["url"].as_str().unwrap(), "https://httpbin.org/post"); } // #[test] // fn complex_post_request() { // let form = HashMap::new(); // let attrs = HashMap::new(); // // let resp = Request::new("https://httpbin.org/post") // .unwrap() // .method(Method::POST) // .add_attrs() // }