Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
jonhoo committed Feb 19, 2022
2 parents eb77417 + 0ef6a2a commit 5d94d36
Show file tree
Hide file tree
Showing 38 changed files with 3,019 additions and 473 deletions.
15 changes: 15 additions & 0 deletions .codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
coverage:
range: 90..100 # set a high standard for ourselves
round: down
precision: 2
status:
project:
default:
threshold: 1%
ignore:
- "ci"
- "tests"
# Make less noisy comments
comment:
layout: "files"
require_changes: yes
6 changes: 6 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
version: 2
updates:
- package-ecosystem: cargo
directory: /
schedule:
interval: daily
27 changes: 27 additions & 0 deletions .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
on:
push:
branches: [master]
pull_request:
name: coverage
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Install browsers
run: |
./ci/ubuntu-latest-firefox
./ci/ubuntu-latest-chrome
- name: Install cargo-tarpaulin
uses: actions-rs/install@v0.1
with:
crate: cargo-tarpaulin
version: latest
use-tool-cache: true
- name: Generate code coverage
run: |
cargo tarpaulin --verbose --timeout 120 --out Xml
- name: Upload to codecov.io
uses: codecov/codecov-action@v2
with:
fail_ci_if_error: true
25 changes: 25 additions & 0 deletions .github/workflows/features.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
on:
push:
branches: [master]
pull_request:
name: cargo hack
jobs:
check:
runs-on: ubuntu-latest
steps:
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
- uses: actions/checkout@v2
- name: Install cargo-hack
uses: actions-rs/install@v0.1
with:
crate: cargo-hack
version: latest
use-tool-cache: true
- name: cargo hack
uses: actions-rs/cargo@v1
with:
command: hack
args: --feature-powerset --exclude-features bench_private check
32 changes: 32 additions & 0 deletions .github/workflows/minimal.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
on:
push:
branches: [master]
pull_request:
name: With dependencies at minimal versions
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: nightly
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
- uses: actions/checkout@v2
- name: Install browsers
run: |
./ci/ubuntu-latest-firefox
./ci/ubuntu-latest-chrome
- name: cargo update -Zminimal-versions
uses: actions-rs/cargo@v1
with:
command: update
toolchain: nightly
args: -Zminimal-versions
- name: cargo test
uses: actions-rs/cargo@v1
with:
command: test
19 changes: 19 additions & 0 deletions .github/workflows/msrv.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
on:
push:
branches: [master]
pull_request:
name: Minimum Supported Rust Version
jobs:
check:
runs-on: ubuntu-latest
steps:
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: 1.53.0 # or patterns
override: true
- uses: actions/checkout@v2
- name: cargo +1.52.0 check
uses: actions-rs/cargo@v1
with:
command: check
36 changes: 36 additions & 0 deletions .github/workflows/style.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
on:
push:
branches: [master]
pull_request:
name: lint
jobs:
style:
runs-on: ubuntu-latest
name: ${{ matrix.toolchain }}
strategy:
fail-fast: false
matrix:
toolchain: [stable, beta]
steps:
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: ${{ matrix.toolchain }}
components: rustfmt, clippy
- uses: actions/checkout@v2
- name: cargo fmt --check
uses: actions-rs/cargo@v1
with:
command: fmt
args: --check
- name: cargo doc
uses: actions-rs/cargo@v1
if: always()
with:
command: doc
args: --no-deps --all-features
- name: cargo clippy
uses: actions-rs/clippy-check@v1
if: always()
with:
token: ${{ secrets.GITHUB_TOKEN }}
36 changes: 36 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
on:
push:
branches: [master]
pull_request:
name: cargo test
jobs:
test:
runs-on: ${{ matrix.os }}
name: ${{ matrix.os }} / ${{ matrix.browser }} (${{ matrix.toolchain }})
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
browser: [firefox, chrome]
toolchain: [stable]
include:
- os: ubuntu-latest
browser: chrome
toolchain: beta
- os: ubuntu-latest
browser: chrome
toolchain: nightly
steps:
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: ${{ matrix.toolchain }}
- uses: actions/checkout@v2
- name: Install ${{ matrix.browser }}
run: |
./ci/${{ matrix.os }}-${{ matrix.browser }}
- name: cargo test
uses: actions-rs/cargo@v1
with:
command: test
args: ${{ matrix.browser }}
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
target/
**/*.rs.bk
Cargo.lock
/.idea
/.idea
*.iml
32 changes: 0 additions & 32 deletions .travis.yml

This file was deleted.

30 changes: 17 additions & 13 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "fantoccini"
version = "0.17.7"
version = "0.19.0-rc.1"
edition = "2018"

description = "High-level API for programmatically interacting with web pages through WebDriver."
Expand All @@ -23,25 +23,29 @@ native-tls = ["hyper-tls"]
rustls-tls = ["hyper-rustls"]

[dependencies]
webdriver = { version = "0.43.0", default-features = false }
webdriver = { version = "0.44", default-features = false }
url = "2.2.2"
serde = { version = "1.0", features = [ "derive" ] }
serde_json = "1.0"
futures-core = "0.3.0"
futures-util = "0.3.0"
tokio = { version = "1", features = [ "sync", "rt" ] }
hyper = { version = "0.14", features = [ "stream", "client", "http1", "http2" ] }
cookie = { version = "0.14", features = ["percent-encode"] }
serde = { version = "1.0.103", features = ["derive"] }
serde_json = "1.0.25"
futures-core = "0.3"
futures-util = "0.3"
tokio = { version = "1", features = ["sync", "rt"] }
hyper = { version = "0.14", features = ["stream", "client", "http1", "http2"] }
cookie = { version = "0.16.0", features = ["percent-encode"] }
base64 = "0.13"
hyper-rustls = { version = "0.22.1", optional = true }
hyper-rustls = { version = "0.23.0", optional = true }
hyper-tls = { version = "0.5.0", optional = true }
mime = "0.3.9"
http = "0.2"
time = "0.2.26"
time = "0.3"

# to make -Zminimal-versions happy
# remove gcc and winapi 0.0.1 from build tree
_time01 = { version = "0.1.34", package = "time" }

[dev-dependencies]
tokio = { version = "1", features = [ "full" ] }
hyper = { version = "0.14", features = [ "server", "tcp" ] }
tokio = { version = "1", features = ["full"] }
hyper = { version = "0.14", features = ["server", "tcp"] }
serial_test = "0.5"

[package.metadata.docs.rs]
Expand Down
40 changes: 28 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

[![Crates.io](https://img.shields.io/crates/v/fantoccini.svg)](https://crates.io/crates/fantoccini)
[![Documentation](https://docs.rs/fantoccini/badge.svg)](https://docs.rs/fantoccini/)
[![Build Status](https://travis-ci.com/jonhoo/fantoccini.svg?branch=master)](https://travis-ci.com/jonhoo/fantoccini)
[![codecov](https://codecov.io/gh/jonhoo/fantoccini/branch/master/graph/badge.svg?token=NteBJ0F7Ok)](https://codecov.io/gh/jonhoo/fantoccini)
[![Gitter chat](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/fantoccini-rs/Lobby)

A high-level API for programmatically interacting with web pages through WebDriver.
Expand All @@ -23,13 +23,7 @@ source code, and `Client::raw_client_for` to build a raw HTTP request for a part
## Examples

These examples all assume that you have a [WebDriver compatible] process running on port 4444.
A quick way to get one is to run [`geckodriver`] at the command line. The code also has
partial support for the legacy WebDriver protocol used by `chromedriver` and `ghostdriver`.

The examples will be using `panic!` or `unwrap` generously when errors occur (see `map_err`)
--- you should probably not do that in your code, and instead deal with errors when they occur.
This is particularly true for methods that you *expect* might fail, such as lookups by CSS
selector.
A quick way to get one is to run [`geckodriver`] at the command line.

Let's start out clicking around on Wikipedia:

Expand All @@ -39,7 +33,7 @@ use fantoccini::{Client, Locator};
// let's set up the sequence of steps we want the browser to take
#[tokio::main]
async fn main() -> Result<(), fantoccini::error::CmdError> {
let mut c = Client::new("http://localhost:4444").await.expect("failed to connect to WebDriver");
let c = Client::new("http://localhost:4444").await.expect("failed to connect to WebDriver");

// first, go to the Wikipedia page for Foobar
c.goto("https://en.wikipedia.org/wiki/Foobar").await?;
Expand Down Expand Up @@ -67,7 +61,7 @@ Let's make the program do that for us instead:
// go to the Wikipedia frontpage this time
c.goto("https://www.wikipedia.org/").await?;
// find the search form, fill it out, and submit it
let mut f = c.form(Locator::Css("#search-form")).await?;
let f = c.form(Locator::Css("#search-form")).await?;
f.set_by_name("search", "foobar").await?
.submit().await?;

Expand All @@ -85,14 +79,21 @@ What if we want to download a raw file? Fantoccini has you covered:
// go back to the frontpage
c.goto("https://www.wikipedia.org/").await?;
// find the source for the Wikipedia globe
let mut img = c.find(Locator::Css("img.central-featured-logo")).await?;
let img = c.find(Locator::Css("img.central-featured-logo")).await?;
let src = img.attr("src").await?.expect("image should have a src");
// now build a raw HTTP client request (which also has all current cookies)
let raw = img.client().raw_client_for(fantoccini::Method::GET, &src).await?;

// we then read out the image bytes
use futures_util::TryStreamExt;
let pixels = raw.into_body().try_concat().await.map_err(fantoccini::error::CmdError::from)?;
let pixels = raw
.into_body()
.try_fold(Vec::new(), |mut data, chunk| async move {
data.extend_from_slice(&chunk);
Ok(data)
})
.await
.map_err(fantoccini::error::CmdError::from)?;
// and voilla, we now have the bytes for the Wikipedia logo!
assert!(pixels.len() > 0);
println!("Wikipedia logo is {}b", pixels.len());
Expand All @@ -102,9 +103,24 @@ println!("Wikipedia logo is {}b", pixels.len());

For more examples, take a look at the `examples/` directory.

# Contributing to fantoccini

The following information applies only to developers interested in contributing
to this project. If you simply want to use it to automate web browsers you can
skip this section.

## How to run tests

The tests assume that you have [`chromedriver`] and [`geckodriver`] already running on your system.
You can download them using the links above. Then run them from separate tabs in your terminal.
They will stay running until terminated with Ctrl+C or until the terminal session is closed.

Then run `cargo test` from this project directory.

[WebDriver protocol]: https://www.w3.org/TR/webdriver/
[CSS selectors]: https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Selectors
[powerful]: https://developer.mozilla.org/en-US/docs/Web/CSS/Pseudo-classes
[operators]: https://developer.mozilla.org/en-US/docs/Web/CSS/Attribute_selectors
[WebDriver compatible]: https://github.com/Fyrd/caniuse/issues/2757#issuecomment-304529217
[`geckodriver`]: https://github.com/mozilla/geckodriver
[`chromedriver`]: https://chromedriver.chromium.org/downloads
Loading

0 comments on commit 5d94d36

Please sign in to comment.