Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[NOT READY] Major update #185

Open
wants to merge 24 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
{
"env": {
"browser": true,
"commonjs": true,
"es2021": true
},
"parserOptions": {
"ecmaVersion": 12
},
"rules": {
"curly": 2,
"eqeqeq": ["error", "smart"],
"no-extend-native": 2,
"indent": 0,
"no-use-before-define": ["error", "nofunc"],
"no-caller": 2,
"no-undef": 2,
"no-unused-vars": ["error", { "vars": "all", "args": "none" }],
"comma-dangle": 2,
"max-depth": ["error", 4],
"no-trailing-spaces": 2,
"no-loop-func": 2,
"semi": 2
},
"globals": {
"steal": true,
"can": true,

"Zepto": true,

"QUnit": true,
"test": true,
"asyncTest": true,
"expect": true,
"module": true,
"ok": true,
"equal": true,
"notEqual": true,
"deepEqual": true,
"notDeepEqual": true,
"strictEqual": true,
"notStrictEqual": true,
"raises": true,
"start": true,
"stop": true,

"formElExp": true,
"KeyboardEvent": true
}
}
58 changes: 0 additions & 58 deletions .jshintrc

This file was deleted.

2 changes: 1 addition & 1 deletion .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ utils/
Gruntfile.js
.gitignore
.jsbeautifyrc
.jshintrc
.eslintrc.json
.travis.yml
.editorconfig
!dist/
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
language: node_js
node_js:
- 8
- 10
addons:
firefox: "63.0"
dist: xenial
Expand Down
212 changes: 157 additions & 55 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,105 +11,207 @@ For questions or discussion, check out our [forums](https://forums.donejs.com/c/
> If you are looking for the Synergy project, you can find it [here](https://www.npmjs.com/~postquagga). Thanks
> [postquagga](https://www.npmjs.com/~postquagga) for letting us use the name!

Syn lets you simulate user behavior like typing, clicking, moving, and
dragging exactly how a real user would perform those actions.
`syn` lets you simulate user behavior like typing, clicking, moving, and
dragging exactly how a real user would perform those actions. It can be easily dropped into
existing

```js
Syn.click( 'hello' )
.type( 'Hello World' )
.drag( 'trash' );
it("does something when you click and type and drag", async function(){

await syn.click( '#hello' );
await syn.type( '#hello', 'Hello World' );
await syn.drag( '#hello', '#trash' )

// check the results
});
```

## Install

Install Syn via the command line with npm:

> npm install syn

or bower:

> bower install syn

Or by downloading it [here](https://github.com/bitovi/syn/archive/v0.2.0.zip).
```shell
npm install syn
```

Inside the download, npm package and bower package, there are the following folders:
Inside the download and npm package there are the following folders:

- `dist/global/syn.js` - A standalone file that can be used with a `<script>` tag.
- `dist/amd` - An AMD build that can be used with [RequireJS](http://requirejs.org) and other AMD loaders.
- `dist/cjs` - A CommonJS build that is used by node or browserify.
- `src` - The source files that can be loaded by [StealJS](http://stealjs.com), SystemJS, and eventually JSPM.

## Setup

The following walk you through how to load Syn into various environments.

### Node / Browserify
### Webpack / StealJS

Assuming you installed with `npm`, simply `require("syn")` like the following:

var syn = require("syn");
syn.click(document.getElementById('hello'));
```js
const syn = require("syn");
syn.click('#hello');
```

### StealJS
### Script Tag / Standalone

If you installed via NPM or Bower and are using the [npm](http://stealjs.com/docs/npm.html)
or [bower](http://stealjs.com/docs/bower.html) module for configuration,
you can use import, require, or define to load the syn module without any configuration.
If you don't use a module loader, you can simply add the following to your page:

import syn from "syn";
syn.click(document.getElementById('hello'));
<script src='PATH/TO/dist/syn.js'></script>

### AMD / RequireJS
_PATH/TO_ should be the path to the installed syn folder.

Add the following package configuration:
## Use

require.config({
packages: [{
name: 'syn',
location: 'PATH/TO/syn/dist/amd',
main: 'syn'
}]
});
`syn` has 6 core user behavior actions that
simulate most of how a user interacts with a page.

_PATH/TO_ should be the path from your baseUrl to the location of the syn folder. Once this is
properly configured, you should be able to write:
`syn` also has the ability to configure event behavior. This can be useful if you need to simulate something that
syn does not currently support.

define(['syn'], function(syn){
syn.click(document.getElementById('hello'));
});
### Core user behavior actions

### Script Tag / Standalone
The core user behavior actions all:

If you don't use a module loader, you can simply add the following to your page:
- take an element (either has a CSS selector )
- take optional options that can configure the behavior of the
- return a promise

<script src='PATH/TO/dist/syn.js'></script>
These methods are all intended to work within an
[async function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/async_function) and use `await` as follows:

_PATH/TO_ should be the path to the installed syn folder.
```js
it("your test function", async function(){

await syn.click( '#hello' );
await syn.rightClick( '#hello' );
await syn.dblClick( '#hello' );
await syn.type( '#hello', 'Hello World' );
await syn.key( '#hello', '!' );
await syn.drag( '#hello', '#trash' );
await syn.move( '#trash', '#hello' );
// check the results
});
```

## Use
#### syn.click( element [, options] )

Click an element. This will properly dispatch all the mouse, pointer and focus events
and default behavior that a user would create when "clicking" on an element.

Examples:

```js
// clicks the element with 'big-button' as its ID
await syn.click( "#big-button" )

### syn.click( element [, options][, callback] )
// does the same thing as the previous example, but passes an
// element directly.
await syn.click( document.querySelector('#big-button') )
```

### syn.dblclick( element [, options][, callback] )
Parameters:

### syn.type( element, text [, callback] )
- __element__ `HTMLElement|CSSSelector` An element to click or a CSS selector used to find the element to click.
- __options__ `Object` Options used to extend the event objects that are dispatched.

### syn.key( element, key [, callback] )
Returns:

### syn.delay( time=600 )
- `Promise<Boolean>` A promise that resolves to `false` if `event.preventDefault()` was called, returns `true` if otherwise.

### syn.drag( element, optionsOrTarget [, callback])
#### syn.rightClick( element [, options] )

#### syn.dblclick( element [, options] )

#### syn.type( element, text )

## Contributing
#### syn.key( element, key )

Check out the [contribution guide](CONTRIBUTING.md).
#### syn.drag( element, optionsOrTarget )

#### syn.move( element, optionsOrTarget )

Moves a pointer from one position to another.
Note that this will will dispatch all the move, enter, and leave events
one might expect from a mouse moving over the page.

Examples:

```js
// Move from the center of the '#from' element to the center of the '#to' element
await syn.move("#from", "#to");

// Move from the center of the '#from' element to the center of the '#to' element
// in one second
await syn.move( document,{
from: "#from",
to: "#to",
duration: 1000
});

// Move from the top-left corner of the page to 100px down and 100px to the right
await syn.move( document, {
from: "0x0",
to: "100x100"
});

// Same as above, but a longer syntax
await syn.move( document, {
from: {pageX: 0, pageY: 0},
to: {pageX: 100, pageY: 100}
});

// Move from the top-left corner of the screen to 100px down and 100px to the right
await syn.move( document, {
from: {clientX: 0, clientY: 0},
to: {clientX: 100, clientY: 100}
});

// Move from the center of '#from' right 20 pixels and up 30 pixels
await syn.move("#from", "+20 +30");
```

Parameters:

- __element__ `HTMLElement|CSSSelector` If `optionsOrTarget.from` is not specified, the move will
use the center of this element as the starting point. An element reference
_MUST_ be provided so syn knows how to dispatch the events correctly.
The `document` can be provided in this case.
- __optionsOrTarget__ `HTMLElement|String|Object` If an HTMLElement or a String is
provided, the move will use the center of the specified element as the endpoint of
the move. Otherwise, an object with the following values can be provided:

```js
{
// Specifies where the move should start at
// Element - start at the geometric center
// CSSSelector - find this element in the page, start at the geometric center
// PagePosition - where in the page move will start. Ex: "300x300"
// ClientPosition - where in the window move will start. Ex: "300X300"
// RelativePosition - where to start relative to the element. Ex: "+300 -20"
from: Element|CSSSelector|PagePosition|ClientPosition|RelativePosition,

## Relevant Links
// Specifies where the move should start at
// Element - start at the geometric center
// CSSSelector - find this element in the page, start at the geometric center
// PagePosition - where in the page move will start. Ex: `"300x300"`
// ClientPosition - where in the window move will start. Ex: `"300X300"`
// RelativePosition - where to start relative to the element. Ex: `"+300 -20"`
to: Element|CSSSelector|PagePosition|ClientPosition|RelativePosition,

1. Blog post introducing [Syn — a Standalone Synthetic Event Library](https://www.bitovi.com/blog/syn-a-standalone-synthetic-event-library)
2. [Gitter chat](https://gitter.im/bitovi/syn)
// Number of ms the move should occur within. Ex: `100`. Defaults to 500.
duration: Integer
}
```

Returns:

- `Promise<>` Returns a promise that resolves when the move has completed.


### Configuration

> This section will be


## Contributing

Check out the [contribution guide](CONTRIBUTING.md).
Loading