Protractor console log

protractor console log to file
protractor print to terminal
protractor-console-plugin
how to create log file in protractor
protractor logger
protractor async/await
protractor-browser-logs - npm
protractor style guide

I want to output the text of a div in my protractor test, so far I have:

console.log(ptor.findElement(protractor.By.id('view-container')).getText());

but this outputs

[object Object]

I tried "toString()" and same result.

Is there a way to output the text to the console?


getText and most other Protractor methods return promises. You want to put your console.log statement inside the promise resolution:

Using the new Protractor syntax:

element(by.id('view-container')).getText().then(function(text) {
  console.log(text);
});

Capture console.log in your Protractor Tests � ng-book.com – blog, Capture console. log in your Protractor Tests. browser. manage(). logs() . get('browser'). then(function(browserLog) { console. log('log: ' + require('util'). inspect(browserLog)); Reading Time: 1 minute This post is part of a ten-part series on how to write better Protractor tests. You can find the rest of the series here.. If you’re anything like me, your code probably has zillions of console.log everywhere.


this is pretty old, but as a former n00b at protractor, I wished there was more documentation.

you could also use:

element(by.id('view-container')).getText().then(console.log);

or what I like to do for readability is put all the objects on a page in their own function, section, or file:

//top declaration of variables
var viewContainer = element(by.id('view-container')).getText();

.... //bunch of code
....

viewContainer.then(console.log);

That will take care of most of your garden-variety debugging needs.

For promises in general, you could try using protractor.promise.all()

let's say you have two things that are both promises:

var getTime      = element(by.xpath(theTimeXpath)).getText();
var getPageTitle = element(by.xpath(thePageTitle)).getInnerHtml();

protractor.promise.all([getTime, getPageTitle]).then(function(theResultArray){

  var timeText           = result[0];
  var pageTitleInnerHtml = result[1];

   console.log(timeText);           // outputs the actual text
   console.log(pageTitleInnerHtml); //outputs the text of the Inner html
});

This second method is useful for when things begin to get more complex. personally, however, I find other ways around this. Although it's not bad, it's kind of funky for other developers having to read my code.

protractor-console, Print console logging statements that occur during Protractor test runs. Chrome console log Protractor is an end-to-end test framework for AngularJS applications. Protractor runs tests against your application running in a real browser, interacting with it as a user


I would like to suggest a small improvement to other answers.

short answer : I like to use browser.sleep(0).then(..); where I need to push something to protractor's flow.

it is generic and easy to move around.

tl;dr

so using the above, you can easily add a function on browser (or ptor) something like:

browser.log = function( logger, level, msg ){
     browser.sleep(0).then(function(){ logger[level](msg); });
}

or something a bit more sophisticated with apply - but that depends on your logger.

you can obviously enhance that a bit to have logger like api

var logger = browser.getLogger('name');

should be implemented like (lets assume log4js)

browser.getLogger = function( name ){
        var logger = require('log4js').getLogger(name);

        function logMe( level ) {
                 return function(msg ){
                      browser.sleep(0).then(function(){ logger[level](msg); });
                 }

        }

        return { info : logMe('info'), ... }
}

basically, the sky is the limit.

I am sure there's a way to make my code a lot shorter, the point is using the sleep method as basis.

Asserting console logs in Protractor tests - Frontend Weekly, Chrome console log. Protractor is an end-to-end test framework for AngularJS applications. Protractor runs tests against your application� Protractor Console output. As protractor is built on top of webdriver JS, we should resolve promise while printing to console output. so below statement doesn’t work. console.log("Browser title :- " + browser.gettitle()); instead, you can use. browser.getTitle().then(function(txt){console.log("Browser Title :- " + txt);}); watch details here


You could always assert that the text you get is the text you expect:

expect(element(by.id('view-container')).getText()).toBe('desired-text');

Protractor Logging - console output - print to log file, As protractor is built on top of webdriver JS, we should resolve promise while printing to Duration: 20:23 Posted: Jul 20, 2018 However, during execution of the protractor e2e test, the web site opens in chrome, I see things happen in the browser, then the browser closes before I can examine any console.log output. I think I need to keep chrome open somehow.


you can try this one:

const textInfo = element(by.id('view-container'));
console.log('text: ', textInfo.getText());

Unable to print the locator (webelement) in Console Log � Issue , Protractor Version: 4.0.3; Angular Version: ``; Browser(s): Chrome; Operating System and Version ``; Your protractor configuration file. exports� More generally, if I pass multiple arguments to console.log only the first one is logged, if the first argument is a string containing string-replacement format specifiers no replacement happens, and if the first argument is an object or something other than a string it's cast to a string, as far as the protractor-side log extraction is concerned.


Protractor logging Log4JS, qavbox_protractor_ts This video will show how to Print protractor output to console Use log4js Duration: 20:23 Posted: Jul 20, 2018 The logging levels available in protractor are: “OFF”, “SEVERE”, “WARNING”, “INFO”, “CONFIG”, “FINE”, “FINER”, “FINEST”, “ALL”. (Lower -> Higher) “ALL” is the highest logging level.


FAQs - Protractor, This will output logs from the browser console. Note that logs below the set logging level will be ignored. The default level is warnings and above. To change , add� Protractor Browser Commands – Restart the browser in Protractor Restart browser is done by closing the current browser instance automatically and creating a new one. But to note, restart function automatically overwrite all the previous settings such as maximize the window, angular switch, etc.


ElementArrayFinder.prototype.each - Protractor, element.all(by.css('.items li')).each(function(element, index) { // Will print 0 First, 1 Second, 2 Third. element.getText().then(function (text) { console.log(index,� Take screenshot for every failed spec in protractor+jasmine How to implement fluent wait using explicit wait in protractor? Setting Logging preferences in protractor: loggingPrefs November 6, 2016 March 30, 2017 by Vijay