量角器代码中未调用断言

时间:2018-07-04 04:17:48

标签: protractor

我是量角器的新手,正在尝试我的示例代码;但努力使断言在量角器中工作。 即使在某些情况下,元素的getText()也会返回对象数组,尽管在页面中,只有一个具有该属性的元素。

代码示例:

describe('Launch Zoo Adaption Website and Provide Text Value',function()
{
    beforeEach(async function(){
        await browser.get("http://www.thetestroom.com/jswebapp/index.html");
    });



    it('Launch Zoo Adaption Website',async function()
    {
        var some_name = 'Zoo Adoption | Home';
        some_name = browser.getTitle().then(async function(webpagetitle){
            await console.log("Title:"+webpagetitle);
        if (webpagetitle === 'Zoo Adoption | Home'){
         return 'Some Other Name';
        }
        else{
        return 'Some Name';
            }
        });
        await expect(some_name).toEqual('Some Other Name');
        //var ExpectedHomePageTitle='Zoo Adoption | Home';
        //browser.driver.sleep(3000);
        //await console.log("Actual Title:"+browser.getTitle());
        //browser.driver.sleep(3000);
        //await expect(browser.getTitle()).toEqual('Zoo Adoption | Home');
    });

    it('Provide Textfield value in Zoo Adaption HomePage',async function()
    {
        var ExpectedTextinInputField='Hello India';
        await element(by.model("person.name")).sendKeys(ExpectedTextinInputField);
        await element(by.binding("person.name")).getText().then(async function(text){
            console.log("Expected Text:"+text);
            await expect(text).toEqual(ExpectedTextinInputField);
        });
        await console.log("Actual text displayed in dynamic field:"+(element(by.binding('person.name'))).getText());
    });
});

控制台输出:

  

开始的标题:动物园采用|预期文本:你好印度实际   在动态字段中显示的文本:[对象对象]

     

     

2个规格,0个故障   在3.695秒内完成

请帮助我了解

a。为什么我的代码没有断言?

b。为什么getText()返回对象数组?

1 个答案:

答案 0 :(得分:0)

describe('Launch Zoo Adaption Website and Provide Text Value',function()
{
    beforeEach(async function(){
        await browser.get("http://www.thetestroom.com/jswebapp/index.html");
    });
    it('Launch Zoo Adaption Website',async function()
    {
       var title = browser.getTitle();
       expect(title).toEqual('Zoo Adoption | Home');
    });
it('Provide Textfield value in Zoo Adaption HomePage',async function()
    {
         var ExpectedTextinInputField='Hello India';
        await element(by.css("input[type=""]")).sendKeys(ExpectedTextinInputField);
        await element(by.class("ng-binding")).getText().then(async function(text){
            console.log("Expected Text:"+text);
            await expect(text).toEqual(ExpectedTextinInputField);
        });     
});

有关here的详细说明,请参见使用量角器创建和执行测试。