npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

astrolabe

v0.3.6

Published

Page objects for protractor

Downloads

1,172

Readme

Astrolabe Build Status

Astrolabe is an extension for protractor that adds page objects to your functional/e2e tests.

Installation

via npm (node package manager)

$ npm install astrolabe

Usage

Example signInPage.js

var Page = require('astrolabe').Page;

module.exports = Page.create({

    url: { value: 'http://mysite.com/signin' },

    username: { get: function() { return this.findElement(this.by.input('username')); } }, // finds an input element with the name 'username'
    submit:   { get: function() { return this.findElement(this.by.id('submit')); } }       // finds an element with the id 'submit'
});

adding to tests:

var signInPage = require('./path/to/signInPage');

...

navigating:

signInPage.go(); // will send browser to 'http://mysite.com/signin'

signInPage.go('some', 'path'); // will send browser to 'http://mysite.com/signin/some/path'
signInPage.go('some/path');    // will send browser to 'http://mysite.com/signin/some/path'

signInPage.go({ some: 'query' }); // will send browser to 'http://mysite.com/signin?some=query'

interacting: (See Protractor API Docs for more info on available api methods)

signInPage.username.sendKeys('a username'); // will fill the username input with the text 'a username'

signInPage.submit.click(); // will click on the submit element
signInPage.username.getAttribute('value'); // will return a promise that is resolved with the value of the text field, in this case 'a username'

// this can be used within an expectation
expect(signInPage.username.getAttribute('value')).toBe('a username');

It is possible to create convenience methods to wrap up common logic.

Example signInPage.js

var Page = require('astrolabe').Page;

module.exports = Page.create({

    url: { value: 'http://mysite.com/signin' },

    username: { get: function() { return this.findElement(this.by.input('username')); } },
    password: { get: function() { return this.findElement(this.by.input('password')); } },
    submit:   { get: function() { return this.findElement(this.by.id('submit')); } },
    invalid:  { get: function() { return this.findElement(this.by.id('incorrectLogin')); } },

    InvalidLoginException: { get: function() { return this.exception('Invalid Login'); } },

    // Adds a signIn method to the page object.
    signIn:   { value: function(username, password) {

        var page = this;

        page.go();

        page.username.sendKeys(username);
        page.password.sendKeys(password);

        page.submit.click();

        return this.invalid.isDisplayed().then(function (wrongLogin) {
            if (wrongLogin) {
                page.InvalidLoginException.thro(username + ', ' + password + ' is not valid');
            }
        });
    } }
});

can be used in your tests:

var signInPage = require('./path/to/signInPage');

...

signInPage.signIn('test user', 'testpassword'); // will navigate to sign in page, enter username and password then click submit.

...

Cloning and running Astrolabe's tests

Clone the github repository.

git clone https://github.com/stuplum/astrolabe.git
cd astrolabe
npm install

npm test

Running Astrolabe's example protractor test

Install protractor with.

npm install protractor

Start up a selenium server (See the appendix below for help with this). By default, the tests expect the selenium server to be running at http://localhost:4444/wd/hub.

The example folder contains a simple test suite which runs against angularjs.org. It is a port of the simple test suite included with protractor.

Currently only the protractor runner is supported. The runner accepts a configuration file, which runs the tests at example/onProtractorRunner.js.

node_modules/.bin/protractor examples/protractor.conf.js

Setting up a standalone selenium server

See Appendix A of protractor's installation instructions