【问题标题】:Protractor-Jasmine2-HTML-Report量角器-Jasmine2-HTML-报告
【发布时间】:2018-01-12 18:26:58
【问题描述】:

我正在使用 Protractor 中的报告执行部分并使用 Jasmine2 Html Reporter。我能够生成报告,但是当我的测试完全通过而没有任何失败时,报告仍然显示状态为 0.00%。我不确定为什么会这样。我还附上快照以供参考。

代码是:

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

规范代码为:

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

};

        })

    });

【问题讨论】:

  • 你能粘贴你的规范文件代码吗,看起来不像 IT 块中的预期。
  • 是的,您的 IT 块中没有任何期望语句。你应该做一些期望发布用户正在执行的每个操作。类似expect(element(by.model('accessCode')).isDisplayed()).toBe(true);在用户名文本框中发布发送文本。 & 基本上在每个用户操作后使用 expect 语句。
  • 感谢您的快速回复。但我怀疑要生成报告,我的代码是写在配置文件中的。规范文件只是测试用例。那么如何在配置文件中进行更改,以便在测试用例通过且没有任何失败的情况下获得正确的结果(比如 100%)。
  • 您的 conf 文件看起来不错,这就是您能够在执行后看到报告的原因。要在测试用例中获得 100%,您需要添加期望语句。请尝试添加一个期望并运行测试。让我知道在报告中发布此步骤后您会看到什么。
  • 你能帮我看看我可以在我的规范文件中写什么,即我的测试用例,以便在报告中获得测试通过状态。另外,我怀疑通过在测试用例中编写期望,当我们在配置文件中声明与报告相关的所有内容时,控制台或量角器将如何知道它与报告有关。

标签: protractor


【解决方案1】:

尝试使用以下规范文件,它工作正常。

你可以看到的结果

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!');
    });
});

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-05-18
    • 2015-10-23
    • 2019-03-28
    • 1970-01-01
    • 2014-09-26
    • 1970-01-01
    • 2015-06-22
    • 2018-05-08
    相关资源
    最近更新 更多