protractor_conf.js文件:

exports.config = {
    directConnect: true,
    capabilities: {
        'browserName': 'chrome',
        "chromeOptions" : {
            args: ["--window-size=2000,2000"],
        }
    },
    specs: ['test-organization.js'],     //运行的测试文件地址
    jasmineNodeOpts: {
        showColors: true,
        defaultTimeoutInterval: 30000
    },
};

  测试文件:

/**
 * Created by lifei on 2017/6/27.
 */

var name= Math.floor(Math.random()*1000011)
function loginFunc(address){       //登录
    browser.get(address);
    element(by.model("form.username")).sendKeys("admin");
    element(by.model("form.password")).sendKeys("admin");
    element(by.css("input.loginbtn")).click();
    var userName = element(by.binding("user.name")).getText();
    expect(userName).toEqual("admin");
}
function save(save){        //点击完成按钮
    element(by.cssContainingText("button",save)).click()//完成
    browser.wait(function () {
        return browser.isElementPresent(element(by.css("button.confirm")));
    }, 2000);
    element(by.css("button.confirm")).click();
}

describe("user", function(){
    beforeEach(function(){
        browser.sleep(1000);
    })
    it("login", function(){
        loginFunc("http://localhost:8004/src/#/login")
    });
    it("orization", function(){
        browser.wait(function () {
            return browser.isElementPresent(element(by.cssContainingText(".title"," 网络管理 ")));
        }, 2000);
        element(by.cssContainingText(".title"," 统一配置 ")).click();
    })
    it("create", function(){
        browser.wait(function () {
            return browser.isElementPresent(element(by.cssContainingText("button","创建用户")));
        }, 2000);
        element(by.cssContainingText("button","创建用户")).click();

        element(by.model("form.name")).sendKeys(name);           //用户名
        element(by.model("form.password")).sendKeys("1111");        //密码
        element(by.model("form.cpassword")).sendKeys("1111");       //重复密码
        element.all(by.repeater("p in projects")).get(2).click();   //选择租户
        element(by.cssContainingText("button", "编辑角色")).click();//选择角色
        browser.sleep(1000);
        element.all(by.repeater("x in roles")).get(4).click();
        element(by.cssContainingText("button", "确定")).click();
        save("提交");
        //验证
        var service = element.all(by.repeater("x in $data")).get(0).$$("a").get(0).getText();
        expect(service).toEqual("lifei")
    });

    it("edit", function() {
        browser.sleep(2000);
        element.all(by.repeater("x in $data")).get(0).$$("a").get(0).click()
        element(by.cssContainingText("button", "编辑角色")).click();//选择角色
        browser.sleep(1000);
        element.all(by.repeater("x in roles")).get(0).click();
        element(by.cssContainingText("button", "确定")).click();
        element(by.cssContainingText("button","提交")).click();
        browser.sleep(2000)
        element(by.cssContainingText("button","确定!")).click();
        browser.sleep(2000)
        element(by.cssContainingText("button","OK")).click();
        browser.sleep(2000)
        //返回
        element(by.cssContainingText("a","组织管理")).click();
        service = element.all(by.repeater("x in $data")).get(0).$$("td").get(2).getText();
        expect(service).toEqual("testtttt");
    });
    it("deleteUser", function(){
        var number = element.all(by.repeater("x in $data")).count()
         expect(number).toBe(1);
        element.all(by.repeater("x in $data")).get(3).element(by.css("button.dropdown-toggle")).click();
        element.all(by.repeater("x in $data")).get(3).element(by.cssContainingText("a","删除")).click();
        browser.sleep(2000)
        element(by.cssContainingText("button","确定!")).click();
       browser.sleep(2000)
        element(by.cssContainingText("button","OK")).click();

        var name = element.all(by.repeater("x in $data")).get(0).$$("a").get(0).getText();
        expect(name).toEqual("lifei");

    })
    afterEach(function(){
        browser.sleep(1000);
    })
})

  

posted on 2017-06-28 13:24  下辈子当座桥-李飞  阅读(561)  评论(0编辑  收藏  举报