0
votes

I am working on report execution part in Protractor and using Jasmine2 Html Reporter. I am able to generate a report but when my test passes completely without any failure still report shows status as 0.00%. I am not sure why this is happening. I am also attaching the snap shot for the reference.

enter image description here

The code is :

var HtmlReporter = require('protractor-jasmine2-html-reporter');

var reporter = new HtmlReporter({
    plugins: [{
    package: 'jasmine2-protractor-utils',
    showSummary: true,
    reportTitle: "Clinicare Report",
    filename: 'Clinicarereport.html',
    disableHTMLReport: false,//disableHTMLReport
    disableScreenshot: false,
    captureOnlyFailedSpecs: true,
    screenshotPath:'./reports/screenshots',
    screenshotOnExpectFailure:true,
    screenshotOnSpecFailure:true,
    dest: 'protractor-reports',
    filename: 'protractor-report.html',
    takeScreenshots: true,
    ignoreSkippedSpecs: true,
    takeScreenshotsOnlyOnFailures: true
//  screenshotsFolder: 'F:\\Screeshots'
    }]
});             
exports.config = 
{

    directconnect: true,
    capabilities: {'browserName': 'chrome'},
    framework: 'jasmine',
    specs: ['example1.js'],
    jasmineNodeOpts: {
    defaultTimeoutInterval: 300000
},
onPrepare: function() {
// Add a screenshot reporter and store screenshots to `/tmp/screenshots`:
      jasmine.getEnv().addReporter(reporter);     
  }
  }

The spec code is:

var Excel = require('exceljs');
        var XLSX = require('xlsx');
        var os = require('os');
        var TEMP_DIR = os.tmpdir();
        var wrkbook = new Excel.Workbook();

        describe('Open the clinicare website by logging into the site', function () {
        it('Should Add a text in username and password fields and hit login button', function () {
        console.log("hello6");

        var wb = XLSX.readFile('E:\\Demo\\Generate a test report\\Data_Login.xlsx');
        var ws = wb.Sheets.Sheet1;
        var json = XLSX.utils.sheet_to_json(wb.Sheets.Sheet1);
        console.log("json", json);  

        //var json = XLSX.utils.sheet_to_json(wb.Sheets.Sheet1);
        //console.log("json", json);

        for(var a = 0; a < json.length ; a++){
                    console.log("Test_URL", json[a].Test_URL);
                    console.log("User_Name", json[a].User_Name);
                    console.log("Password", json[a].Password);
                browser.get(json[a].Test_URL); 

                //Perform Login:UserName 
                element(by.model('accessCode')).sendKeys(json[a].User_Name); 

                //Perform Login:Password 
                element(by.model('password')).sendKeys(json[a].Password); 

                //Perform Login:LoginButton 
                element(by.css('.btn.btn-primary.pull-right')).click(); 

                //Clicking on New Tab
                element(by.xpath('/html/body/div[3]/div[1]/div[17]/div/div/table[2]/thead/tr/th[1]/i')).click();

        //Clicking on Image for Logout
        element(by.css('.user-auth-img.img-circle')).click();
        browser.driver.sleep(2000)

        //Clicking on LogOut Button
        element(by.xpath('/html/body/div[3]/div[1]/div[16]/div[1]/div/div[2]/nav/div[2]/ul/li[4]/ul/li[5]/a/span')).click();
        browser.driver.sleep(2000)

        //Clicking on Ok for confirmation
        element(by.id('logout')).click();

        console.log(json[a].User_Name + "Passed the Test");

};

        })

    });
1
Can you paste your spec file code, looks like no expect in IT block.tyaga001
Yes see there is no expect statement anywhere in your IT block. You should do some expect post every action user is taking. something like expect(element(by.model('accessCode')).isDisplayed()).toBe(true); post sending text in username text box. & use expect statement after every user action basically.tyaga001
Thanks for the quick response. But I have a doubt that to generate a report my code is written in config file. The spec file is just the test case. So how can I make changes in the config file so as to get the proper result (say 100%)when the test case passed without any failures.Vinee
your conf file looks fine that's why you are able to see the report post execution. to get 100% in test case you need to add expect statement. please try to add one expect & run the test. let me know what you will see post this step in report.tyaga001
Can you please help me in what exactly I can write in my spec file i.e my test case to get the test pass status in the report. Also, I have one doubt that by writing expect in the test case how the console or Protractor will get to know that its about the report when we are declaring everything in the config file related to report.Vinee

1 Answers

0
votes

Try with below spec file it's working fine.

Results you can see Final Report

describe("basic test", function () {
  beforeAll(function () {
    console.log('beforeAll');
  });
  beforeEach(function () {
    console.log('beforeEach');
  });
  afterAll(function () {
    console.log('afterAll');
  });
  afterEach(function () {
    console.log('afterEach');
  });
  it("Test Case 1: to verify see the global functions hierarchy", function () {
    console.log('Sample Test 1');
  });
  it("Test Case 2: to verify see the global functions hierarchy", function () {
    browser.get('http://www.angularjs.org');
            element(by.model('todoText')).sendKeys('write a protractor test');
            element(by.css('[value="add"]')).click();    
            var todoList = element.all(by.repeater('todo in todos'));
            expect(todoList.count()).toEqual(3);  
    });
    it('should greet the named user', function() {
      browser.get('http://www.angularjs.org');
      element(by.model('yourName')).sendKeys('Julie');
      var greeting = element(by.binding('yourName')); 
      expect(greeting.getText()).toEqual('Hello Julie!');
    });
});