commit a1e7b71e6ebe6ca8e1541034d6991558b524026f
parent 4f2b32c19d61c8b6752b4ceb133e824aa652ce9e
Author: Marcel <mtrnord1@gmail.com>
Date: Thu, 11 Jun 2020 15:49:27 +0200
Add initial test
Took 1 hour 43 minutes
Diffstat:
4 files changed, 188 insertions(+), 19 deletions(-)
diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml
@@ -0,0 +1,60 @@
+name: Test Daydream
+
+on:
+ push:
+ branches:
+ - master
+ pull_request:
+ branches:
+ - master
+
+jobs:
+ deploy:
+ runs-on: ubuntu-latest
+ steps:
+ - uses: actions/checkout@v2
+
+ - name: Setup Rust
+ uses: actions-rs/toolchain@v1
+ with:
+ toolchain: stable
+ - name: Setup Wasm Rust
+ uses: actions-rs/toolchain@v1
+ with:
+ toolchain: stable
+ target: wasm32-unknown-unknown
+
+ - name: Setup Node
+ uses: actions/setup-node@v1
+ with:
+ node-version: 14
+ - uses: nanasess/setup-chromedriver@master
+ with:
+ - run: |
+ export DISPLAY=:99
+ chromedriver --url-base=/wd/hub &
+ sudo Xvfb -ac :99 -screen 0 1280x1024x24 > /dev/null 2>&1 &
+
+ - name: Install
+ run: yarn
+
+ - name: Get emscripten SDK
+ run: wget https://github.com/emscripten-core/emsdk/archive/master.zip && unzip master.zip && ./emsdk-master/emsdk install latest && ./emsdk-master/emsdk activate latest
+
+ - name: Install gettext
+ run: sudo apt-get update && sudo apt-get install -y gettext
+
+ - name: Install xtr
+ run: cargo install xtr
+
+ - name: Install cargo-i18n
+ run: cargo install cargo-i18n
+
+ - name: Regenerate translation files
+ run: cargo i18n || exit 0
+
+ - name: Build
+ run: source emsdk-master/emsdk_env.sh && yarn run build
+
+ - name: Run tests
+ run: cargo test
diff --git a/Cargo.toml b/Cargo.toml
@@ -38,19 +38,9 @@ i18n-embed = { version = "0.4", features = ["web-sys-requester"] }
rust-embed = { version = "5", features = ["debug-embed", "compression"]}
[dev-dependencies]
-wasm-bindgen-test = "0.3"
-reqwest = { version = "0.10", features = ["blocking", "json"] }
-futures-timer = { version = "3.0.2", features = ["wasm-bindgen"] }
-
-[dev-dependencies.web-sys]
-version = "0.3"
-features = [
- 'Document',
- 'Element',
- 'HtmlElement',
- 'Node',
- 'Window',
-]
+reqwest = { version = "0.10", features = ["json"] }
+fantoccini = "0.13.1"
+tokio = { version = "0.2", features = ["full"] }
[dependencies.web-sys]
diff --git a/src/app/views/login.rs b/src/app/views/login.rs
@@ -183,7 +183,7 @@ impl Component for Login {
}
}
- <form class="uk-form-stacked uk-margin" onsubmit=self.link.callback(|e: FocusEvent| {e.prevent_default(); Msg::Login})>
+ <form class="uk-form-stacked uk-margin" id="login_form" onsubmit=self.link.callback(|e: FocusEvent| {e.prevent_default(); Msg::Login})>
<div class="uk-margin">
<label class="uk-form-label">
{
@@ -198,6 +198,7 @@ impl Component for Login {
class=homeserver_classes
type="url"
id="homeserver"
+ name="homeserver"
placeholder=
{
tr!(
@@ -223,6 +224,7 @@ impl Component for Login {
<input
class=mxid_classes
id="username"
+ name="username"
placeholder=
{
tr!(
@@ -249,6 +251,7 @@ impl Component for Login {
class=password_classes
type="password"
id="password"
+ name="password"
placeholder=
{
tr!(
@@ -264,7 +267,7 @@ impl Component for Login {
<div class="uk-margin">
<div class="uk-form-controls">
- <button class="uk-button uk-button-primary">
+ <button class="uk-button uk-button-primary" id="login_button">
{
tr!(
// The Login Button of the Login page
diff --git a/tests/web.rs b/tests/web.rs
@@ -1,8 +1,124 @@
//! Test suite for the Web and headless browsers.
-#![cfg(target_arch = "wasm32")]
+use std::{fs, thread};
+use std::process::Command;
+use std::thread::sleep;
+use std::time::Duration;
-extern crate wasm_bindgen_test;
-use wasm_bindgen_test::*;
+use fantoccini::{Client, Locator};
-wasm_bindgen_test_configure!(run_in_browser);
+#[tokio::test]
+async fn test_println() {
+ println!("test_println output");
+}
+
+#[tokio::test]
+async fn test_browser() {
+ let joinable = thread::spawn(move || {
+ let _process = match Command::new("npm").args(&["run", "start:dev"]).spawn() {
+ Ok(process) => process,
+ Err(err) => panic!("Running process error: {}", err),
+ };
+ });
+ let joinable_two = thread::spawn(move || {
+ let _process = match Command::new("chromium-browser")
+ .args(&["--no-sandbox", "--headless", "--port=4444"])
+ .spawn()
+ {
+ Ok(process) => process,
+ Err(err) => panic!("Running process error: {}", err),
+ };
+ });
+
+ println!("Waiting 2min...");
+ sleep(Duration::from_secs(120));
+ println!("Starting browser...");
+ let mut c = Client::new("http://localhost:4444")
+ .await
+ .expect("failed to connect to WebDriver");
+
+ println!("Open Page...");
+ c.goto("http://localhost:8000").await.unwrap();
+
+ let url = c.current_url().await.unwrap();
+ assert_eq!(url.as_ref(), "http://localhost:8000");
+
+ println!("Select Hostname Field");
+ c.find(Locator::Css("input#homeserver"))
+ .await
+ .unwrap()
+ .click()
+ .await
+ .unwrap();
+
+ let mut f = c.form(Locator::Css(".login_form")).await.unwrap();
+ f.set_by_name("homeserver", "http://localhost:8448")
+ .await
+ .unwrap()
+ .submit()
+ .await
+ .unwrap();
+
+
+ let jpeg_data = c.screenshot().await.unwrap();
+
+ fs::write("tests/homeserver_input.jpg", &jpeg_data).unwrap();
+
+ println!("Select MXID Field");
+ c.find(Locator::Css("input#username"))
+ .await
+ .unwrap()
+ .click()
+ .await
+ .unwrap();
+
+ f.set_by_name("username", "@carl:example.com")
+ .await
+ .unwrap()
+ .submit()
+ .await
+ .unwrap();
+
+ let jpeg_data = c.screenshot().await.unwrap();
+
+ fs::write("tests/username_input.jpg", &jpeg_data).unwrap();
+
+ println!("Select Password Field");
+ c.find(Locator::Css("input#password"))
+ .await
+ .unwrap()
+ .click()
+ .await
+ .unwrap();
+
+ f.set_by_name("password", "12345")
+ .await
+ .unwrap()
+ .submit()
+ .await
+ .unwrap();
+
+ let jpeg_data = c.screenshot().await.unwrap();
+ fs::write("tests/password_input.jpg", &jpeg_data).unwrap();
+
+ println!("Press Login");
+ f.submit().await.unwrap();
+
+ c.wait_for_find(Locator::Css("div.scrollable")).await;
+
+ //sleep(Duration::from_secs(5));
+
+ let jpeg_data = c.screenshot().await.unwrap();
+
+ fs::write("tests/main_view.jpg", &jpeg_data).unwrap();
+ joinable.join();
+ joinable_two.join();
+ Command::new("bash")
+ .args(&["-c", "\"pkill -f npm\""])
+ .spawn()
+ .unwrap();
+ Command::new("bash")
+ .args(&["-c", "\"pkill -f node\""])
+ .spawn()
+ .unwrap();
+}