Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
SeleniumHQ
GitHub Repository: SeleniumHQ/Selenium
Path: blob/trunk/rust/tests/skills_tests.rs
10192 views
1
// Licensed to the Software Freedom Conservancy (SFC) under one
2
// or more contributor license agreements. See the NOTICE file
3
// distributed with this work for additional information
4
// regarding copyright ownership. The SFC licenses this file
5
// to you under the Apache License, Version 2.0 (the
6
// "License"); you may not use this file except in compliance
7
// with the License. You may obtain a copy of the License at
8
//
9
// http://www.apache.org/licenses/LICENSE-2.0
10
//
11
// Unless required by applicable law or agreed to in writing,
12
// software distributed under the License is distributed on an
13
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
// KIND, either express or implied. See the License for the
15
// specific language governing permissions and limitations
16
// under the License.
17
18
use tempfile::tempdir;
19
20
mod common;
21
use common::get_selenium_manager;
22
23
#[test]
24
fn skills_test_default() {
25
let tmp_dir = tempdir().expect("Unable to create temp directory");
26
let skills_file = tmp_dir.path().join("skills").join("skills.md");
27
28
let mut cmd = get_selenium_manager();
29
cmd.current_dir(tmp_dir.path())
30
.arg("--init-skills")
31
.assert()
32
.success();
33
34
assert!(skills_file.exists());
35
36
let content = std::fs::read_to_string(skills_file).expect("Unable to read skills.md");
37
assert!(content.contains("# Selenium Skills & Best Practices"));
38
}
39
40
#[test]
41
fn skills_test_fallback() {
42
let tmp_dir = tempdir().expect("Unable to create temp directory");
43
let skills_dir = tmp_dir.path().join("skills");
44
std::fs::create_dir_all(&skills_dir).expect("Unable to create directory");
45
let default_skills_file = skills_dir.join("skills.md");
46
std::fs::write(&default_skills_file, "Original").expect("Unable to write file");
47
let fallback_file = tmp_dir.path().join("selenium.md");
48
49
let mut cmd = get_selenium_manager();
50
cmd.current_dir(tmp_dir.path())
51
.arg("--init-skills")
52
.assert()
53
.success();
54
55
assert!(fallback_file.exists());
56
let content = std::fs::read_to_string(fallback_file).expect("Unable to read selenium.md");
57
assert!(content.contains("# Selenium Skills & Best Practices"));
58
}
59
60
#[test]
61
fn skills_test_custom_name() {
62
let tmp_dir = tempdir().expect("Unable to create temp directory");
63
let custom_file = tmp_dir.path().join("my-skills.txt");
64
65
let mut cmd = get_selenium_manager();
66
cmd.current_dir(tmp_dir.path())
67
.arg("--init-skills")
68
.arg("my-skills.txt")
69
.assert()
70
.success();
71
72
assert!(custom_file.exists());
73
let content = std::fs::read_to_string(custom_file).expect("Unable to read file");
74
assert!(content.contains("# Selenium Skills & Best Practices"));
75
}
76
77
#[test]
78
fn skills_no_overwrite_test() {
79
let tmp_dir = tempdir().expect("Unable to create temp directory");
80
let skills_dir = tmp_dir.path().join("skills");
81
std::fs::create_dir_all(&skills_dir).expect("Unable to create directory");
82
let skills_file = skills_dir.join("skills.md");
83
std::fs::write(&skills_file, "Original content").expect("Unable to write file");
84
85
let mut cmd = get_selenium_manager();
86
cmd.current_dir(tmp_dir.path())
87
.arg("--init-skills")
88
.assert()
89
.success();
90
91
// It should NOT overwrite skills/skills.md, but instead fallback to selenium.md
92
let content = std::fs::read_to_string(&skills_file).expect("Unable to read skills.md");
93
assert_eq!(content, "Original content");
94
95
let fallback_file = tmp_dir.path().join("selenium.md");
96
assert!(fallback_file.exists());
97
}
98
99
#[test]
100
fn skills_custom_no_overwrite_test() {
101
let tmp_dir = tempdir().expect("Unable to create temp directory");
102
let custom_file = tmp_dir.path().join("my-skills.md");
103
std::fs::write(&custom_file, "Original content").expect("Unable to write file");
104
105
let mut cmd = get_selenium_manager();
106
cmd.current_dir(tmp_dir.path())
107
.arg("--init-skills")
108
.arg("my-skills.md")
109
.assert()
110
.failure();
111
112
let content = std::fs::read_to_string(custom_file).expect("Unable to read file");
113
assert_eq!(content, "Original content");
114
}
115
116