API Docs for: 0.0.9
Show:

Actions Class

Module: DalekJS

Actions are a way to control your browsers, e.g. simulate user interactions like clicking elements, open urls, filling out input fields, etc.

Constructor

Actions

()

Methods

$

(
  • selector
)
chainable

Alias of query

Parameters:

  • selector String

    Selector of the element to query

_addToActionQueue

(
  • opts
  • driverMethod
  • A
)
private chainable

Adds a method to the queue of actions/assertions to execute

Parameters:

  • opts Object

    Options of the action to invoke

  • driverMethod String

    Name of the method to call on the driver

  • A Function

    callback function that will be executed when the action has been executed

_generateCallbackAssertion

(
  • key
  • type
)
Function private

Generates a callback that will be fired when the action has been completed. The callback itself will then validate the answer and will also emit an event that the action has been successfully executed.

Parameters:

  • key String

    Unique key of the action

  • type String

    Type of the action (normalle the actions name)

Returns:

Function:

The generated callback function

_generateCallbackAssertion

(
  • type
  • hash
  • opts
  • key
)
Function private

Generates a callback that will be fired when the action has been completed. The callback will then store value into opts variable.

Parameters:

  • type String

    Type of the action (normalle the actions name)

  • hash String

    Unique id of the action

  • opts String

    Variable where will be stored result of execution of the action

  • key String

    Name of the property where will be stored result of execution of the action

Returns:

Function:

The generated callback function

accept

()

Accepts an alert/prompt/confirm dialog. This is basically the same actions as when you are clicking okay or hitting return in one of that dialogs.

<div>
  <a id="attentione" onclick="window.alert('Alonsy!')">ALERT!ALERT!</a>
</div>
 test.open('http://adomain.com')
    // alert appears
    .click('#attentione')
    // alert is gone
    .accept()
    .done();

Note: Does not work in Firefox & PhantomJS

Returns:

chainable

answer

(
  • keystrokes
)

Types a text into the text input field of a prompt dialog. Like you would do when using your keyboard.

<div>
  <a id="aquestion" onclick="this.innerText = window.prompt('Your favourite companion:')">????</a>
</div>
 test.open('http://adomain.com')
    .click('#aquestion')
    .answer('Rose')
    .assert.text('#aquestion').is('Rose', 'Awesome she was!')
    .done();

Note: Does not work in Firefox & PhantomJS

Parameters:

  • keystrokes String

    Text to be applied to the element

Returns:

chainable

back

() chainable

Moves back a step in browser's history.

This is basically the same as hitting the back button in your browser

test.open('http://google.com')
  .open('https://github.com')
  .assert.url.is('https://github.com/', 'We are at GitHub')
  .back()
  .assert.url.is('http://google.com', 'We are at Google!')
  .forward()
  .assert.url.is('https://github.com/', 'Back at GitHub! Timetravel FTW');
  .done();

click

(
  • selector
)
chainable

Performs a click on the element matching the provided selector expression.

If we take Daleks homepage (the one you're probably visiting right now), the HTML looks something like this (it does not really, but hey, lets assume this for a second)

<nav>
  <ul>
    <li><a id="homeapge" href="/index.html">DalekJS</a></li>
    <li><a id="docs" href="/docs.html">Documentation</a></li>
    <li><a id="faq" href="/faq.html">F.A.Q</a></li>
  </ul>
</nav>
test.open('http://dalekjs.com')
    .click('#faq')
    .assert.title().is('DalekJS - Frequently asked questions', 'What the F.A.Q.')
    .done();

By default, this performs a left click. In the future it might become the ability to also execute a "right button" click.

Note: Does not work correctly in Firefox when used on <select> & <option> elements

Parameters:

  • selector String

    Selector of the element to be clicked

close

() chainable

Close the active window and automatically selects the parent window.

this.test.toWindow('test');
this.test.close();

//you can now write your code as if the original parent window was selected because .close()
//selects that automatically for you so you don't have to call .toParentWindow() everytime

dismiss

()

Dismisses an prompt/confirm dialog. This is basically the same actions as when you are clicking cancel in one of that dialogs.

<div>
  <a id="nonono" onclick="(this.innerText = window.confirm('No classic doctors in the 50th?') ? 'Buh!' : ':(') ">What!</a>
</div>
 test.open('http://adomain.com')
    // prompt appears
    .click('#nonono')
    // prompt is gone
    .dismiss()
    .assert.text('#nonono').is(':(', 'So sad')
    .done();

Note: Does not work in Firefox & PhantomJS

Returns:

chainable

execute

(
  • script
)

Executes a JavaScript function within the browser context

 test.open('http://adomain.com')
    .execute(function () {
      window.myFramework.addRow('foo');
      window.myFramework.addRow('bar');
    })
    .done();

You can also apply arguments to the function

 test.open('http://adomain.com')
    .execute(function (paramFoo, aBar) {
      window.myFramework.addRow(paramFoo);
      window.myFramework.addRow(aBar);
    }, 'foo', 'bar')
    .done();

Note: Buggy in Firefox

Parameters:

  • script Function

    JavaScript function that should be executed

Returns:

chainable

forward

() chainable

Moves a step forward in browser's history.

This is basically the same as hitting the forward button in your browser

test.open('http://google.com')
  .open('https://github.com')
  .assert.url.is('https://github.com/', 'We are at GitHub')
  .back()
  .assert.url.is('http://google.com', 'We are at Google!')
  .forward()
  .assert.url.is('https://github.com/', 'Back at GitHub! Timetravel FTW')
  .done();

log.dom

(
  • selector
)
chainable

Logs a part of the remote dom

<body>
  <div id="smth">
    <input type="hidden" value="not really a value" id="ijustwannahaveavalue"/>
  </div>
</body>
test.open('http://dalekjs.com/guineapig')
    .log.dom('#smth')
    .done();

Will output this:

 DOM: #smth <input type="hidden" value="not really a value" id="ijustwannahaveavalue"/>

Parameters:

  • selector String

    CSS selector

log.message

(
  • message
)
chainable

Logs a user defined message

test.open('http://dalekjs.com/guineapig')
    .execute(function () {
      this.data('aKey', 'aValue');
    })
    .log.message(function () {
      return test.data('aKey'); // outputs MESSAGE: 'aValue'
    })
    .done();

'Normal' messages can be logged too:

test.open('http://dalekjs.com/guineapig')
    .log.message('FooBar') // outputs MESSAGE: FooBar
    .done();

Parameters:

  • message Function | String

maximize

() chainable

Maximizes the browser window.

<div>
  <span id="magicspan">The span in the fireplace</span>
</div>

`css

magicspan {

display: inline; }

mouseEvent

(
  • type
  • selector
)
chainable

Triggers a mouse event on the first element found matching the provided selector. Supported events are mouseup, mousedown, click, mousemove, mouseover and mouseout. TODO: IMPLEMENT

Parameters:

  • type String
  • selector String

open

(
  • location
)
chainable

Performs an HTTP request for opening a given location. You can forge GET, POST, PUT, DELETE and HEAD requests.

Basically the same as typing a location into your browsers URL bar and hitting return.

test.open('http://dalekjs.com')
    .assert.url().is('http://dalekjs.com', 'DalekJS I\'m in you')
    .done();

Parameters:

  • location String

    URL of the page to open

query

(
  • selector
)
chainable

It can be really cumbersome to repeat selectors all over when performing multiple actions or assertions on the same element(s). When you use the query method (or its alias $), you're able to specify a selector once instead of repeating it all over the place.

So, instead of writing this:

test.open('http://doctorwhotv.co.uk/')
    .assert.text('#nav').is('Navigation')
    .assert.visible('#nav')
    .assert.attr('#nav', 'data-nav', 'true')
    .click('#nav')
    .done();

you can write this:

test.open('http://doctorwhotv.co.uk/')
    .query('#nav')
      .assert.text().is('Navigation')
      .assert.visible()
      .assert.attr('data-nav', 'true')
      .click()
    .end()
    .done();

Always make sure to terminate it with the end method!

Parameters:

  • selector String

    Selector of the element to query

reload

() chainable

Reloads current page location.

This is basically the same as hitting F5/refresh in your browser

test.open('http://google.com')
  .reload()
  .done();

resize

(
  • dimensions
)
chainable

Resizes the browser window to a set of given dimensions (in px). The default configuration of dalek opening pages is a width of 1280px and a height of 1024px. You can specify your own default in the configuration.

<div>
  <span id="magicspan">The span in the fireplace</span>
</div>
#magicspan {
  display: inline;
}

// @media all and (max-width: 500px) and (min-width: 300px)
#magicspan {
  display: none;
}
 test.open('http://adomain.com')
    .assert.visible('#magicspan', 'Big screen, visible span')
    .resize({width: 400, height: 500})
    .assert.notVisible('#magicspan', 'Small screen, no visible span magic!')
    .done();

Note: Does not work in Firefox

Parameters:

  • dimensions Object

    Width and height as properties to apply

screenshot

(
  • pathname
  • css
)

Take a screenshot of the current page or css element.

The pathname argument takes some placeholders that will be replaced Placeholder:

  • :browser - The browser name (e.g. 'Chrome', 'Safari', 'Firefox', etc.)
  • :version - The browser version (e.g. '10_0', '23_11_5', etc.)
  • :os - The operating system (e.g. OSX, Windows, Linux)
  • :osVersion - The operating system version (e.g XP, 7, 10_8, etc.)
  • :viewport - The current viewport in pixels (e.g. w1024_h768)
  • :timestamp - UNIX like timestapm (e.g. 637657345)
  • :date - Current date in format MM_DD_YYYY (e.g. 12_24_2013)
  • :datetime - Current datetime in format MM_DD_YYYY_HH_mm_ss (e.g. 12_24_2013_14_55_23)
// creates 'my/folder/my_file.png'
test.screenshot('my/folder/my_file.png');
// creates 'my/page/in/safari/homepage.png'
test.screenshot('my/page/in/:browser/homepage.png');
// creates 'my/page/in/safari_6_0_1/homepage.png'
test.screenshot('my/page/in/:browser_:version/homepage.png');
// creates 'my/page/in/safari_6_0_1/on/osx/homepage.png'
test.screenshot('my/page/in/:browser_:version/on/:os/homepage.png');
// creates 'my/page/in/safari_6_0_1/on/osx_10_8/homepage.png'
test.screenshot('my/page/in/:browser_:version/on/:os_:osVersion/homepage.png');
// creates 'my/page/at/w1024_h768/homepage.png'
test.screenshot('my/page/at/:viewport/homepage.png');
// creates 'my/page/at/637657345/homepage.png'
test.screenshot('my/page/in_time/:timestamp/homepage.png');
// creates 'my/page/at/12_24_2013/homepage.png'
test.screenshot('my/page/in_time/:date/homepage.png');
// creates 'my/page/at/12_24_2013_14_55_23/homepage.png'
test.screenshot('my/page/in_time/:datetime/homepage.png');

Parameters:

  • pathname String

    Name of the folder and file the screenshot should be saved to

  • css String

    selector of element should be screeshoted

Returns:

chainable

sendKeys

(
  • selector
  • keystrokes
)
chainable

This acts just like .type() with a key difference. This action can be used on non-input elements (useful for test site wide keyboard shortcuts and the like). So assumeing we have a keyboard shortcut that display an alert box, we could test that with something like this:

test.open('http://home.dalek.com')
    .sendKeys('body', '\uE00C')
    .assert.dialogText('press the escape key give this alert text')
    .done();

Note: Does not work correctly in Firefox with special keys

Parameters:

  • selector String

    Selector of the form field to be filled

  • keystrokes String

    Text to be applied to the element

setCookie

() chainable

Sets a cookie. More configuration options will be implemented in the future, by now, you can only set a cookie with a specific name and contents. This will be a domain wide set cookie.

 test.open('http://adomain.com')
     .setCookie('my_cookie_name', 'my=content')
     .done();

setHttpAuth

(
  • username
  • password
)
Actions

Sets HTTP_AUTH_USER and HTTP_AUTH_PW values for HTTP based authentication systems.

If your site is behind a HTTP basic auth, you're able to set the username and the password

test.setHttpAuth('OSWIN', 'rycbrar')
    .open('http://admin.therift.com');

Most of the time, you`re not storing your passwords within files that will be checked in your vcs, for this scenario, you have two options:

The first option is, to use daleks cli capabilities to generate config variables from the command line, like this

$ dalek --vars USER=OSWIN,PASS=rycbrar
test.setHttpAuth(test.config.get('USER'), test.config.get('PASS'))
    .open('http://admin.therift.com');

The second option is, to use env variables to generate config variables from the command line, like this

$ SET USER=OSWIN
$ SET PASS=rycbrar
$ dalek
test.setHttpAuth(test.config.get('USER'), test.config.get('PASS'))
    .open('http://admin.therift.com');

If both, dalek variables & env variables are set, the dalek variables win. For more information about this, I recommend to check out the configuration docs

TODO: IMPLEMENT

Parameters:

  • username String
  • password String

Returns:

setValue

(
  • selector
  • value
)
Actions

Fills the fields of a form with given values.

<input type="text" value="not really a value" id="ijustwannahaveavalue"/>
test.open('http://dalekjs.com')
    .setValue('#ijustwannahaveavalue', 'a value')
    .assert.val('#ijustwannahaveavalue', 'a value', 'Value is changed');

Parameters:

  • selector String
  • value String

Returns:

submit

(
  • selector
)
chainable

Submits a form.

<form id="skaaro" action="skaaro.php" method="GET">
  <input type="hidden" name="intheshadows" value="itis"/>
  <input type="text" name="truth" id="truth" value=""/>
</form>
test.open('http://home.dalek.com')
    .type('#truth', 'out there is')
    .submit('#skaaro')
    .done();

Note: Does not work in Firefox yet

Parameters:

  • selector String

    Selector of the form to be submitted

toFrame

(
  • selector
)
chainable

Switches to an iFrame context

Sometimes you encounter situations, where you need to drive/access an iFrame sitting in your page. You can access such frames with this method, but be aware of the fact, that the complete test context than switches to the iframe context, every action and assertion will be executed within the iFrame context. Btw.: The domain of the IFrame can be whatever you want, this method has no same origin policy restrictions.

If you wan't to get back to the parents context, you have to use the toParent method.

<div>
  <iframe id="login" src="/login.html"/>
</div>
 test.open('http://adomain.withiframe.com')
   .assert.title().is('Title of a page that embeds an iframe')
   .toFrame('#login')
     .assert.title().is('Title of a page that can be embedded as an iframe')
   .toParent()
   .done();

NOTE: Buggy in Firefox

Parameters:

  • selector String

    Selector of the frame to switch to

toParent

() chainable

Switches back to the parent page context when the test context has been switched to an iFrame context

<div>
  <iframe id="login" src="/login.html"/>
</div>
 test.open('http://adomain.withiframe.com')
   .assert.title().is('Title of a page that embeds an iframe')
   .toFrame('#login')
     .assert.title().is('Title of a page that can be embedded as an iframe')
   .toParent()
   .assert.title().is('Title of a page that embeds an iframe')
   .done();

NOTE: Buggy in Firefox

toParentWindow

() chainable

Switches back to the parent window context when the test context has been switched to a different window context

<div>
  <a onclick="window.open('http://google.com','goog','width=480, height=300')">Open Google</a>
</div>
 test.open('http://adomain.com')
   .assert.title().is('Title of a page that can open a popup window')
   .toWindow('goog')
     .assert.title().is('Google')
   .toParentWindow()
   .assert.title().is('Title of a page that can open a popup window')
   .done();

NOTE: Buggy in Firefox

toWindow

(
  • name
)
chainable

Switches to a different window context

Sometimes you encounter situations, where you need to access a different window, like popup windows. You can access such windows with this method, but be aware of the fact, that the complete test context than switches to the window context, every action and assertion will be executed within the chosen window context. Btw.: The domain of the window can be whatever you want, this method has no same origin policy restrictions.

If you want to get back to the parents context, you have to use the toParentWindow method.

<div>
  <a onclick="window.open('http://google.com','goog','width=480, height=300')">Open Google</a>
</div>
 test.open('http://adomain.com')
   .assert.title().is('Title of a page that can open a popup window')
   .toWindow('goog')
     .assert.title().is('Google')
   .toParentWindow()
   .done();

NOTE: Buggy in Firefox

Parameters:

  • name String

    Name of the window to switch to

type

(
  • selector
  • keystrokes
)
chainable

Types a text into an input field or text area. And yes, it really types, character for character, like you would do when using your keyboard.

<form id="skaaro" action="skaaro.php" method="GET">
  <input type="hidden" name="intheshadows" value="itis"/>
  <input type="text" name="truth" id="truth" value=""/>
</form>
test.open('http://home.dalek.com')
    .type('#truth', 'out there is')
    .assert.val('#truth', 'out there is', 'Text has been set')
    .done();

You can also send special keys using unicode.

  • test.open('http://home.dalek.com')
     .type('#truth', 'out \uE008there\uE008 is')
     .assert.val('#truth', 'out THERE is', 'Text has been set')
     .done();
    You can go here to read up on special keys and unicodes for them (note that a code of U+EXXX is actually written in code as \uEXXX).

Note: Does not work correctly in Firefox with special keys

Parameters:

  • selector String

    Selector of the form field to be filled

  • keystrokes String

    Text to be applied to the element

wait

(
  • timeout
)
chainable

Pause steps suite execution for a given amount of time, and optionally execute a step on done.

This makes sense, if you have a ticker for example, tht scrolls like every ten seconds & you want to assure that the visible content changes every ten seconds

test.open('http://myticker.org')
  .assert.visible('.ticker-element:first-child', 'First ticker element is visible')
  .wait(10000)
  .assert.visible('.ticker-element:nth-child(2)', 'Snd. ticker element is visible')
  .wait(10000)
  .assert.visible('.ticker-element:last-child', 'Third ticker element is visible')
  .done();

If no timeout argument is given, a default timeout of 5 seconds will be used

test.open('http://myticker.org')
  .assert.visible('.ticker-element:first-child', 'First ticker element is visible')
  .wait()
  .assert.visible('.ticker-element:nth-child(2)', 'Snd. ticker element is visible')
  .wait()
  .assert.visible('.ticker-element:last-child', 'Third ticker element is visible')
  .done();

Parameters:

  • timeout Number

    in milliseconds

waitFor

(
  • fn
  • args
  • timeout
)
chainable

Waits until a function returns true to process any next step.

You can also set a callback on timeout using the onTimeout argument, and set the timeout using the timeout one, in milliseconds. The default timeout is set to 5000ms.

 test.open('http://adomain.com')
    .waitFor(function () {
      return window.myCheck === true;
    })
    .done();

You can also apply arguments to the function, as well as a timeout

 test.open('http://adomain.com')
    .waitFor(function (aCheck) {
      return window.myThing === aCheck;
    }, ['arg1', 'arg2'], 10000)
    .done();

Note: Buggy in Firefox

Parameters:

  • fn Function

    Async function that resolves an promise when ready

  • args Array

    Additional arguments

  • timeout Number

    Timeout in miliseconds

waitForElement

(
  • selector
  • timeout
)
chainable

Waits until an element matching the provided selector expression exists in remote DOM to process any next step.

Lets assume we have a ticker that loads its contents via AJAX, and appends new elements, when the call has been successfully answered:

test.open('http://myticker.org')
  .assert.text('.ticker-element:first-child', 'First!', 'First ticker element is visible')
  // now we load the next ticker element, defsult timeout is 5 seconds
  .waitForElement('.ticker-element:nth-child(2)')
  .assert.text('.ticker-element:nth-child(2)', 'Me snd. one', 'Snd. ticker element is visible')
  // Lets assume that this AJAX call can take longer, so we raise the default timeout to 10 seconds
  .waitForElement('.ticker-element:last-child', 10000)
  .assert.text('.ticker-element:last-child', 'Me, third one!', 'Third ticker element is visible')
  .done();

Note that the function exits succesfully when the first element is found, matching the given selector

Parameters:

  • selector String

    Selector that matches the element to wait for

  • timeout Number

    Timeout in milliseconds

waitForResource

(
  • ressource
  • timeout
)
chainable

Wait until a resource that matches the given testFx is loaded to process a next step.

TODO: IMPLEMENT

Parameters:

  • ressource String

    URL of the ressource that should be waited for

  • timeout Number

    Timeout in miliseconds

waitForText

(
  • text
  • timeout
)
chainable

Waits until the passed text is present in the page contents before processing the immediate next step.

TODO: IMPLEMENT

Parameters:

  • text String

    Text to be waited for

  • timeout Number

    Timeout in miliseconds

waitUntilVisible

(
  • selector
  • timeout
)
chainable

Waits until an element matching the provided selector expression is visible in the remote DOM to process a next step.

TODO: IMPLEMENT

Parameters:

  • selector String

    Selector of the element that should be waited to become invisible

  • timeout Number

    Timeout in miliseconds

waitWhileVisible

(
  • selector
  • timeout
)
chainable

Waits until an element matching the provided selector expression is no longer visible in remote DOM to process a next step.

TODO: IMPLEMENT

Parameters:

  • selector String

    Selector of the element that should be waited to become visible

  • timeout Number

    Timeout in miliseconds