fix: prevent find flags from leaking into fill value (#955)
This commit is contained in:
+49
-7
@@ -1742,10 +1742,6 @@ fn parse_find(rest: &[&str], id: &str) -> Result<Value, ParseError> {
|
|||||||
usage: "find <locator> <value> [action] [text]",
|
usage: "find <locator> <value> [action] [text]",
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
let name_idx = rest.iter().position(|&s| s == "--name");
|
|
||||||
let name = name_idx.and_then(|i| rest.get(i + 1).copied());
|
|
||||||
let exact = rest.contains(&"--exact");
|
|
||||||
|
|
||||||
match *locator {
|
match *locator {
|
||||||
"role" | "text" | "label" | "placeholder" | "alt" | "title" | "testid" | "first"
|
"role" | "text" | "label" | "placeholder" | "alt" | "title" | "testid" | "first"
|
||||||
| "last" => {
|
| "last" => {
|
||||||
@@ -1765,10 +1761,41 @@ fn parse_find(rest: &[&str], id: &str) -> Result<Value, ParseError> {
|
|||||||
},
|
},
|
||||||
})?;
|
})?;
|
||||||
let subaction = rest.get(2).unwrap_or(&"click");
|
let subaction = rest.get(2).unwrap_or(&"click");
|
||||||
let fill_value = if rest.len() > 3 {
|
let mut name: Option<&str> = None;
|
||||||
Some(rest[3..].join(" "))
|
let mut exact = false;
|
||||||
} else {
|
let mut fill_parts: Vec<&str> = Vec::new();
|
||||||
|
|
||||||
|
if rest.len() > 3 {
|
||||||
|
let mut i = 3;
|
||||||
|
while i < rest.len() {
|
||||||
|
match rest[i] {
|
||||||
|
"--exact" => {
|
||||||
|
exact = true;
|
||||||
|
i += 1;
|
||||||
|
}
|
||||||
|
"--name" => {
|
||||||
|
let n =
|
||||||
|
rest.get(i + 1)
|
||||||
|
.ok_or_else(|| ParseError::MissingArguments {
|
||||||
|
context: format!("find {}", locator),
|
||||||
|
usage:
|
||||||
|
"find role <role> [action] [--name <name>] [--exact]",
|
||||||
|
})?;
|
||||||
|
name = Some(*n);
|
||||||
|
i += 2;
|
||||||
|
}
|
||||||
|
token => {
|
||||||
|
fill_parts.push(token);
|
||||||
|
i += 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let fill_value = if fill_parts.is_empty() {
|
||||||
None
|
None
|
||||||
|
} else {
|
||||||
|
Some(fill_parts.join(" "))
|
||||||
};
|
};
|
||||||
|
|
||||||
match *locator {
|
match *locator {
|
||||||
@@ -3324,6 +3351,21 @@ mod tests {
|
|||||||
assert!(cmd.get("value").is_none());
|
assert!(cmd.get("value").is_none());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_find_role_fill_does_not_include_flags_in_value() {
|
||||||
|
let cmd = parse_command(
|
||||||
|
&args("find role textbox fill hello --name username --exact"),
|
||||||
|
&default_flags(),
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
assert_eq!(cmd["action"], "getbyrole");
|
||||||
|
assert_eq!(cmd["role"], "textbox");
|
||||||
|
assert_eq!(cmd["subaction"], "fill");
|
||||||
|
assert_eq!(cmd["name"], "username");
|
||||||
|
assert_eq!(cmd["exact"], true);
|
||||||
|
assert_eq!(cmd["value"], "hello");
|
||||||
|
}
|
||||||
|
|
||||||
// === Download Tests ===
|
// === Download Tests ===
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|||||||
Reference in New Issue
Block a user