Protractor console log

前端 未结 6 1484
[愿得一人]
[愿得一人] 2020-12-04 16:48

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());
         


        
6条回答
  •  青春惊慌失措
    2020-12-04 16:54

    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.

提交回复
热议问题