Fetching values from email in protractor test case

This is something I’ve solved recently. Hope the solution would also apply for your use-case. Prerequisites: mail-listener2 package understanding of the concept of promises Step by step instructions: Install mail-listener2: npm install mail-listener2 –save-dev In your protractor config initialize Mail Listener and make it available globally: onPrepare: function () { var MailListener = require(“mail-listener2”); // … Read more

Expected conditions in protractor

Once feat(expectedConditions) is in (probably protractor 1.7), you can do: var EC = protractor.ExpectedConditions; var e = element(by.id(‘xyz’)); browser.wait(EC.presenceOf(e), 10000); expect(e.isPresent()).toBeTruthy(); Please note though, if you’re working with an Angular app and your test requires these conditional waits, it’s a big red flag for what you’re doing, as protractor should handle waits natively.

What is browser.ignoreSynchronization in protractor?

The simple answer is that it makes protractor not wait for Angular promises, such as those from $http or $timeout to resolve, which you might want to do if you’re testing behaviour during $http or $timeout (e.g., a “loading” message), or testing non-Angular sites or pages, such as a separate login page. For example, to … Read more

Element not visible error (not able to click an element)

This is a rather common problem in test automation with selenium. Here are the common solutions: make sure the element you want to click is actually visible. Sometimes you need to make extra actions on a page to make the element visible. For example, open up a dropdown for an option to appear or open … Read more

Select -> option abstraction

No such thing in Protractor, but we can write our own: select-wrapper.js ‘use strict’; var SelectWrapper = function(selector) { this.webElement = element(selector); }; SelectWrapper.prototype.getOptions = function() { return this.webElement.all(by.tagName(‘option’)); }; SelectWrapper.prototype.getSelectedOptions = function() { return this.webElement.all(by.css(‘option[selected=”selected”]’)); }; SelectWrapper.prototype.selectByValue = function(value) { return this.webElement.all(by.css(‘option[value=”‘ + value + ‘”]’)).click(); }; SelectWrapper.prototype.selectByPartialText = function(text) { return this.webElement.all(by.cssContainingText(‘option’, text)).click(); … Read more

Protractor e2e test case for downloading pdf file

I can currently set download path location Chrome capabilities: { ‘browserName’: ‘chrome’, ‘platform’: ‘ANY’, ‘version’: ‘ANY’, ‘chromeOptions’: { // Get rid of –ignore-certificate yellow warning args: [‘–no-sandbox’, ‘–test-type=browser’], // Set download path and avoid prompting for download even though // this is already the default on Chrome but for completeness prefs: { ‘download’: { ‘prompt_for_download’: … Read more

how to use Protractor on non angularjs website?

Another approach is to set browser.ignoreSynchronization = true before browser.get(…). Protractor wouldn’t wait for Angular loaded and you could use usual element(…) syntax. browser.ignoreSynchronization = true; browser.get(‘http://localhost:8000/login.html’); element(by.id(‘username’)).sendKeys(‘Jane’); element(by.id(‘password’)).sendKeys(‘1234’); element(by.id(‘clickme’)).click();

How to disable animations in protractor for angular js application

You can check out the angular’s protractor configuration: https://github.com/angular/angular.js/blob/master/protractor-shared-conf.js You should add it under onPrepare block: onPrepare: function() { /* global angular: false, browser: false, jasmine: false */ // Disable animations so e2e tests run more quickly var disableNgAnimate = function() { angular.module(‘disableNgAnimate’, []).run([‘$animate’, function($animate) { $animate.enabled(false); }]); }; browser.addMockModule(‘disableNgAnimate’, disableNgAnimate);

Using protractor with loops

The reason this is happening is because protractor uses promises. Read https://github.com/angular/protractor/blob/master/docs/control-flow.md Promises (i.e. element(by…), element.all(by…)) execute their then functions when the underlying value becomes ready. What this means is that all the promises are first scheduled and then the then functions are run as the results become ready. When you run something like this: … Read more