Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/399.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
getText不是函数错误量角器(javascript)_Javascript_Selenium Webdriver_Protractor_Automated Tests - Fatal编程技术网

getText不是函数错误量角器(javascript)

getText不是函数错误量角器(javascript),javascript,selenium-webdriver,protractor,automated-tests,Javascript,Selenium Webdriver,Protractor,Automated Tests,我已经安装了node.js和量角器。我有使用selenium webdriver的经验,但量角器快把我逼疯了!!!我对javascript也不是很熟悉 这就是我的代码的样子: describe('My app', function() { var result = element(by.id('result-name')); var enterBtn = element(by.id('enter')); var clearFieldBtn = element(by.id

我已经安装了node.js和量角器。我有使用selenium webdriver的经验,但量角器快把我逼疯了!!!我对javascript也不是很熟悉

这就是我的代码的样子:

describe('My app', function() {

    var result = element(by.id('result-name'));
    var enterBtn = element(by.id('enter'));
    var clearFieldBtn = element(by.id('clear-field'); 

    it('should bring up components on load', function() {
        browser.get(`http://localhost:${process.env.PORT}`);
        browser.wait(until.titleContains('Sample App'), 500);
        browser.wait(until.presenceOf(browser.element(by.id('my-test-app'))), 500);

        expect(enterBtn).isPresent;
      });

    it('result should equal username', function () {
        browser.get(`http://localhost:${process.env.PORT}`);

        expect(clearFieldBtn).isPresent;
        expect(result.getText()).toEqual('John Smith'); //both tests pass without this line of code   

    });

});
最后一行“expect(result.getText()).toEqual('John Smith');”向我抛出了一个错误。我得到:

expect(...).toEqual is not a function
任何帮助都将不胜感激。我花了几个小时试图找到一个解决方案,并尝试了不同的事情

我还想在api文档中实现isPresent函数,如下所示:expect($('.item').isPresent()).toBeTruthy()

我试着做:

expect(clearFieldBtn).isPresent().toBeTruthy();

但我知道iPresent不是一个函数

这条线以上的预期似乎很糟糕。应该是

expect(clearFieldBtn.isPresent()).toBeTruthy();

我不确定这是否会导致下面这行出现奇怪的错误…我只是想我会把它扔出去。所有量角器API都需要在expect中调用,因为
isPresent
不是
expect

的属性。您是否尝试过以下几行:

    clearFieldBtn.isPresent().then(function(bln) {
         expect(bln).toBe(true);
    });

    result.getText().then(function(tmpText) {
         expect(tmpText).toBe('John Smith');
    });

如果在result.getText()上仍然出现错误,请检查result对象是否存在。

还注意到您的
clearFieldBtn
元素缺少一个括号如果您只是在自己的it块中运行
expect(true)。toBeTruthy()
,您会得到什么,听起来你甚至没有安装Jasmine如果你不能访问这些功能Protractor只是一个测试框架,你需要一个测试库来配合它
getText
和量角器函数都很好,但您需要一个库(jasmine)来使用
toEqual
来保存
等。量角器默认使用jasmine,但您应该在配置中声明一个,即
框架:“jasmine”
,我猜
descripe
it
也来自jasmine,所以这可能不是问题所在,因为它们不会抛出错误。。。。这是一个奇怪的问题。你的标题有误导性。问题/错误不是关于
getText()
,而是关于您的jasmine函数
toEqual
toContain
等。您也可以发布您的配置,您使用的是什么测试库?