Closed Bug 799008 Opened 7 years ago Closed 7 years ago

findElements does not scope to parent

Categories

(Testing :: Marionette, defect)

x86
macOS
defect
Not set

Tracking

(firefox18 fixed, firefox19 fixed)

RESOLVED FIXED
mozilla19
Tracking Status
firefox18 --- fixed
firefox19 --- fixed

People

(Reporter: jlal, Assigned: fredy)

Details

Attachments

(1 file, 2 obsolete files)

STR:

marionette.navigate('https://developer.mozilla.org/en-US/docs/Mozilla/Boot_to_Gecko/Marionette_for_Interactive_Python')

head = marionette.find_element('css selector', '#article-head')
head.find_elements('css selector', 'div')

expected:

find elements to return the single 'div' element inside #article-head

actual:

all div elements in the entire document are returned.

--

My best guess is this related to: https://mxr.mozilla.org/mozilla-central/source/testing/marionette/marionette-elements.js#251

My build is from October 2nd (which is far after this code has been modified).
the workaround is to do something like

marionette.find_elements('css selector', '#article-head div');
Attached patch bugfix (obsolete) — Splinter Review
At findElements function, on css-selector case, searching for the elements always starts at the rootNode which is the document and not at the current node (startNode).

The attached patch corrects this behavior.
Attachment #669143 - Flags: review?
Comment on attachment 669143 [details] [diff] [review]
bugfix

Can you add a test case for this too?
Attachment #669143 - Flags: review? → review?(dburns)
Attached patch fix and unit test (obsolete) — Splinter Review
Attachment #669143 - Attachment is obsolete: true
Attachment #669143 - Flags: review?(dburns)
Attachment #672024 - Flags: review?(dburns)
Comment on attachment 672024 [details] [diff] [review]
fix and unit test


> 
>+    def test_selector_scope(self):

Can we make the test name more verbose so we can, at a glance, work out what it is supposed to do. E.g. test_css_selector_scope_doesnt_start_at_rootnode

>+        el = self.marionette.execute_script("return window.document.getElementById('mozLink');")
>+        nav_el = self.marionette.execute_script("return window.document.getElementById('testDiv');")

Why are you using execute script instead of find_element here?
(In reply to David Burns :automatedtester from comment #5)
> Comment on attachment 672024 [details] [diff] [review]
> fix and unit test
> 
> 
> > 
> >+    def test_selector_scope(self):
> 
> Can we make the test name more verbose so we can, at a glance, work out what
> it is supposed to do. E.g. test_css_selector_scope_doesnt_start_at_rootnode
> 
Yes, that's sound better. I am going to fix that. 

> >+        el = self.marionette.execute_script("return window.document.getElementById('mozLink');")
> >+        nav_el = self.marionette.execute_script("return window.document.getElementById('testDiv');")
> 
> Why are you using execute script instead of find_element here?

I just saw it on some other tests in the same file, e.g. test_xpath.
I thought also that, just in case, the find_element function don't work, using execute script will make this test pass.
I can also fix this behavior.
(In reply to Alfredos-Panagiotis Damkalis (irc: fredy) from comment #6)
> Yes, that's sound better. I am going to fix that. 
> 
*that sounds better
Attached patch patch v2Splinter Review
Name of the test is fixed and the execute_scripts replaced with find_element.
Attachment #672024 - Attachment is obsolete: true
Attachment #672024 - Flags: review?(dburns)
Attachment #672541 - Flags: review?(dburns)
Comment on attachment 672541 [details] [diff] [review]
patch v2

awesome work!
Attachment #672541 - Flags: review?(dburns) → review+
https://hg.mozilla.org/mozilla-central/rev/f5760fcd8420
Assignee: nobody → fredy
Status: NEW → RESOLVED
Closed: 7 years ago
Flags: in-testsuite+
Resolution: --- → FIXED
Target Milestone: --- → mozilla19
Whiteboard: [automation-needed-in-aurora]
You need to log in before you can comment on or make changes to this bug.