Skip to content
This repository was archived by the owner on Jul 29, 2024. It is now read-only.

Commit 24ae714

Browse files
authored
docs(website): Improve documentation around drag and drop. (#3867)
Fixes #1205 Also adds support for `@external` to our docs.
1 parent 4af3b2e commit 24ae714

File tree

6 files changed

+117
-5
lines changed

6 files changed

+117
-5
lines changed

Diff for: docs/faq.md

+7
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,13 @@ This is a [webdriver quirk](http://grokbase.com/t/gg/webdriver/12bcmvwhcm/extarc
5151
`<input>` and `<textarea>` elements always have
5252
empty `getText` values. Instead, try `element.getAttribute('value')`.
5353

54+
How can I drag and drop elements?
55+
---------------------------------
56+
You can specify a sequence of [actions](http://www.protractortest.org/#/api?view=webdriver.WebDriver.prototype.actions)
57+
to drag an drop elements. Note mouse actions do not work on Chrome with the HTML5 Drag and Drop API due to a known
58+
[Chromedriver issue](https://bugs.chromium.org/p/chromedriver/issues/detail?id=841)
59+
60+
5461
How can I interact directly with the JavaScript running in my app?
5562
------------------------------------------------------------------
5663

Diff for: lib/selenium-webdriver/webdriver.js

+38-4
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,20 @@
77

88
goog.provide('webdriver');
99

10+
/**
11+
* Class for defining sequences of complex user interactions.
12+
* @external webdriver.ActionSequence
13+
* @see http://seleniumhq.github.io/selenium/docs/api/javascript/module/selenium-webdriver/lib/actions_exports_ActionSequence.html
14+
*/
15+
webdriver.ActionSequence = function() {};
16+
17+
/**
18+
* Class for defining sequences of user touch interactions.
19+
* @external webdriver.TouchSequence
20+
* @see http://seleniumhq.github.io/selenium/docs/api/javascript/module/selenium-webdriver/index_exports_TouchSequence.html
21+
*/
22+
webdriver.TouchSequence = function() {};
23+
1024
// //////////////////////////////////////////////////////////////////////////////
1125
// //
1226
// // webdriver.WebDriver
@@ -25,20 +39,37 @@ goog.provide('webdriver');
2539
webdriver.WebDriver = function() {};
2640

2741
/**
28-
* Creates a new action sequence using this driver. The sequence will not be
42+
* Creates a sequence of user actions using this driver. The sequence will not be
2943
* scheduled for execution until {@link webdriver.ActionSequence#perform} is
3044
* called.
3145
*
32-
* See http://seleniumhq.github.io/selenium/docs/api/javascript/module/selenium-webdriver/lib/actions_exports_ActionSequence.html
33-
* for more examples of action sequences.
46+
* See the selenium webdriver docs <a href="http://seleniumhq.github.io/selenium/docs/api/javascript/module/selenium-webdriver/lib/actions_exports_ActionSequence.html">
47+
* for more details on action sequences</a>.
48+
*
49+
* Mouse actions do not work on Chrome with the HTML5 Drag and Drop API due to a known <a href="https://bugs.chromium.org/p/chromedriver/issues/detail?id=841">
50+
* Chromedriver issue</a>
3451
*
3552
* @example
53+
* // Dragging one element to another.
3654
* browser.actions().
3755
* mouseDown(element1).
3856
* mouseMove(element2).
3957
* mouseUp().
4058
* perform();
4159
*
60+
* // You can also use the `dragAndDrop` convenience action.
61+
* browser.actions().
62+
* dragAndDrop(element1, element2).
63+
* perform();
64+
*
65+
* // Instead of specifying an element as the target, you can specify an offset
66+
* // in pixels. This example double-clicks slightly to the right of an element.
67+
* browser.actions().
68+
* mouseMove(element).
69+
* mouseMove({x: 50, y: 0}).
70+
* doubleClick().
71+
* perform();
72+
*
4273
* @returns {!webdriver.ActionSequence} A new action sequence for this instance.
4374
*/
4475
webdriver.WebDriver.prototype.actions = function() {};
@@ -48,13 +79,16 @@ webdriver.WebDriver.prototype.actions = function() {};
4879
* scheduled for execution until {@link actions.TouchSequence#perform} is
4980
* called.
5081
*
82+
* See the selenium webdriver docs <a href="http://seleniumhq.github.io/selenium/docs/api/javascript/module/selenium-webdriver/index_exports_TouchSequence.html">
83+
* for more details on touch sequences</a>.
84+
*
5185
* @example
5286
* browser.touchActions().
5387
* tap(element1).
5488
* doubleTap(element2).
5589
* perform();
5690
*
57-
* @return {!actions.TouchSequence} A new touch sequence for this instance.
91+
* @return {!webdriver.TouchSequence} A new touch sequence for this instance.
5892
*/
5993
webdriver.WebDriver.prototype.touchActions = function() {};
6094

Diff for: website/docgen/dgeni-config.js

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ jsDocProcessor.config(function(parseTagsProcessor) {
1414
tagDefs.push({name: 'deprecated'});
1515
tagDefs.push({name: 'example'});
1616
tagDefs.push({name: 'extends'});
17+
tagDefs.push({name: 'external'});
1718
tagDefs.push({name: 'private'});
1819
tagDefs.push({name: 'type'});
1920
tagDefs.push({name: 'view'});

Diff for: website/docgen/processors/add-links.js

+30
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ var _ = require('lodash');
66
*/
77
var typeTable;
88

9+
/**
10+
* A lookup table with links to external types.
11+
* @type {Object.<string, string}
12+
*/
13+
var externalTypes = {};
14+
915
/**
1016
* The hash used to generate the links to the source code.
1117
*/
@@ -88,6 +94,10 @@ var toMarkdownLinkFormat = function(link, doc, code) {
8894
}
8995
desc = desc.replace(new RegExp('\n', 'g'), ' ');
9096

97+
if (desc in externalTypes) {
98+
type = externalTypes[desc];
99+
}
100+
91101
if (!type.match(/^https?:\/\//)) {
92102
// Remove extra '()' at the end of types
93103
if (type.substr(-2) == '()') {
@@ -144,6 +154,22 @@ var getTypeString = function(param) {
144154
return escape(str);
145155
};
146156

157+
/**
158+
* Filters out types with @external annotations and adds their @see link to the
159+
* externalTypes table
160+
*
161+
* @param {Array.<Object>} docs The jsdoc list.
162+
*/
163+
var filterExternalDocs = function(docs) {
164+
return _.reject(docs, function (doc) {
165+
if (!!doc.external) {
166+
externalTypes[doc.name] = doc.see[0];
167+
return true;
168+
}
169+
return false;
170+
});
171+
};
172+
147173
/**
148174
* Add links to the external documents
149175
*/
@@ -154,6 +180,8 @@ module.exports = function addLinks() {
154180
$process: function(docs) {
155181
typeTable = _.groupBy(docs, 'name');
156182

183+
docs = filterExternalDocs(docs);
184+
157185
docs.forEach(function(doc) {
158186
addLinkToSourceCode(doc);
159187
doc.description = addLinkToLinkAnnotation(doc.description, doc);
@@ -173,6 +201,8 @@ module.exports = function addLinks() {
173201
doc.returnString = '';
174202
}
175203
});
204+
205+
return docs;
176206
}
177207
};
178208
};

Diff for: website/docgen/spec/add-links-spec.js

+40
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,46 @@ describe('add-links', function() {
167167
toBe('A promise located [{@code webdriver.WebElement}](webdriver.WebElement)s.');
168168
});
169169

170+
it('should add @external links', function() {
171+
// Given a doc with a @external annotation.
172+
var docs = [
173+
{
174+
name: 'webdriver.ActionSequence',
175+
external: 'webdriver.ActionSequence',
176+
see: [ 'http://seleniumhq.github.io/selenium/doc' ],
177+
},
178+
{
179+
name: 'browser.action()',
180+
description: 'Creates a new action sequence using the driver.',
181+
fileName: 'protractor',
182+
fileInfo: {filePath: ''},
183+
startingLine: 3,
184+
returns: {
185+
tagDef: {
186+
name: 'returns',
187+
aliases: ['return'],
188+
canHaveType: true
189+
},
190+
tagName: 'return',
191+
description: 'A new action sequence for this instance.',
192+
startingLine: 119,
193+
typeExpression: 'webdriver.ActionSequence',
194+
type: {
195+
type: 'NameExpression',
196+
name: 'webdriver.ActionSequence'
197+
},
198+
typeList: ['webdriver.ActionSequence']
199+
}
200+
}
201+
];
202+
203+
// When you add links.
204+
addLinks(docs);
205+
206+
// Then ensure a link was added to the type.
207+
expect(docs[1].returnString).toBe('[webdriver.ActionSequence](http://seleniumhq.github.io/selenium/doc)');
208+
});
209+
170210
it('should handle {@link type desc} links', function() {
171211
// Given a doc with a @link annotation.
172212
var docs = [

Diff for: website/test/e2e/api_spec.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ describe('Api', function() {
104104

105105
// Then ensure the child functions are shown.
106106
expect(apiPage.getChildFunctionNames()).toEqual([
107-
'then', 'clone', 'locator', 'getWebElement', 'all', 'element', '$$',
107+
'clone', 'locator', 'getWebElement', 'all', 'element', '$$',
108108
'$', 'isPresent', 'isElementPresent', 'evaluate', 'allowAnimations', 'equals']);
109109
});
110110

0 commit comments

Comments
 (0)