//Auth: Maja
'use strict';
var webdriver = require('selenium-webdriver');
//var chai = require('chai');
//var expect = require('chai');
var assert = require('assert');
var sinon = require ('sinon');
var {Builder, By, until} = require('selenium-webdriver');
var test = require('selenium-webdriver/testing');
var driver = new webdriver.Builder().forBrowser('chrome').build();
/*--------------------------------------------------------------------------*/
test.describe('AgroLife: prijavljivanje na sistem\n', function() {
test.it('prijavna forma ispravno popunjena', function() {
driver.get('http://localhost:3000')
//driver.get('http://agrolife.greensoft.co:3000')
.then(_ => driver.findElement(By.id("textfield-1011-inputEl")).sendKeys("Miodrag"))
.then(_ => driver.findElement(By.id("textfield-1012-inputEl")).sendKeys("Miodrag"))
.then(_ => driver.findElement(By.id("textfield-1013-inputEl")).sendKeys("1243!"))
.then(_ => driver.wait(until.elementLocated(By.id('button-1015-btnIconEl')), 2000).click())
});
test.it('Prijava na sistem uspesna', function(){
driver.wait(until.elementLocated(By.id('button-1230-btnIconEl')), 90000);
});
});
/* -------------------------------------------------------------------------- */
test.describe('Materijali-window', function() {
test.it('Otvaranje prozora materijali', function() {
driver.wait(until.elementLocated(By.id('button-1243-btnIconEl')), 1000)
.then(_ => driver.findElement(By.id('button-1243-btnIconEl')).click())
.then(_ => driver.findElement(By.id('menuitem-1247-itemEl')).click())
});
});
test.describe('Unos grupe/podgrupe/materijal', function(){
test.it('Ispravni podaci grupe', function(){
//Materijali grupa
driver.wait(until.elementLocated(By.id('tab-1466-btnEl')), 10000).click()
// Materijali-grupa/forma
.then(_ => driver.findElement(By.id('textfield-1417-inputEl')).sendKeys('Maja grupa'))
.then(_ => driver.findElement(By.id('textfield-1418-inputEl')).sendKeys('Maja ikonica'))
.then(_ => driver.findElement(By.id('textfield-1419-inputEl')).sendKeys('Maja priotitet'))
//.then(_ => driver.findElement(By.id('ext-gen5431')).click())
test.it('Korisnik dodao grupu materijala', function(){
driver.wait(until.elementLocated(By.id('button-1424-btnInnerEl')), 5000).click();
});
});
test.it('Ispravni podaci podgrupe', function(){
//Materijali-podgrupa/forma
driver.wait(until.elementLocated(By.id('tab-1467-btnIconEl')),10000).click()
.then(_ => driver.findElement(By.id('combo-1453-inputEl')).sendKeys('Maja grupa'))
.then(_ => driver.findElement(By.id('textfield-1454-inputEl')).sendKeys('maja podgrupa'))
.then(_ => driver.findElement(By.id('textfield-1455-inputEl')).sendKeys('majina ikona'))
.then(_ => driver.findElement(By.id('textfield-1456-inputEl')).sendKeys('5'))
.then(_ => driver.findElement(By.id('ext-gen5343')).click())
//Dodaj
test.it('Korisnik dodao podgrupu materijala', function(){
driver.wait(until.elementLocated(By.id('button-1461-btnIconEl')), 5000).click();
});
//Sacuvaj izmene
//Brisanje
});
test.it('Ispravni podaci materijal', function(){
driver.wait(until.elementLocated(By.id('tab-1465-btnIconEl')),10000).click()
// Materijali-forma
.then(_ => driver.findElement(By.id('textfield-1374-inputEl')).sendKeys('789456'))
.then(_ => driver.findElement(By.id('textfield-1375-inputEl')).sendKeys('maja materijal'))
.then(_ => driver.findElement(By.id('numberfield-1376-inputEl')).sendKeys('100'))
.then(_ => driver.findElement(By.id('combo-1377-inputEl')).sendKeys('Goriva i maziva'))
.then(_ => driver.findElement(By.id('combo-1378-inputEl')).sendKeys('Gorivo'))
.then(_ => driver.findElement(By.id('combo-1379-inputEl')).sendKeys('Kelj'))
.then(_ => driver.findElement(By.id('textfield-1380-inputEl')).sendKeys('L'))
test.it('Korisnik dodao materijal', function(){
driver.wait(until.elementLocated(By.id('button-1385-btnIconEl')), 5000).click();
});
});
});
test.describe('Odjavljivanje iz aplikacije', function(){
test.it('odjavljivanje uspesno', function(){
// Odjava iz aplikacije
driver.findElement(By.id("button-1354-btnIconEl")).click()
.then(_ => driver.findElement(By.id("button-1005-btnIconEl")).click())
})
test.it('Izlazak iz browsera', function(){
// Zatvaranje browsera
driver.quit();
})
})
/* global describe, before, beforeEach, afterEach, it, browser, element, by, protractor */
import { expect, config } from './globals';
const EC = protractor.ExpectedConditions;
browser.ignoreSynchronization = true;
describe('Index page', () => {
const videoContainer = '.video-container';
const greenBtnClass = '.btn.btn-green';
const contactPopupEl = element(by.id('modal-contact'));
const contactPopupCloseEl = contactPopupEl.element(by.css('.close-modal'));
before(() => {
browser.get('');
});
it('should have title as \'Tactical Mastery Flashlights\'', () => {
expect(browser.getTitle()).to.eventually.equal('Tactical Mastery Flashlights');
});
describe('Contact modal - open', () => {
afterEach(() => {
contactPopupCloseEl.click();
browser.wait(EC.invisibilityOf(contactPopupEl), 1000);
});
it('should open contact popup when click on \'Yes! I want 75% Off!\' green button.', () => {
const buttonEl = element(by.cssContainingText(greenBtnClass, 'Yes! I want 75% Off!'));
browser.wait(EC.visibilityOf(buttonEl));
buttonEl.click();
browser.sleep(1000);
expect(contactPopupEl.isDisplayed()).to.eventually.equal(true);
});
if (config.capabilities.browserName === 'phantomjs') {
// console.warn('It can\'t test video on phantomjs.');
} else {
it('should open contact popup when click on \'Click Here\' of hero video', () => {
const buttonId = 'wistia_22_midrollLink_link';
const buttonEl = element(by.css(videoContainer)).element(by.id(buttonId));
browser.wait(EC.visibilityOf(buttonEl), 300000);
buttonEl.click();
browser.sleep(1000);
expect(contactPopupEl.isDisplayed()).to.eventually.equal(true);
});
it.skip('should open contact popup when the hero video ends', () => 'pending');
}
});
describe('Contact modal - validate', () => {
const buttonYesEl = element(by.cssContainingText('.btn.btn-danger', 'YES!'));
const nameEl = element(by.name('contactModalName'));
const emailEl = element(by.name('email'));
const phoneEl = element(by.name('phoneNumber'));
const nameGroupEl = element(by.css('.form-group-name'));
const emailGroupEl = element(by.css('.form-group-email'));
const phoneGroupEl = element(by.css('.form-group-phone'));
before(() => {
const buttonEl = element(by.cssContainingText(greenBtnClass, 'Yes! I want 75% Off!'));
browser.wait(EC.elementToBeClickable(buttonEl), 1000);
buttonEl.click();
browser.wait(EC.visibilityOf(contactPopupEl), 1000);
});
describe('Name field', () => {
const emptyValidator = nameGroupEl.element(by.cssContainingText('.form-control-feedback', 'Please enter your name.'));
const lengthValidator = nameGroupEl.element(by.cssContainingText('.form-control-feedback', 'The name must be more than 1 and less than 100'));
const rightValidator = nameGroupEl.element(by.cssContainingText('.valid-message.text-success', 'Nice to meet you!'));
beforeEach(() => {
nameEl.clear();
});
it('should validate name when input \'\'', () => {
nameEl.sendKeys('');
buttonYesEl.click();
browser.sleep(1000);
expect(emptyValidator.isDisplayed()).to.eventually.equal(true);
});
it('should validate name when input long length string greater than 100', () => {
let longName = '0';
for (let i = 0, end = 100; i < end; i += 1) {
longName = `0${longName}`;
}
nameEl.sendKeys(longName);
expect(lengthValidator.isDisplayed()).to.eventually.equal(true);
});
it('should validate name when input \'OK\'', () => {
nameEl.sendKeys('OK');
expect(rightValidator.isDisplayed()).to.eventually.equal(true);
});
});
describe('Email field', () => {
const emptyValidator = emailGroupEl.element(by.cssContainingText('.form-control-feedback', 'The email address is required.'));
const formatValidator = emailGroupEl.element(by.cssContainingText('.form-control-feedback', 'The email address is not valid.'));
const lengthValidator = emailGroupEl.element(by.cssContainingText('.form-control-feedback', 'The email address must be more than 6 and less than 30'));
const rightValidator = emailGroupEl.element(by.cssContainingText('.valid-message.text-success', 'Great!'));
beforeEach(() => {
emailEl.clear();
});
it('should validate email when input \'\'', () => {
emailEl.sendKeys('');
buttonYesEl.click();
browser.sleep(1000);
expect(emptyValidator.isDisplayed()).to.eventually.equal(true);
});
it('should validate email when input \'wrong\'', () => {
emailEl.sendKeys('wrong');
expect(formatValidator.isDisplayed()).to.eventually.equal(true);
});
it.skip('should validate email when input \'[email protected]\'', () => {
emailEl.sendKeys('[email protected]');
expect(formatValidator.isDisplayed()).to.eventually.equal(true);
});
it('should validate email when input \'[email protected]\'', () => {
emailEl.sendKeys('[email protected]');
expect(formatValidator.isDisplayed()).to.eventually.equal(true);
});
it('should validate email when input \'[email protected]\'', () => {
emailEl.sendKeys('[email protected]');
expect(lengthValidator.isDisplayed()).to.eventually.equal(true);
});
it('should validate email when input long \'[email protected]\'', () => {
emailEl.sendKeys('[email protected]');
expect(lengthValidator.isDisplayed()).to.eventually.equal(true);
});
it('should validate email when input \'[email protected]\'', () => {
emailEl.sendKeys('[email protected]');
expect(rightValidator.isDisplayed()).to.eventually.equal(true);
});
});
describe('Phone field', () => {
const emptyValidator = phoneGroupEl.element(by.cssContainingText('.form-control-feedback', 'Please supply a phone number'));
const formatValidator = phoneGroupEl.element(by.cssContainingText('.form-control-feedback', 'Not a valid 10-digit US phone number'));
const rightValidator = phoneGroupEl.element(by.cssContainingText('.valid-message.text-success', 'Success!'));
beforeEach(() => {
phoneEl.clear();
});
it('should validate phone number when input \'\'', () => {
phoneEl.sendKeys('');
buttonYesEl.click();
browser.sleep(1000);
expect(emptyValidator.isDisplayed()).to.eventually.equal(true);
});
it('should validate phone number when input single letter \'a\'', () => {
phoneEl.sendKeys('a');
expect(emptyValidator.isDisplayed()).to.eventually.equal(true);
});
it('should validate phone number when input letters \'test phone number\'', () => {
phoneEl.sendKeys('test phone number');
expect(emptyValidator.isDisplayed()).to.eventually.equal(true);
});
it('should validate phone number when input short digits \'12345\'', () => {
phoneEl.sendKeys('12345');
expect(formatValidator.isDisplayed()).to.eventually.equal(true);
});
it('should trim 10 digits and validate phone number when input long digits \'00001111222233334444\'', () => {
phoneEl.sendKeys('00001111222233334444');
expect(rightValidator.isDisplayed()).to.eventually.equal(true);
});
it('should filter digits and validate phone number when input complex string \'000 a111 222b cc333\'', () => {
phoneEl.sendKeys('000 a111 222b cc333');
expect(rightValidator.isDisplayed()).to.eventually.equal(true);
});
});
});
});
'use strict';
/* global browser, element, expect */
var params = browser.params.scenarios;
// Iterate through available test parameters
for (var p in params) {
if (params.hasOwnProperty(p)) {
var param = params[p];
// IIFE needed because the async nature of e2e protractor tests
(function(param) {
// E2E tests // START
describe('caret aware ' + param.type, function() {
var el,
attrVal = 'cursor',
UP_KEY = param.type === 'input' ?
protractor.Key.UP :
protractor.Key.PAGE_UP,
DOWN_KEY = param.type === 'input' ?
protractor.Key.DOWN :
protractor.Key.PAGE_DOWN;
beforeEach(function() {
browser.get(param.page);
el = element(by.id(param.id));
});
it('should have directive attribute with "' + attrVal + '" value', function() {
el.getAttribute('data-caret-aware').then(function(attr) {
expect(typeof attr).toBe('string');
expect(attr).toEqual(attrVal);
});
});
it('should caret have to be initialized to 0 and not movable', function() {
el.evaluate(attrVal).then(function(pos) {
expect(pos).toEqual(0);
el.sendKeys(protractor.Key.END);
el.evaluate(attrVal).then(function(pos) {
expect(pos).toEqual(0);
el.sendKeys(protractor.Key.UP);
el.evaluate(attrVal).then(function(pos) {
expect(pos).toEqual(0);
});
});
});
});
describe('should track caret position when movement keys are used', function() {
var text;
beforeEach(function() {
text = param.text;
el.sendKeys(text);
});
it('should move caret to the start when UP KEY is used', function() {
if (browser.name === 'firefox' && param.type === 'input') {
// NOTE: skipped // FIXME: what firefox want?
} else {
el.sendKeys(UP_KEY);
el.evaluate(attrVal).then(function(pos) {
expect(pos).toEqual(0);
});
}
});
it('should move caret to the end when DOWN KEY is used', function() {
el.sendKeys(UP_KEY);
el.sendKeys(DOWN_KEY);
el.evaluate(attrVal).then(function(pos) {
expect(pos).toEqual(text.length);
});
});
it('should decrement caret when ARROW LEFT is used', function() {
el.sendKeys(protractor.Key.ARROW_LEFT);
el.evaluate(attrVal).then(function(pos) {
expect(pos).toEqual(text.length - 1);
});
});
it('should decrement caret when LEFT is used', function() {
el.sendKeys(protractor.Key.LEFT);
el.evaluate(attrVal).then(function(pos) {
expect(pos).toEqual(text.length - 1);
});
});
it('should decrement caret when ARROW RIGHT is used', function() {
el.sendKeys(protractor.Key.ARROW_LEFT);
el.sendKeys(protractor.Key.ARROW_RIGHT);
el.evaluate(attrVal).then(function(pos) {
expect(pos).toEqual(text.length);
});
});
it('should decrement caret when RIGHT is used', function() {
el.sendKeys(protractor.Key.LEFT);
el.sendKeys(protractor.Key.RIGHT);
el.evaluate(attrVal).then(function(pos) {
expect(pos).toEqual(text.length);
});
});
it('should stop caret when at maximum right position', function() {
el.sendKeys(DOWN_KEY);
el.evaluate(attrVal).then(function(pos) {
expect(pos).toEqual(text.length);
el.sendKeys(DOWN_KEY);
el.evaluate(attrVal).then(function(pos) {
expect(pos).toEqual(text.length);
});
});
});
it('should stop caret when at minimum left position', function() {
if (browser.name === 'firefox' && param.type === 'input') {
// NOTE: skipped // FIXME: what firefox want?
} else {
el.sendKeys(UP_KEY);
el.evaluate(attrVal).then(function(pos) {
expect(pos).toEqual(0);
el.sendKeys(UP_KEY);
el.evaluate(attrVal).then(function(pos) {
expect(pos).toEqual(0);
});
});
}
});
});
describe('should track caret position when input changes', function() {
var text;
beforeEach(function() {
text = param.text;
el.sendKeys(text);
});
it('should move caret forward when text is inserted', function() {
el.evaluate(attrVal).then(function(pos) {
expect(pos).toEqual(text.length);
});
});
it('should move caret backward when text is deleted with backspace', function() {
var numToCancel = 2,
i = numToCancel;
while (i-- > 0) {
el.sendKeys(protractor.Key.BACK_SPACE);
}
el.evaluate(attrVal).then(function(pos) {
expect(pos).toEqual(text.length - numToCancel);
});
});
it('should keep the caret fixed when text is deleted with canc', function() {
if (browser.name === 'firefox' && param.type === 'input') {
// NOTE: skipped // FIXME: what firefox want?
} else {
el.sendKeys(UP_KEY);
el.sendKeys(protractor.Key.DELETE);
el.evaluate(attrVal).then(function(pos) {
expect(pos).toEqual(0);
});
}
});
it('should move caret forwar when text is prepended', function() {
if (browser.name === 'firefox' && param.type === 'input') {
// NOTE: skipped // FIXME: what firefox want?
} else {
var pre = 'pre';
el.sendKeys(UP_KEY);
el.sendKeys(pre);
el.evaluate(attrVal).then(function(pos) {
expect(pos).toEqual(pre.length);
});
}
});
});
describe('should track caret positions when the text of the element is selected', function() {
var text,
selectionBtn,
selectionRes;
beforeEach(function() {
selectionBtn = element(by.buttonText('print selection'));
selectionRes = element(by.id('selection'));
text = param.text;
el.sendKeys(text);
});
it('should correctly retrieve selection info when text is selected through SHIFT + ARROW LEFT', function() {
var arrows = 4,
resultingStart = text.length - arrows;
// Cursor is at the end, select RTL: KEYDOWN W/ SHIFT + ARROW_LEFT(s) + KEYUP W/ SHIFT
browser
.actions()
.keyDown(protractor.Key.SHIFT)
.sendKeys(Array(arrows + 1).join(protractor.Key.ARROW_LEFT))
.keyUp(protractor.Key.SHIFT)
.perform();
// Check resulting start pos
el.evaluate(attrVal).then(function(pos) {
expect(pos).toEqual(resultingStart);
});
// Check selection info
browser.actions().click(selectionBtn).perform();
selectionRes.getText().then(function(content) {
expect(JSON.parse(content)).toEqual({
start: resultingStart,
end: text.length,
length: arrows,
text: text.substr(resultingStart, arrows)
});
});
});
it('should correctly retrieve selection info when text is selected through SHIFT + ARROW RIGHT', function() {
if (browser.name === 'firefox' && param.type === 'input') {
// NOTE: skipped // FIXME: what firefox want?
} else {
var arrows = 4,
resultingEnd = arrows;
el.sendKeys(UP_KEY);
// Cursor is at the 0, select LTR: KEYDOWN W/ SHIFT + ARROW_RIGHT(s) + KEYUP W/ SHIFT
browser
.actions()
.keyDown(protractor.Key.SHIFT)
.sendKeys(Array(arrows + 1).join(protractor.Key.ARROW_RIGHT))
.keyUp(protractor.Key.SHIFT)
.perform();
// Check start pos
el.evaluate(attrVal).then(function(pos) {
expect(pos).toEqual(0);
});
// Check selection info
browser.actions().click(selectionBtn).perform();
selectionRes.getText().then(function(content) {
expect(JSON.parse(content)).toEqual({
start: 0,
end: resultingEnd,
length: arrows,
text: text.substr(0, resultingEnd)
});
});
}
});
it('should correctly handle CTRL + A', function() {
el.sendKeys(protractor.Key.chord(protractor.Key.CONTROL, 'a'));
el.evaluate(attrVal).then(function(pos) {
expect(pos).toEqual(0);
});
// Check selection info
browser.actions().click(selectionBtn).perform();
selectionRes.getText().then(function(content) {
expect(JSON.parse(content)).toEqual({
start: 0,
end: text.length,
length: text.length,
text: text
});
});
});
it('should allow to click when content is selected and update caret position', function() {
if (browser.name === 'firefox') {
// NOTE: skipped // FIXME: what firefox want?
} else {
var wantedPos = 1;
var factor = param.type === 'input' ? 7.5 : 10;
browser
.actions()
.keyDown(protractor.Key.SHIFT)
.sendKeys(Array(text.length + 1).join(protractor.Key.ARROW_LEFT))
.keyUp(protractor.Key.SHIFT)
.perform();
//
el.evaluate(attrVal).then(function(pos) {
expect(pos).toEqual(0);
// Now click at (factor * wantedPos, 15) pixels offset from top left
// (i.e., aproximately after third character)
browser
.actions()
.mouseMove(el, { x: factor * wantedPos, y: 15 })
.click()
.perform();
// Verify
el.evaluate(attrVal).then(function(pos) {
expect(pos).toEqual(wantedPos);
});
browser.actions().click(selectionBtn).perform();
selectionRes.getText().then(function(content) {
expect(JSON.parse(content)).toEqual({
start: wantedPos,
end: wantedPos,
length: 0,
text: ''
});
});
});
}
});
});
describe('should track caret position when element is clicked', function() {
var text,
factor = param.type === 'input' ? 7.5 : 10;
beforeEach(function() {
text = param.text;
el.sendKeys(text);
});
it('should work when element is clicked at the start', function() {
if (browser.name === 'firefox') {
// NOTE: skipped // FIXME: what firefox want?
} else {
var startPos = 0;
browser
.actions()
.mouseMove(el, { x: factor * startPos, y: 15})
.click()
.perform();
el.evaluate(attrVal).then(function(pos) {
expect(pos).toEqual(0);
});
}
});
it('should work when element is clicked at the end', function() {
var endPos = text.length;
var nlines = text.split(/\n/).length;
var y = nlines > 0 ? nlines * 15 : 15;
browser
.actions()
.mouseMove(el, { x: factor * endPos, y: y})
.click()
.perform();
el.evaluate(attrVal).then(function(pos) {
expect(pos).toEqual(endPos);
});
});
});
});
// E2E tests // END
})(param);
}
}
Accelerate Your Automation Test Cycles With LambdaTest
Leverage LambdaTest’s cloud-based platform to execute your automation tests in parallel and trim down your test execution time significantly. Your first 100 automation testing minutes are on us.