-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add base for GUI tests #2476
Merged
Merged
Add base for GUI tests #2476
Changes from 2 commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
use std::env::current_dir; | ||
use std::fs::{read_to_string, remove_dir_all}; | ||
use std::process::Command; | ||
|
||
fn get_available_browser_ui_test_version_inner(global: bool) -> Option<String> { | ||
let mut command = Command::new("npm"); | ||
command | ||
.arg("list") | ||
.arg("--parseable") | ||
.arg("--long") | ||
.arg("--depth=0"); | ||
if global { | ||
command.arg("--global"); | ||
} | ||
let stdout = command.output().expect("`npm` command not found").stdout; | ||
let lines = String::from_utf8_lossy(&stdout); | ||
lines | ||
.lines() | ||
.find_map(|l| l.split(':').nth(1)?.strip_prefix("browser-ui-test@")) | ||
.map(std::borrow::ToOwned::to_owned) | ||
} | ||
|
||
fn get_available_browser_ui_test_version() -> Option<String> { | ||
get_available_browser_ui_test_version_inner(false) | ||
.or_else(|| get_available_browser_ui_test_version_inner(true)) | ||
} | ||
|
||
fn expected_browser_ui_test_version() -> String { | ||
let content = read_to_string(".github/workflows/main.yml") | ||
.expect("failed to read `.github/workflows/main.yml`"); | ||
for line in content.lines() { | ||
let line = line.trim(); | ||
if let Some(version) = line.strip_prefix("BROWSER_UI_TEST_VERSION:") { | ||
return version.trim().replace('\'', ""); | ||
} | ||
} | ||
panic!("failed to retrieved `browser-ui-test` version"); | ||
} | ||
|
||
fn main() { | ||
let browser_ui_test_version = expected_browser_ui_test_version(); | ||
match get_available_browser_ui_test_version() { | ||
Some(version) => { | ||
if version != browser_ui_test_version { | ||
eprintln!( | ||
"⚠️ Installed version of browser-ui-test (`{version}`) is different than the \ | ||
one used in the CI (`{browser_ui_test_version}`) You can install this version \ | ||
using `npm update browser-ui-test` or by using `npm install browser-ui-test\ | ||
@{browser_ui_test_version}`", | ||
); | ||
} | ||
} | ||
None => { | ||
panic!( | ||
"`browser-ui-test` is not installed. You can install this package using `npm \ | ||
update browser-ui-test` or by using `npm install browser-ui-test\ | ||
@{browser_ui_test_version}`", | ||
); | ||
} | ||
} | ||
|
||
let current_dir = current_dir().expect("failed to retrieve current directory"); | ||
let test_book = current_dir.join("test_book"); | ||
|
||
// Result doesn't matter. | ||
let _ = remove_dir_all(test_book.join("book")); | ||
|
||
let mut cmd = Command::new("cargo"); | ||
cmd.arg("run").arg("build").arg(&test_book); | ||
// Then we run the GUI tests on it. | ||
assert!(cmd.status().is_ok_and(|status| status.success())); | ||
|
||
let book_dir = format!("file://{}", current_dir.join("test_book/book/").display()); | ||
|
||
let mut command = Command::new("npx"); | ||
command | ||
.arg("browser-ui-test") | ||
.args(["--variable", "DOC_PATH", book_dir.as_str()]) | ||
.args(["--test-folder", "tests/gui"]); | ||
if std::env::args().any(|arg| arg == "--disable-headless-test") { | ||
command.arg("--no-headless"); | ||
} | ||
|
||
// Then we run the GUI tests on it. | ||
let status = command.status().expect("failed to get command output"); | ||
assert!(status.success(), "{status:?}"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
// This GUI test checks sidebar hide/show and also its behaviour on smaller | ||
// width. | ||
|
||
// We disable the requests checks because `searchindex.json` will always fail | ||
// locally. | ||
fail-on-request-error: false | ||
go-to: |DOC_PATH| + "index.html" | ||
set-window-size: (1100, 600) | ||
// Need to reload for the new size to be taken account by the JS. | ||
reload: | ||
|
||
store-value: (content_indent, 308) | ||
|
||
define-function: ( | ||
"hide-sidebar", | ||
[], | ||
block { | ||
// The content should be "moved" to the right because of the sidebar. | ||
assert-css: ("#sidebar", {"transform": "none"}) | ||
assert-position: ("#page-wrapper", {"x": |content_indent|}) | ||
|
||
// We now hide the sidebar. | ||
click: "#sidebar-toggle" | ||
wait-for: "body.sidebar-hidden" | ||
// `transform` is 0.3s so we need to wait a bit (0.5s) to ensure the animation is done. | ||
wait-for: 5000 | ||
assert-css-false: ("#sidebar", {"transform": "none"}) | ||
// The page content should now be on the left. | ||
assert-position: ("#page-wrapper", {"x": 0}) | ||
}, | ||
) | ||
|
||
define-function: ( | ||
"show-sidebar", | ||
[], | ||
block { | ||
// The page content should be on the left and the sidebar "moved out". | ||
assert-css: ("#sidebar", {"transform": "matrix(1, 0, 0, 1, -308, 0)"}) | ||
assert-position: ("#page-wrapper", {"x": 0}) | ||
|
||
// We expand the sidebar. | ||
click: "#sidebar-toggle" | ||
wait-for: "body.sidebar-visible" | ||
// `transform` is 0.3s so we need to wait a bit (0.5s) to ensure the animation is done. | ||
wait-for: 5000 | ||
assert-css-false: ("#sidebar", {"transform": "matrix(1, 0, 0, 1, -308, 0)"}) | ||
// The page content should be moved to the right. | ||
assert-position: ("#page-wrapper", {"x": |content_indent|}) | ||
}, | ||
) | ||
|
||
call-function: ("hide-sidebar", {}) | ||
call-function: ("show-sidebar", {}) | ||
|
||
// We now test on smaller width to ensure that the sidebar is collapsed by default. | ||
set-window-size: (900, 600) | ||
reload: | ||
call-function: ("show-sidebar", {}) | ||
call-function: ("hide-sidebar", {}) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lacking anything else to try...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@GuillaumeGomez
Okay, then. Looks like the solution is to turn off the sandbox (at least in CI, which is already isolated into containers).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You need to rustfmt this file. Tabs aren't used for indentation here.