mirror of
https://github.com/servo/servo.git
synced 2025-07-24 15:50:21 +01:00
Auto merge of #23585 - georgeroman:tag_name_selector_for_find_element_wd_commands, r=jdm
Implement tag name selector for FindElement and related WebDriver commands <!-- Please describe your changes on the following line: --> --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `___` with appropriate data: --> - [X] `./mach build -d` does not report any errors - [X] `./mach test-tidy` does not report any errors <!-- Either: --> - [X] There are tests for these changes <!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.--> <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. --> <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/23585) <!-- Reviewable:end -->
This commit is contained in:
commit
75275965f0
8 changed files with 211 additions and 72 deletions
|
@ -2019,6 +2019,14 @@ impl ScriptThread {
|
|||
reply,
|
||||
)
|
||||
},
|
||||
WebDriverScriptCommand::FindElementTagName(selector, reply) => {
|
||||
webdriver_handlers::handle_find_element_tag_name(
|
||||
&*documents,
|
||||
pipeline_id,
|
||||
selector,
|
||||
reply,
|
||||
)
|
||||
},
|
||||
WebDriverScriptCommand::FindElementsCSS(selector, reply) => {
|
||||
webdriver_handlers::handle_find_elements_css(
|
||||
&*documents,
|
||||
|
@ -2027,6 +2035,14 @@ impl ScriptThread {
|
|||
reply,
|
||||
)
|
||||
},
|
||||
WebDriverScriptCommand::FindElementsTagName(selector, reply) => {
|
||||
webdriver_handlers::handle_find_elements_tag_name(
|
||||
&*documents,
|
||||
pipeline_id,
|
||||
selector,
|
||||
reply,
|
||||
)
|
||||
},
|
||||
WebDriverScriptCommand::FindElementElementCSS(selector, element_id, reply) => {
|
||||
webdriver_handlers::handle_find_element_element_css(
|
||||
&*documents,
|
||||
|
@ -2036,6 +2052,15 @@ impl ScriptThread {
|
|||
reply,
|
||||
)
|
||||
},
|
||||
WebDriverScriptCommand::FindElementElementTagName(selector, element_id, reply) => {
|
||||
webdriver_handlers::handle_find_element_element_tag_name(
|
||||
&*documents,
|
||||
pipeline_id,
|
||||
element_id,
|
||||
selector,
|
||||
reply,
|
||||
)
|
||||
},
|
||||
WebDriverScriptCommand::FindElementElementsCSS(selector, element_id, reply) => {
|
||||
webdriver_handlers::handle_find_element_elements_css(
|
||||
&*documents,
|
||||
|
@ -2045,6 +2070,15 @@ impl ScriptThread {
|
|||
reply,
|
||||
)
|
||||
},
|
||||
WebDriverScriptCommand::FindElementElementsTagName(selector, element_id, reply) => {
|
||||
webdriver_handlers::handle_find_element_elements_tag_name(
|
||||
&*documents,
|
||||
pipeline_id,
|
||||
element_id,
|
||||
selector,
|
||||
reply,
|
||||
)
|
||||
},
|
||||
WebDriverScriptCommand::FocusElement(element_id, reply) => {
|
||||
webdriver_handlers::handle_focus_element(
|
||||
&*documents,
|
||||
|
|
|
@ -182,6 +182,25 @@ pub fn handle_find_element_css(
|
|||
reply.send(node_id).unwrap();
|
||||
}
|
||||
|
||||
pub fn handle_find_element_tag_name(
|
||||
documents: &Documents,
|
||||
pipeline: PipelineId,
|
||||
selector: String,
|
||||
reply: IpcSender<Result<Option<String>, ()>>,
|
||||
) {
|
||||
let node_id = documents
|
||||
.find_document(pipeline)
|
||||
.ok_or(())
|
||||
.and_then(|doc| {
|
||||
Ok(doc
|
||||
.GetElementsByTagName(DOMString::from(selector))
|
||||
.elements_iter()
|
||||
.next())
|
||||
})
|
||||
.map(|node| node.map(|x| x.upcast::<Node>().unique_id()));
|
||||
reply.send(node_id).unwrap();
|
||||
}
|
||||
|
||||
pub fn handle_find_elements_css(
|
||||
documents: &Documents,
|
||||
pipeline: PipelineId,
|
||||
|
@ -204,6 +223,25 @@ pub fn handle_find_elements_css(
|
|||
reply.send(node_ids).unwrap();
|
||||
}
|
||||
|
||||
pub fn handle_find_elements_tag_name(
|
||||
documents: &Documents,
|
||||
pipeline: PipelineId,
|
||||
selector: String,
|
||||
reply: IpcSender<Result<Vec<String>, ()>>,
|
||||
) {
|
||||
let node_ids = documents
|
||||
.find_document(pipeline)
|
||||
.ok_or(())
|
||||
.and_then(|doc| Ok(doc.GetElementsByTagName(DOMString::from(selector))))
|
||||
.map(|nodes| {
|
||||
nodes
|
||||
.elements_iter()
|
||||
.map(|x| x.upcast::<Node>().unique_id())
|
||||
.collect::<Vec<String>>()
|
||||
});
|
||||
reply.send(node_ids).unwrap();
|
||||
}
|
||||
|
||||
pub fn handle_find_element_element_css(
|
||||
documents: &Documents,
|
||||
pipeline: PipelineId,
|
||||
|
@ -221,12 +259,32 @@ pub fn handle_find_element_element_css(
|
|||
reply.send(node_id).unwrap();
|
||||
}
|
||||
|
||||
pub fn handle_find_element_elements_css(
|
||||
pub fn handle_find_element_element_tag_name(
|
||||
documents: &Documents,
|
||||
pipeline: PipelineId,
|
||||
element_id: String,
|
||||
selector: String,
|
||||
reply: IpcSender<Result<Option<String>, ()>>,
|
||||
) {
|
||||
let node_id = find_node_by_unique_id(documents, pipeline, element_id)
|
||||
.ok_or(())
|
||||
.and_then(|node| match node.downcast::<Element>() {
|
||||
Some(elem) => Ok(elem
|
||||
.GetElementsByTagName(DOMString::from(selector))
|
||||
.elements_iter()
|
||||
.next()),
|
||||
None => Err(()),
|
||||
})
|
||||
.map(|node| node.map(|x| x.upcast::<Node>().unique_id()));
|
||||
reply.send(node_id).unwrap();
|
||||
}
|
||||
|
||||
pub fn handle_find_element_elements_css(
|
||||
documents: &Documents,
|
||||
pipeline: PipelineId,
|
||||
element_id: String,
|
||||
selector: String,
|
||||
reply: IpcSender<Result<Vec<String>, ()>>,
|
||||
) {
|
||||
let node_ids = find_node_by_unique_id(documents, pipeline, element_id)
|
||||
.ok_or(())
|
||||
|
@ -237,12 +295,34 @@ pub fn handle_find_element_elements_css(
|
|||
.map(|nodes| {
|
||||
nodes
|
||||
.iter()
|
||||
.map(|x| Some(x.upcast::<Node>().unique_id()))
|
||||
.map(|x| x.upcast::<Node>().unique_id())
|
||||
.collect()
|
||||
});
|
||||
reply.send(node_ids).unwrap();
|
||||
}
|
||||
|
||||
pub fn handle_find_element_elements_tag_name(
|
||||
documents: &Documents,
|
||||
pipeline: PipelineId,
|
||||
element_id: String,
|
||||
selector: String,
|
||||
reply: IpcSender<Result<Vec<String>, ()>>,
|
||||
) {
|
||||
let node_ids = find_node_by_unique_id(documents, pipeline, element_id)
|
||||
.ok_or(())
|
||||
.and_then(|node| match node.downcast::<Element>() {
|
||||
Some(elem) => Ok(elem.GetElementsByTagName(DOMString::from(selector))),
|
||||
None => Err(()),
|
||||
})
|
||||
.map(|nodes| {
|
||||
nodes
|
||||
.elements_iter()
|
||||
.map(|x| x.upcast::<Node>().unique_id())
|
||||
.collect::<Vec<String>>()
|
||||
});
|
||||
reply.send(node_ids).unwrap();
|
||||
}
|
||||
|
||||
pub fn handle_focus_element(
|
||||
documents: &Documents,
|
||||
pipeline: PipelineId,
|
||||
|
|
|
@ -25,9 +25,13 @@ pub enum WebDriverScriptCommand {
|
|||
ExecuteScript(String, IpcSender<WebDriverJSResult>),
|
||||
ExecuteAsyncScript(String, IpcSender<WebDriverJSResult>),
|
||||
FindElementCSS(String, IpcSender<Result<Option<String>, ()>>),
|
||||
FindElementTagName(String, IpcSender<Result<Option<String>, ()>>),
|
||||
FindElementsCSS(String, IpcSender<Result<Vec<String>, ()>>),
|
||||
FindElementsTagName(String, IpcSender<Result<Vec<String>, ()>>),
|
||||
FindElementElementCSS(String, String, IpcSender<Result<Option<String>, ()>>),
|
||||
FindElementElementsCSS(String, String, IpcSender<Result<Option<String>, ()>>),
|
||||
FindElementElementTagName(String, String, IpcSender<Result<Option<String>, ()>>),
|
||||
FindElementElementsCSS(String, String, IpcSender<Result<Vec<String>, ()>>),
|
||||
FindElementElementsTagName(String, String, IpcSender<Result<Vec<String>, ()>>),
|
||||
FocusElement(String, IpcSender<Result<(), ()>>),
|
||||
GetActiveElement(IpcSender<Option<String>>),
|
||||
GetCookie(String, IpcSender<Vec<Serde<Cookie<'static>>>>),
|
||||
|
|
|
@ -804,17 +804,25 @@ impl Handler {
|
|||
&self,
|
||||
parameters: &LocatorParameters,
|
||||
) -> WebDriverResult<WebDriverResponse> {
|
||||
if parameters.using != LocatorStrategy::CSSSelector {
|
||||
return Err(WebDriverError::new(
|
||||
ErrorStatus::UnsupportedOperation,
|
||||
"Unsupported locator strategy",
|
||||
));
|
||||
}
|
||||
|
||||
let (sender, receiver) = ipc::channel().unwrap();
|
||||
|
||||
let cmd = WebDriverScriptCommand::FindElementCSS(parameters.value.clone(), sender);
|
||||
self.browsing_context_script_command(cmd)?;
|
||||
match parameters.using {
|
||||
LocatorStrategy::CSSSelector => {
|
||||
let cmd = WebDriverScriptCommand::FindElementCSS(parameters.value.clone(), sender);
|
||||
self.browsing_context_script_command(cmd)?;
|
||||
},
|
||||
LocatorStrategy::TagName => {
|
||||
let cmd =
|
||||
WebDriverScriptCommand::FindElementTagName(parameters.value.clone(), sender);
|
||||
self.browsing_context_script_command(cmd)?;
|
||||
},
|
||||
_ => {
|
||||
return Err(WebDriverError::new(
|
||||
ErrorStatus::UnsupportedOperation,
|
||||
"Unsupported locator strategy",
|
||||
));
|
||||
},
|
||||
}
|
||||
|
||||
match receiver.recv().unwrap() {
|
||||
Ok(value) => {
|
||||
|
@ -894,20 +902,31 @@ impl Handler {
|
|||
Ok(WebDriverResponse::Void)
|
||||
}
|
||||
|
||||
// https://w3c.github.io/webdriver/#find-elements
|
||||
fn handle_find_elements(
|
||||
&self,
|
||||
parameters: &LocatorParameters,
|
||||
) -> WebDriverResult<WebDriverResponse> {
|
||||
if parameters.using != LocatorStrategy::CSSSelector {
|
||||
return Err(WebDriverError::new(
|
||||
ErrorStatus::UnsupportedOperation,
|
||||
"Unsupported locator strategy",
|
||||
));
|
||||
let (sender, receiver) = ipc::channel().unwrap();
|
||||
|
||||
match parameters.using {
|
||||
LocatorStrategy::CSSSelector => {
|
||||
let cmd = WebDriverScriptCommand::FindElementsCSS(parameters.value.clone(), sender);
|
||||
self.browsing_context_script_command(cmd)?;
|
||||
},
|
||||
LocatorStrategy::TagName => {
|
||||
let cmd =
|
||||
WebDriverScriptCommand::FindElementsTagName(parameters.value.clone(), sender);
|
||||
self.browsing_context_script_command(cmd)?;
|
||||
},
|
||||
_ => {
|
||||
return Err(WebDriverError::new(
|
||||
ErrorStatus::UnsupportedOperation,
|
||||
"Unsupported locator strategy",
|
||||
));
|
||||
},
|
||||
}
|
||||
|
||||
let (sender, receiver) = ipc::channel().unwrap();
|
||||
let cmd = WebDriverScriptCommand::FindElementsCSS(parameters.value.clone(), sender);
|
||||
self.browsing_context_script_command(cmd)?;
|
||||
match receiver.recv().unwrap() {
|
||||
Ok(value) => {
|
||||
let resp_value: Vec<Value> = value
|
||||
|
@ -931,21 +950,32 @@ impl Handler {
|
|||
element: &WebElement,
|
||||
parameters: &LocatorParameters,
|
||||
) -> WebDriverResult<WebDriverResponse> {
|
||||
if parameters.using != LocatorStrategy::CSSSelector {
|
||||
return Err(WebDriverError::new(
|
||||
ErrorStatus::UnsupportedOperation,
|
||||
"Unsupported locator strategy",
|
||||
));
|
||||
}
|
||||
|
||||
let (sender, receiver) = ipc::channel().unwrap();
|
||||
let cmd = WebDriverScriptCommand::FindElementElementCSS(
|
||||
parameters.value.clone(),
|
||||
element.id.clone(),
|
||||
sender,
|
||||
);
|
||||
|
||||
self.browsing_context_script_command(cmd)?;
|
||||
match parameters.using {
|
||||
LocatorStrategy::CSSSelector => {
|
||||
let cmd = WebDriverScriptCommand::FindElementElementCSS(
|
||||
parameters.value.clone(),
|
||||
element.id.clone(),
|
||||
sender,
|
||||
);
|
||||
self.browsing_context_script_command(cmd)?;
|
||||
},
|
||||
LocatorStrategy::TagName => {
|
||||
let cmd = WebDriverScriptCommand::FindElementElementTagName(
|
||||
parameters.value.clone(),
|
||||
element.id.clone(),
|
||||
sender,
|
||||
);
|
||||
self.browsing_context_script_command(cmd)?;
|
||||
},
|
||||
_ => {
|
||||
return Err(WebDriverError::new(
|
||||
ErrorStatus::UnsupportedOperation,
|
||||
"Unsupported locator strategy",
|
||||
));
|
||||
},
|
||||
}
|
||||
|
||||
match receiver.recv().unwrap() {
|
||||
Ok(value) => {
|
||||
|
@ -967,34 +997,46 @@ impl Handler {
|
|||
element: &WebElement,
|
||||
parameters: &LocatorParameters,
|
||||
) -> WebDriverResult<WebDriverResponse> {
|
||||
if parameters.using != LocatorStrategy::CSSSelector {
|
||||
return Err(WebDriverError::new(
|
||||
ErrorStatus::UnsupportedOperation,
|
||||
"Unsupported locator strategy",
|
||||
));
|
||||
}
|
||||
|
||||
let (sender, receiver) = ipc::channel().unwrap();
|
||||
let cmd = WebDriverScriptCommand::FindElementElementsCSS(
|
||||
parameters.value.clone(),
|
||||
element.id.clone(),
|
||||
sender,
|
||||
);
|
||||
|
||||
self.browsing_context_script_command(cmd)?;
|
||||
match parameters.using {
|
||||
LocatorStrategy::CSSSelector => {
|
||||
let cmd = WebDriverScriptCommand::FindElementElementsCSS(
|
||||
parameters.value.clone(),
|
||||
element.id.clone(),
|
||||
sender,
|
||||
);
|
||||
self.browsing_context_script_command(cmd)?;
|
||||
},
|
||||
LocatorStrategy::TagName => {
|
||||
let cmd = WebDriverScriptCommand::FindElementElementsTagName(
|
||||
parameters.value.clone(),
|
||||
element.id.clone(),
|
||||
sender,
|
||||
);
|
||||
self.browsing_context_script_command(cmd)?;
|
||||
},
|
||||
_ => {
|
||||
return Err(WebDriverError::new(
|
||||
ErrorStatus::UnsupportedOperation,
|
||||
"Unsupported locator strategy",
|
||||
));
|
||||
},
|
||||
}
|
||||
|
||||
match receiver.recv().unwrap() {
|
||||
Ok(value) => {
|
||||
let value_resp = value
|
||||
let resp_value: Vec<Value> = value
|
||||
.into_iter()
|
||||
.map(|x| serde_json::to_value(WebElement::new(x)).unwrap())
|
||||
.collect::<Vec<Value>>();
|
||||
let value_resp = serde_json::Value::Array(value_resp);
|
||||
Ok(WebDriverResponse::Generic(ValueResponse(value_resp)))
|
||||
.collect();
|
||||
Ok(WebDriverResponse::Generic(ValueResponse(
|
||||
serde_json::to_value(resp_value)?,
|
||||
)))
|
||||
},
|
||||
Err(_) => Err(WebDriverError::new(
|
||||
ErrorStatus::InvalidSelector,
|
||||
"Invalid Selector",
|
||||
"Invalid selector",
|
||||
)),
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,9 +11,6 @@
|
|||
[test_find_element_partial_link_text[<a href=#> partial link text </a>-link\]]
|
||||
expected: FAIL
|
||||
|
||||
[test_htmldocument[tag name-html\]]
|
||||
expected: FAIL
|
||||
|
||||
[test_find_element_link_text[<a href=#>link<br>text</a>-link\ntext\]]
|
||||
expected: FAIL
|
||||
|
||||
|
@ -62,9 +59,6 @@
|
|||
[test_find_element_partial_link_text[<a href=#>partial link text</a>-k t\]]
|
||||
expected: FAIL
|
||||
|
||||
[test_find_element[tag name-a\]]
|
||||
expected: FAIL
|
||||
|
||||
[test_xhtml_namespace[partial link text-link text\]]
|
||||
expected: FAIL
|
||||
|
||||
|
|
|
@ -62,9 +62,6 @@
|
|||
[test_find_element_partial_link_text[<a href=#>partial link text</a>-k t\]]
|
||||
expected: FAIL
|
||||
|
||||
[test_find_element[tag name-a\]]
|
||||
expected: FAIL
|
||||
|
||||
[test_xhtml_namespace[partial link text-link text\]]
|
||||
expected: FAIL
|
||||
|
||||
|
|
|
@ -5,9 +5,6 @@
|
|||
[test_find_elements_link_text[<a href=#>LINK TEXT</a>-LINK TEXT\]]
|
||||
expected: FAIL
|
||||
|
||||
[test_htmldocument[tag name-html\]]
|
||||
expected: FAIL
|
||||
|
||||
[test_find_elements_link_text[<a href=#>link text</a>-link text\]]
|
||||
expected: FAIL
|
||||
|
||||
|
@ -50,9 +47,6 @@
|
|||
[test_find_elements[xpath-//a\]]
|
||||
expected: FAIL
|
||||
|
||||
[test_find_elements[tag name-a\]]
|
||||
expected: FAIL
|
||||
|
||||
[test_find_elements_partial_link_text[<a href=# style='text-transform: uppercase'>partial link text</a>-LINK\]]
|
||||
expected: FAIL
|
||||
|
||||
|
|
|
@ -44,18 +44,12 @@
|
|||
[test_parent_of_document_node_errors]
|
||||
expected: FAIL
|
||||
|
||||
[test_no_element[css selector-#wontExist\]]
|
||||
expected: FAIL
|
||||
|
||||
[test_find_elements_partial_link_text[<a href=#>partial link&text</a>-k&t\]]
|
||||
expected: FAIL
|
||||
|
||||
[test_find_elements[xpath-//a\]]
|
||||
expected: FAIL
|
||||
|
||||
[test_find_elements[tag name-a\]]
|
||||
expected: FAIL
|
||||
|
||||
[test_find_elements_partial_link_text[<a href=# style='text-transform: uppercase'>partial link text</a>-LINK\]]
|
||||
expected: FAIL
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue