Skip to content

Commit

Permalink
Implement tag name selector for FindElements WebDriver command
Browse files Browse the repository at this point in the history
  • Loading branch information
georgeroman committed Jul 21, 2019
1 parent 7d5b324 commit dec73e4
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 14 deletions.
8 changes: 8 additions & 0 deletions components/script/script_thread.rs
Expand Up @@ -2035,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,
Expand Down
19 changes: 19 additions & 0 deletions components/script/webdriver_handlers.rs
Expand Up @@ -223,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,
Expand Down
1 change: 1 addition & 0 deletions components/script_traits/webdriver_msg.rs
Expand Up @@ -27,6 +27,7 @@ pub enum WebDriverScriptCommand {
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>, ()>>),
FocusElement(String, IpcSender<Result<(), ()>>),
Expand Down
27 changes: 19 additions & 8 deletions components/webdriver_server/lib.rs
Expand Up @@ -902,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
Expand Down
6 changes: 0 additions & 6 deletions tests/wpt/metadata/webdriver/tests/find_elements/find.py.ini
Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down

0 comments on commit dec73e4

Please sign in to comment.