выдержка углового/транспортира с несколькими полями формы

Вопрос:

Это мой первый тест углов/транспортиров для формы входа. При запуске теста он будет тестировать одно поле формы одновременно без проблем, но при добавлении второго поля для проверки он всегда истекает. Есть ли секрет для тестирования полей формы, о которых я не знаю?

'use strict';

describe('Login', function () {
beforeEach(function () {
// URL is relative to baseUrl specified in config/test/protractor-e2e.conf.js
browser.get('');

// browser.get('');
// var account = browser.findElement(by.css('#sign-in-account'));
// var username = browser.findElement(by.css('#sign-in-username'));
// var password = browser.findElement(by.css('#sign-in-password'));
// var submit = browser.findElement(by.css('.button-primary'));
// submit.click();
});

it('should redirect user to first module they have access to after successful login',  function () {

// Should successfully register a user
element(by.name('account')).sendKeys('test');
element(by.name('username')).sendKeys('[email protected]');
// element(by.name('password')).sendKeys('1234');
// element(by.css('.button-primary')).click();

// Should move to register page
// expect(browser.getCurrentUrl()).toContain('silpada.kineticsupply.com/module/analytics');
// Should show the first name where the lock icon was
// expect(element(by.name('account')).getText()).toContain('test');
}, 50000);
});

/*
* config/test/protractor-e2e.conf.js
*
* Protractor end-to-end testing configuration
*/

exports.config = {
// ----- How to setup Selenium -----
//
// There are three ways to specify how to use Selenium. Specify one of the
// following:
//
// 1. seleniumServerJar - to start Selenium Standalone locally.
// 2. seleniumAddress - to connect to a Selenium server which is already
//    running.
// 3. sauceUser/sauceKey - to use remote Selenium servers via SauceLabs.

// The location of the selenium standalone server .jar file.
seleniumServerJar: null,
// The port to start the selenium server on, or null if the server should
// find its own unused port.
seleniumPort: null,
// Chromedriver location is used to help the selenium standalone server
// find chromedriver. This will be passed to the selenium jar as
// the system property webdriver.chrome.driver. If null, selenium will
// attempt to find chromedriver using PATH.
chromeDriver: null,
// Additional command line options to pass to selenium. For example,
// if you need to change the browser timeout, use
// seleniumArgs: ['-browserTimeout=60'],
seleniumArgs: [],

// If sauceUser and sauceKey are specified, seleniumServerJar will be ignored.
// The tests will be run remotely using SauceLabs.
sauceUser: null,
sauceKey: null,

// The address of a running selenium server. If specified, Protractor will
// connect to an already running instance of selenium. This usually looks like
seleniumAddress: 'http://localhost:4444/wd/hub',


// ----- What tests to run -----
//
// Spec patterns are relative to the location of this config.
specs: [
'./e2e/**/login.js'
],

// ----- Capabilities to be passed to the webdriver instance ----
//
// For a full list of available capabilities, see
// https://code.google.com/p/selenium/wiki/DesiredCapabilities
// and
// https://code.google.com/p/selenium/source/browse/javascript/webdriver/capabilities.js
capabilities: {
'browserName': 'chrome'
},

// A base URL for your application under test. Calls to protractor.get()
// with relative paths will be prepended with this.
//baseUrl: 'http://localhost:8081',
baseUrl: 'http://silpada.kineticsupply.com',

allScriptsTimeout:30000,

// Selector for the element housing the angular app - this defaults to
// body, but is necessary if ng-app is on a descendant of <body>
rootElement: 'body',

// A callback function called once protractor is ready and available, and
// before the specs are executed
// You can specify a file containing code to run by setting onPrepare to
// the filename string.
onPrepare: function () {
// At this point, global 'protractor' object will be set up, and jasmine
// will be available. For example, you can add a Jasmine reporter with:
//     jasmine.getEnv().addReporter(new jasmine.JUnitXmlReporter(
//         'outputdir/', true, true));
},

// ----- Options to be passed to minijasminenode -----
jasmineNodeOpts: {
// onComplete will be called just before the driver quits.
onComplete: null,
// If true, display spec names.
isVerbose: true,
// If true, print colors to the terminal.
showColors: true,
// If true, include stack traces in failures.
includeStackTrace: true,
// Default time to wait in ms before a test fails.
defaultTimeoutInterval: 30000
}
};

<div id="sign-in-container">
<div id="sign-in">
<div class="logoContainer">
<!-- <img src="/assets/img/silpada_logo.png" style="display:block;padding:2rem 0;margin:auto;" alt=""> -->
<img ng-src="{{clientLogo}}" style="display:block;padding:2rem 0;margin:auto;" alt="">
</div>
<div ng-hide="catchResponses" alerts></div>
<form id="sign-in-form" name="authForm" ng-submit="login(credentials)">

<input
id="sign-in-account"
name="account"
type="text"
placeholder="Account ID"
ng-model="credentials.account"
required />

<input
id="sign-in-username"
name="username"
type="text"
placeholder="Username"
ng-model="credentials.username"
required />

<input
id="sign-in-password"
name="password"
type="password"
placeholder="Password"
ng-model="credentials.password"
required />

<button ng-disabled="authForm.$invalid || authenticating()" class="button-primary" type="submit">Login <i style="float:right; font-size:1.5rem;" class="fa fa-cog fa-spin" ng-show="authenticating()"></i></button>
<div id="reset-password"><a href="" ng-click="modal()">Forgot password?</a></div>
</form>
</div>

Ответ №1

Здесь мой рабочий скрипт, просто добавьте ptor.ignoreSynchronization = true;

describe('Login', function () {
ptor = protractor.getInstance();
ptor.ignoreSynchronization = true;

beforeEach(function () {
// URL is relative to baseUrl specified in config/test/protractor-e2e.conf.js
ptor.get('/');
});

it('should redirect user to first module they have access to after successful login',  function () {
// Should successfully register a user
ptor.findElement(protractor.By.name('account')).sendKeys('test');
ptor.findElement(protractor.By.name('username')).sendKeys('[email protected]');
ptor.findElement(protractor.By.name('password')).sendKeys('1234');
ptor.findElement(protractor.By.css('.button-primary')).click();

// Should move to register page
expect(browser.getCurrentUrl()).toContain('silpada.kineticsupply.com/module/analytics');

// Should show the first name where the lock icon was
expect(element(by.name('account')).getText()).toContain('test');
});
});

Мой текущий результат

Using the selenium server at http://localhost:4444/wd/hub

Login
should redirect user to first module they have access to after successful lo
gin

Failures:

1) Login should redirect user to first module they have access to after succes
sful login
Message:
Expected 'http://silpada.kineticsupply.com/login' to contain 'silpada.kinet
icsupply.com/module/analytics'.
Stacktrace:
Error: Failed expectation

2) Login should redirect user to first module they have access to after succes
sful login
Message:
Expected '' to contain 'test'.

Stacktrace:
Error: Failed expectation

Finished in 12.697 seconds
1 test, 2 assertions, 2 failures

Оцените статью
TechArks.Ru
Добавить комментарий