代码之家  ›  专栏  ›  技术社区  ›  nhrcpt

在用于web测试的循环量角器中执行多个IT块

  •  1
  • nhrcpt  · 技术社区  · 7 年前

    require('..\\waitAbsent.js');
    require("../node_modules/jasmine-expect/index.js");
    var EC = protractor.ExpectedConditions;
    
    describe('Student Enrollment Page Content Validation', function() {
    
    
    beforeAll(function () {
        browser.driver.manage().window().maximize();
        browser.get(globalVariables.loginMain);
        globalVariables.Email_Input_box.sendKeys(globalVariables.Demo_User);
        globalVariables.Password_Input_Box.sendKeys(globalVariables.Demo_PWD);
        globalVariables.Submit_Button.click();
        browser.wait(EC.invisibilityOf(globalVariables.Submit_Button), 25000, 'submit button is not disappearing yet');
    });
    
    async function Row_Numbers() {
    
        const RowCount = (globalVariables.tableData_Dashboard.all(by.tagName("tr")).count()).then(function(RC){
    
            return RC;
    
        });
    
    }
    
    for (var i = 1; i<Row_Numbers(); i++){
    
        function tableData(n){
            var row_1 = globalVariables.tableData_Dashboard.all(by.tagName("tr")).get(n);
    
            // get cell values
            var cells = row_1.all(by.tagName("td"));
    
            it ('should return the data fo the first cell', function(){
                var Student_ID = cells.get(0).getText().then(function (SID) {
                    console.log(SID);
    
                    return SID;
    
                });
    
                expect(Student_ID.toEqual('Something'));
            });
    
            it ("should show the button in this row", async function(){
    
                const Button = globalVariables['Edit_Button_' + n];
                // console.log(Button)
                expect(await Button.isDisplayed());
                Button.click();
                // do some thing
    
            });
        }tableData(i)
    }
    
    });
    

    E/launcher-等待量角器与页面同步时出错:“angularJS可测试性和角度可测性都未定义。这可能是因为这是一个没有角度的页面,或者因为你的测试涉及 的客户端导航,这可能会干扰量角器的引导。看到了吗 https://github.com/angular/protractor/issues/2643 了解详情”

    如何使用for循环来实现目标?

    1 回复  |  直到 7 年前
        1
  •  1
  •   DublinDev    7 年前

    我对此有几点看法。

    下一步应该不需要tableData函数,因为它似乎用循环中的i counter替换它的参数n会产生相同的效果。

    最后,如果您的代码需要跨越多个页面来实现这些测试,那么最好使用数据驱动的方法并为每个测试编写单独的数据文件。这些表行的值是改变了还是保持一致?

    这种方法可能看起来像这样,但我还没有测试过。

    beforeAll(function () {
        browser.driver.manage().window().maximize();
        browser.get(globalVariables.loginMain);
        globalVariables.Email_Input_box.sendKeys(globalVariables.Demo_User);
        globalVariables.Password_Input_Box.sendKeys(globalVariables.Demo_PWD);
        globalVariables.Submit_Button.click();
        browser.wait(EC.invisibilityOf(globalVariables.Submit_Button), 25000, 'submit button is not disappearing yet');
    });
    
    it('test it', async () => {
        globalVariables.tableData_Dashboard.all(by.tagName("tr")).forEach((row) => {
            var cells = row.all(by.tagName("td"));
    
            var Student_ID = cells.get(0).getText().then(function (SID) {
                console.log(SID);
                return SID;
            });
    
            expect(Student_ID.toEqual('Something'), 'should return the data fo the first cell');
    
            const Button = globalVariables['Edit_Button_' + n];
            // console.log(Button)
            expect(Button.isDisplayed(), 'should show the button in this row').toBe(true);
            Button.click();
            // do some thing
    
        });
    })