Closed Bug 1036934 Opened 5 years ago Closed 2 months ago

Add test for content editing keyboard shortcuts

Categories

(Testing :: Firefox UI Tests, defect)

Version 2
defect
Not set

Tracking

(Not tracked)

RESOLVED WONTFIX

People

(Reporter: mihaelav, Unassigned, Mentored)

References

()

Details

(Whiteboard: [lang=py])

Add automated test for shortcuts related to editing content:

* Ctrl + C - Copy
* Ctrl + X - Cut
* Del - Delete
* Ctrl + V - Paste
* Ctrl + Shift + V - Paste (as plain text)
* Ctrl + Shift + Z - Redo
* Ctrl + A - Select All
* Ctrl + Z - Undo

(Source: https://support.mozilla.org/en-US/kb/keyboard-shortcuts-perform-firefox-tasks-quickly#w_editing)
Summary: Add mozmill test for search keyboard shortcuts → Add mozmill test for content editing keyboard shortcuts
That's clearly something we want for the  Firefox UI tests. A test like that should go into firefox_ui_tests/functional/shortcuts/.

For each of the shortcuts we have to retrieve the appropriate DTD entity from the browser. Therefor the self.browser.get_entity() method can be used. It requires a parameter with the name of the entity to retrieve. Most likely every entity can be found in the browser.dtd file: https://dxr.mozilla.org/mozilla-central/source/browser/locales/en-US/chrome/browser/browser.dtd#136.
Mentor: andrei, matei.andreea89 → hskupin
Component: Mozmill Tests → Firefox UI Tests
Summary: Add mozmill test for content editing keyboard shortcuts → Add test for content editing keyboard shortcuts
Whiteboard: [lang=js] → [lang=py]
I'd like to work on this bug, as it is still open and unassigned.
I've just started on this as well, created a `test_keyboard_shortcuts.py` file in `functional/keyboard_shortcuts/`.  I will use `test_browser_window.py` as a reference in how to write the rest of the test file.
Hi Sandeep! That sounds great. Thanks a lot for your interest. Let me know if you need something else to continue on this bug. For now I assign the bug to you.
Assignee: nobody → sandeep
Status: NEW → ASSIGNED
I have two questions: (1) will there be a test for each keyboard shortcut, (2) what is the content/page that keystrokes will be tested against.  I am assuming that it will not be the location bar browser history, but an actual page that is currently stored in `resources/layout/`.
There will be a single file for content editable shortcuts but different test methods for each of those. Also I would propose to add a new test page which contains an editable div. We don't have such a page yet, so it would have to be created. Let me know if you have questions about that.
Yes, I have created just one file in `functional/keyboard_shortcuts/` which will contain separate tests for each of the keyboard shortcuts.  I have created a test page in `resources/layout/` called `keyboard_shortcuts_test_page.html` containing a single editable div with the ID 'shortcuts' - here is the page:
```
<!DOCTYPE html>
<html lang="en" dir="ltr">
<html>
<head>
    <title>Mozilla</title>
    <link rel="shortcut icon" type="image/ico" href="../images/mozilla_favicon.ico" />
</head>
<body>
    <a href="mozilla.html">
        <img id="mozilla_logo" src="../images/mozilla_logo.jpg" />
    </a>
    <div contentEditable="true" id="shortcuts">
      This is an editable div and this text can be selected and edited by the user using keyboard shortcuts.
    </div>
</body>
</html>
```

I do have a question, which when I am simulating a keyboard action, like copying the text in the div 'shortcuts' to the clipboard, what is the method for doing?
I have the `setUp` method which makes the browser navigate to the test page, and that works fine.  But in the test method for copy for example I am not clear as to how I select the content of the div 'shortcuts'.
To select text you will have to do a double click anywhere in the div. That will give you a selection you could work with. But I don't have that much experience myself yet if Marionette offers other ways too. David, can you give a pointer please for text selection and working with it? If Marionette doesn't have some API for getting selected text we might have to create our own via an execute_script() call and code similar to http://hg.mozilla.org/qa/mozmill-tests/file/default/firefox/tests/functional/testFindInPage/testFindInPage.js#l44.
Flags: needinfo?(dburns)
(In reply to Henrik Skupin (:whimboo) from comment #9)
> To select text you will have to do a double click anywhere in the div. That
> will give you a selection you could work with. But I don't have that much
> experience myself yet if Marionette offers other ways too. David, can you
> give a pointer please for text selection and working with it? If Marionette
> doesn't have some API for getting selected text we might have to create our
> own via an execute_script() call and code similar to
> http://hg.mozilla.org/qa/mozmill-tests/file/default/firefox/tests/functional/
> testFindInPage/testFindInPage.js#l44.


To select a specific word you might need to use execute script to do the selection. If you want to try do a double click you can use Actions which has a double click[1]. 

> action = Actions(marionette).double_click(element)
> action.perform()

https://dxr.mozilla.org/mozilla-central/source/testing/marionette/driver/marionette_driver/marionette.py#362
Flags: needinfo?(dburns)
Thanks David! Sandeep, I would suggest to make use of Actions first. Only if that does not succeed we should find a method through execute_script. I hope the information above helps you to continue on this bug?
Yes I think so, I will be free again to work on this on the weekend,so I will post  what I've done then.

Thanks again David and Henrik.
Sandeep, do you have an update for us on this bug? Have you had the time to check those specific tests?
Flags: needinfo?(sandeep)
Hi, sorry for the delay, unfortunately I haven't had the time recently to look at this or the other bug (#1136902) since my last check.  I will try to do this shortly, perhaps on Saturday, at least after the weekend.
Flags: needinfo?(sandeep)
Some time passed by here. Mind having a status update for us? If you don't have the time to finish off we can put this back to the general bucket and find someone else to finish it off. Thanks.
Hi, I think I will not have time to do this.  Sorry about that, but work commitments and I'm also moving to another place right now.  But I will have time to finish the other, the sanitize utils test.
Thanks for letting us know. So I will move it back into the unassigned group for someone else to pick it up.
Assignee: sandeep → nobody
Status: ASSIGNED → NEW
Product: Mozilla QA → Testing
Maybe I can work on this ? I have basic python knowledge and wrote some automation test using selenium  .
I meant python and selenium :)
Hi Svezauzeto. If you are interested in getting such a test implemented that would be great. Currently we don't have that many l10n related tests and this one would be a great addition. 

Meanwhile the location of the tests has been changed. To get started you should read through the following MDN article. Lets me know if there are remaining questions in getting started.

https://developer.mozilla.org/en-US/docs/Mozilla/QA/Firefox_UI_tests
I will have to do some research but I will definitely give it a try. I will read the link you posted and then hopefully come back with an idea, and then we can solve it.

Thanks
Okay I have made following steps (for now ):

-- runned ./mach firefox-ui-functional to see that tests work
-- made simple html with editable div
-- installed marionnete_driver with pip
-- setup small script so I try to play with marionette ( to see how it actually works ).

I am kinda stuck on last step. This is my python script:

from marionette_driver.marionette import Marionette

client = Marionette('localhost', port=2828)
client.start_session()

url = 'http://mozilla.org'
client.navigate(url)
client.go_back()
client.go_forward()
assert client.get_url() == url

print "done"


When I execute it nothing happens and then I get timeout error(after 60 seconds ). How can I actually open firefox and navigate to some html page (mozilla.org in this example ).

I am using this web page as some guidance http://marionette-client.readthedocs.io/en/master/
As mentioned on IRC please continue to use mach. Just add a path to your test, a manifest, or a folder as argument, eg. ./mach firefox-ui-functional path_to_test. The session and everything around it will automatically be created by the marionette_harness mach is using. There is no need for you to do it yourself.
Hi,

I would like to make some tests of my test script for shortcuts. I have imported html page into testing/firefox-ui/resources and now I would like to start a test.

I know I can run all test using ./mach firefox-ui-functional, but is there any way to start just my test , so I don't have to wait for all others to finish?

Thanks ?
Sure, just put the path to the test as argument to the mach command. Then only this test will be run. Btw it also works with a manifest file or a folder.
I am trying to do something like this, just to get me started:

'''python'''
from marionette_driver.marionette import Marionette
from marionette_driver import marionette
from marionette_driver import wait

class TestKeyboardShortcuts:

    def test_copy_shorcut(self):
        print "doing something"
        self.client = Marionette('localhost',port=2828)
        self.client.start_session
        url = self.client.absolute_url("http.//www.mozilla.org")
        self.client.navigate(url)


'''python'''

the command I run test is 


./mach firefox-ui-functional testing/firefox-ui/tests/functional/keyboard_shortcuts/test_keyboard_shortcuts.py

and the output is 

https://pastebin.mozilla.org/8949701

So basically nothing happens. Is there any example how test should look like to get it properly executed ?
I have tried to copy "look" of test_browser_window.py , but without luck so far.

Thanks
I am trying to do something like this, just to get me started:

'''python'''
from marionette_driver.marionette import Marionette
from marionette_driver import marionette
from marionette_driver import wait

class TestKeyboardShortcuts:

    def test_copy_shorcut(self):
        print "doing something"
        self.client = Marionette('localhost',port=2828)
        self.client.start_session
        url = self.client.absolute_url("http.//www.mozilla.org")
        self.client.navigate(url)


'''python'''

the command I run test is 


./mach firefox-ui-functional testing/firefox-ui/tests/functional/keyboard_shortcuts/test_keyboard_shortcuts.py

and the output is 

https://pastebin.mozilla.org/8949701

So basically nothing happens. Is there any example how test should look like to get it properly executed ?
I have tried to copy "look" of test_browser_window.py , but without luck so far.

Thanks
(In reply to Tomislav Jurin from comment #26)

> class TestKeyboardShortcuts:

This is not a testcase class but just a subclass of the object class. To make it a real test the class needs MarionetteTestCase as parent class.

>     def test_copy_shorcut(self):
>         print "doing something"
>         self.client = Marionette('localhost',port=2828)
>         self.client.start_session

There is no need for that. Marionette is already available as `self.marionette` in any testcase class derived from MarionetteTestCase. The above will actually fail to 

>         url = self.client.absolute_url("http.//www.mozilla.org")

The call to `absolute_url()` is only necessary if you have testcase data located on the disk and which you want to serve for localhost. For complete URLs this is a no-op.

> So basically nothing happens. Is there any example how test should look like
> to get it properly executed ?

Please see the above which will fix it.
Sorry I am not able to fix it. I just can't make Firefox run my html page, always getting the same error no matter what I try:

raise errors.lookup(error)(message, stacktrace=stacktrace)
UnknownException: Cannot navigate in chrome context

''' python '''


from firefox_puppeteer import PuppeteerMixin
from marionette import MarionetteTestCase
from marionette_driver import Wait

class TestKeyboardShortcuts(PuppeteerMixin, MarionetteTestCase):

    def test_copy_shorcut(self):
        url = self.marionette.absolute_url("test_page")
        self.marionette.navigate('url')

''' python '''

to not waste anyone's time I will give up on this task. Hopefully someone who takes this after me will have more luck with this.

Thanks for guidance.
Tomislav, please do not give up that quickly. We are always around for help. So in this case navigation is only possible in content scope which means you will have to use something like:

> def test_copy_shorcut(self):
>     url = self.marionette.absolute_url("test_page")
>     with self.marionette.using_context("content"):
>         self.marionette.navigate('url')

This means it will load the requested URL as part of the tab.
Okay so my working directory is called mozilla-centralCore.

From there pwd to html page that I want to open is:

mozilla-centralCore/testing/firefox-ui/resources/test_page.html

when I copy your code written above I get following result:

nightly firefox version starts
firefox opens "about:" page
it just shuts off after that


These are the logs:



./mach firefox-ui-functional testing/firefox-ui/tests/functional/keyboard_shortcuts/test_keyboard_shortcuts.py 


 0:00.00 LOG: MainThread INFO Using workspace for temporary data: "/home/gilley/mozilla-centralCore"
 0:00.01 LOG: MainThread INFO Application command: /home/gilley/mozilla-centralCore/obj-x86_64-pc-linux-gnu/dist/bin/firefox -no-remote -marionette -profile /tmp/tmpCkyLld.mozrunner
 0:17.45 LOG: MainThread INFO Profile path is /tmp/tmpCkyLld.mozrunner
 0:17.45 LOG: MainThread INFO Starting fixture servers
 0:17.52 LOG: MainThread INFO Fixture server listening on http://192.168.0.24:41151/
 0:17.52 LOG: MainThread INFO Fixture server listening on https://192.168.0.24:38679/
 0:17.52 LOG: MainThread INFO e10s is enabled
 0:17.52 LOG: MainThread mozversion INFO application_buildid: 20161130002124
 0:17.52 LOG: MainThread mozversion INFO application_changeset: 8d8846f63b74eb930e48b410730ae088e9bdbee8
 0:17.52 LOG: MainThread mozversion INFO application_display_name: Nightly
 0:17.52 LOG: MainThread mozversion INFO application_id: {ec8030f7-c20a-464f-9b0e-13a3a9e97384}
 0:17.52 LOG: MainThread mozversion INFO application_name: Firefox
 0:17.52 LOG: MainThread mozversion INFO application_remotingname: firefox
 0:17.52 LOG: MainThread mozversion INFO application_vendor: Mozilla
 0:17.52 LOG: MainThread mozversion INFO application_version: 53.0a1
 0:17.52 LOG: MainThread mozversion INFO platform_buildid: 20161130002124
 0:17.52 LOG: MainThread mozversion INFO platform_changeset: 8d8846f63b74eb930e48b410730ae088e9bdbee8
 0:17.52 LOG: MainThread mozversion INFO platform_version: 53.0a1
 0:17.52 SUITE_START: MainThread 1
 0:39.07 TEST_START: MainThread test_keyboard_shortcuts.py TestKeyboardShortcuts.test_copy_shorcut
 0:48.55 TEST_END: MainThread ERROR, expected PASS
Traceback (most recent call last):
  File "/home/gilley/mozilla-centralCore/testing/marionette/harness/marionette/marionette_test/testcases.py", line 166, in run
    testMethod()
  File "/home/gilley/mozilla-centralCore/testing/firefox-ui/tests/functional/keyboard_shortcuts/test_keyboard_shortcuts.py", line 10, in test_copy_shorcut
    self.marionette.navigate('url')
  File "/home/gilley/mozilla-centralCore/testing/marionette/client/marionette_driver/marionette.py", line 1620, in navigate
    self._send_message("get", {"url": url})
  File "/home/gilley/mozilla-centralCore/testing/marionette/client/marionette_driver/decorators.py", line 23, in _
    return func(*args, **kwargs)
  File "/home/gilley/mozilla-centralCore/testing/marionette/client/marionette_driver/marionette.py", line 715, in _send_message
    self._handle_error(err)
  File "/home/gilley/mozilla-centralCore/testing/marionette/client/marionette_driver/marionette.py", line 748, in _handle_error
    raise errors.lookup(error)(message, stacktrace=stacktrace)
InvalidArgumentException: Malformed URL: url is not a valid URL.
 0:51.24 LOG: MainThread INFO 
SUMMARY
-------
 0:51.24 LOG: MainThread INFO passed: 0
 0:51.24 LOG: MainThread INFO failed: 1
 0:51.24 LOG: MainThread INFO todo: 0
 0:51.24 LOG: MainThread INFO 
FAILED TESTS
-------
 0:51.24 LOG: MainThread INFO test_keyboard_shortcuts.py test_keyboard_shortcuts.TestKeyboardShortcuts.test_copy_shorcut
 0:51.24 SUITE_END: MainThread 
Summary
=======

Ran 1 tests
Expected results: 0
Unexpected results: 1 (ERROR: 1)

Unexpected Results
==================

ERROR test_keyboard_shortcuts.py TestKeyboardShortcuts.test_copy_shorcut


My html page is never opened.

Thanks for help.
I would suggest that we figure out this problem via IRC to not have to add a lot of comments unrelated to the work to get this bug solved. I will be around all the week long, so just check again when I'm around.
I am not sure if anyone is still working on this, but I would like to give it a shot if its available.

Firefox UI tests are going away, and as it looks like nothing happened on that bug for 2 years. So I assume it's not needed anymore.

Status: NEW → RESOLVED
Closed: 2 months ago
Resolution: --- → WONTFIX
You need to log in before you can comment on or make changes to this bug.