Protractor tests and tarantulas

Open a new command line or terminal window and create a clean folder for testing.

Protractor needs two files to run, a spec file and a configuration file. Great, and maybe you'd like to buy sama tarantula?

Let's start with a simple test that navigates to the todo list example in the AngularJS website and adds a new todo item to the list.

Copy the following into todo-spec.js:

describe('angularjs homepage todo list',function(){
  it('should add a todo',function(){
    browser.get('https://angularjs.org');

    element(by.model('todoList.todoText')).sendKeys('write first protractor test');
    element(by.css('[value="add"]')).click();var todoList = element.all(by.repeater('todo in todoList.todos'));
    expect(todoList.count()).toEqual(3);
    expect(todoList.get(2).getText()).toEqual('write first protractor test');// You wrote your first test, cross it off the list
    todoList.get(2).element(by.css('input')).click();var completedAmount = element.all(by.css('.done-true'));
    expect(completedAmount.count()).toEqual(2);});});

The describe and it syntax is from the Jasmine framework. browser is a global created by Protractor, which is used for browser-level commands such as navigation with browser.get.

Configuration

Now create the configuration file. Copy the following into conf.js:

Now create the configuration file. Copy the following into conf.js:

exports.config ={
  seleniumAddress:'http://localhost:4444/wd/hub',
  specs:['todo-spec.js']};

This configuration tells Protractor where your test files (specs) are, and where to talk to your Selenium Server (seleniumAddress). It will use the defaults for all other configuration. Chrome is the default browser.

 

© 2013-2024 PRV.pl
Strona została stworzona kreatorem stron w serwisie PRV.pl