Skip to main content

NetworkInterception

Struct NetworkInterception 

Source
pub struct NetworkInterception { /* private fields */ }
Expand description

Network interception handler

Implementations§

Source§

impl NetworkInterception

Source

pub fn new() -> Self

Create a new network interception handler

Source

pub const fn capture_all(self) -> Self

Enable capturing all requests

Source

pub const fn block_unmatched(self) -> Self

Block unmatched requests

Source

pub fn start(&mut self)

Start interception

Source

pub fn stop(&mut self)

Stop interception

Source

pub const fn is_active(&self) -> bool

Check if interception is active

Source

pub fn route(&mut self, route: Route)

Add a route

Source

pub fn get(&mut self, pattern: &str, response: MockResponse)

Add a GET route

Source

pub fn post(&mut self, pattern: &str, response: MockResponse)

Add a POST route

Source

pub fn put(&mut self, pattern: &str, response: MockResponse)

Add a PUT route

Source

pub fn delete(&mut self, pattern: &str, response: MockResponse)

Add a DELETE route

Source

pub fn handle_request( &mut self, url: &str, method: HttpMethod, headers: HashMap<String, String>, body: Option<Vec<u8>>, ) -> Option<MockResponse>

Handle an incoming request

Source

pub fn captured_requests(&self) -> Vec<CapturedRequest>

Get all captured requests

Source

pub fn requests_matching(&self, pattern: &UrlPattern) -> Vec<CapturedRequest>

Get captured requests matching a URL pattern

Source

pub fn requests_by_method(&self, method: HttpMethod) -> Vec<CapturedRequest>

Get captured requests by method

Source

pub fn assert_requested(&self, pattern: &UrlPattern) -> ProbarResult<()>

Assert a request was made

Source

pub fn assert_requested_times( &self, pattern: &UrlPattern, times: usize, ) -> ProbarResult<()>

Assert a request was made N times

Source

pub fn assert_not_requested(&self, pattern: &UrlPattern) -> ProbarResult<()>

Assert no requests were made matching a pattern

Source

pub fn clear_captured(&self)

Clear captured requests

Source

pub fn route_count(&self) -> usize

Get route count

Source

pub fn clear_routes(&mut self)

Clear all routes

Source

pub fn abort(&mut self, pattern: &str, reason: AbortReason)

Abort requests matching a pattern with a specific reason

Per Playwright: page.route('**/api/*', route => route.abort())

Source

pub fn abort_pattern(&mut self, pattern: UrlPattern, reason: AbortReason)

Abort requests matching a pattern (default reason: Aborted)

Source

pub fn find_request(&self, pattern: &UrlPattern) -> Option<CapturedRequest>

Wait for a request matching a pattern (synchronous check)

Per Playwright: page.waitForRequest(url)

Source

pub fn find_response_for(&self, pattern: &UrlPattern) -> Option<MockResponse>

Wait for a response matching a pattern (returns the response from route)

Per Playwright: page.waitForResponse(url)

Source

pub fn was_aborted(&self, pattern: &UrlPattern) -> bool

Check if a request was aborted

Source

pub fn captured_responses(&self) -> Vec<MockResponse>

Get captured responses (mock responses that were returned)

Trait Implementations§

Source§

impl Debug for NetworkInterception

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for NetworkInterception

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.