“失败:无法读取未定义的属性‘isPresent’" [英] "Failed: Cannot read property 'isPresent' of undefined"

查看:53
本文介绍了“失败:无法读取未定义的属性‘isPresent’"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

it('should be able to create a task for a product as a CTA', function () {
  browser.sleep(6222);browser.sleep(6222);console.log("ss");
  productPage.productsTab.click();
  expect(productPage.myProductsTab.isDisplayed()).toBeTruthy();

  //select checkbox
  productPage.selectProduct.click();
  browser.sleep(2222);
  var elm = productDialogPage.createTaskButton;

  var EC = protractor.ExpectedConditions;

  //get count of checked checkboxes, count must 1 be because it selected one product
  var checkedCount = productPage.selectedProducts.count();
  expect(checkedCount).toBe(1);
  browser.sleep(2222);

  browser.wait(EC.elementToBeClickable(elm, 6222));

  //click task create and expect confirm dialog to be displyed
  productDialogPage.createTaskButton.click();
  expect(ProductDialogPage.confirmDialog.isDisplayed()).toBe(true);
  browser.sleep(2222);

  //click yes to confirm creating task and expext dialog to displayed
  productDialogPage.yesBtnForConfirmDialog.click();
  //expect(taskPageObject.taskDialog.isDisplayed()).toBe(true);
  browser.sleep(6222);

  //put input areas to task create dialog
  this.createTask();
  browser.sleep(2222);

这是我的测试

var elm = productDialogPage.createTaskButton;

var EC = protractor.ExpectedConditions;

//get count of checked checkboxes, count must 1 be because it selected one product
var checkedCount = productPage.selectedProducts.count();
expect(checkedCount).toBe(1);
browser.sleep(2222);

browser.wait(EC.elementToBeClickable(elm, 6222));

//click task create and expect confirm dialog to be displyed
productDialogPage.createTaskButton.click();
expect(ProductDialogPage.confirmDialog.isDisplayed()).toBe(true);
browser.sleep(2222);

这里是部分

count 为 1 后,表示我只选择了一种产品(md-checkbox),这表示选择了产品,因此按钮现在处于活动状态.禁用前

after count is 1, it means i selected only one product (md-checbox), it means product is selected so that button is active now. Before it was disabled

 disabled="disabled"

它有.当我选择时,它就消失了.

it has that. when i select, this is gone.

但是一旦它进入我的测试或我的课程页面,它就会出错.它不运行代码,因为它不等待.

But as soon as it enters my test or my class page, it gives error. it does not run code because it does not wait.

它会导致失败.

我使用了 isvisible ispresentof 但还是一样

i used isvisible ispresentof but still same

错误是针对此代码,失败:无法读取未定义的属性‘isPresent’"

error is for this code, "Failed: Cannot read property 'isPresent' of undefined"

但是我没有ispresent

but i dont have ispresent

之前我只有 2 个类,现在我根据对话框和选项卡分离类,这个错误现在开始了.

before i had 2 classes only, now i separated classes according to dialog and tabs, this error started now.

我可以看到ss"作为输出但是

i can see "ss" as output but

browser.sleep(6222);console.log("ss");

有 6 秒的睡眠时间.它不会去那里.它检查我之前认为的所有变量.

there is sleeping 6 seconds. İt does not go there. it checks i think all variables before.

更新

代替 productdialog.confirmdialog

ınstead productdialog.confirmdialog

我把真正的价值放在

element.all(by.buttonText('Görev Oluştur')).first()element.all(by.buttonText('Görev Oluştur')).first()

它有效.

为什么?

它在这里,仍然在这里,但现在没有使用

it was here, still here but no usage now

var ProductDialogPage = function () {
  //confirm dialog for task creating, use with isDisplayed
  this.confirmDialog = element.all(by.css('._md.md-default-theme._md-transition-in')).first();

  this.yesBtnForConfirmDialog = element.all(by.buttonText('Evet')).first();
};

推荐答案

productDialogPage 页面对象中没有定义 createTaskButton 字段.

There is no createTaskButton field defined in your productDialogPage page object.

您收到此类错误是因为 >elementToBeClickable 预期条件 函数检查元素是否可见、存在和启用调用 isPresent()isEnabled() 在元素上.这是相关代码最终抛出的地方:

You are getting this kind of error because the elementToBeClickable expected condition function checks if an element is visible, present and enabled calling isPresent() and isEnabled() on an element. This is related code where the error is eventually thrown:

presenceOf(elementFinder: ElementFinder): Function {
  return elementFinder.isPresent.bind(elementFinder);
};    

您正在将 elm 变量传递给预期条件:

You are passing elm variable to the expected condition:

browser.wait(EC.elementToBeClickable(elm, 6222));

其中 elm 定义为:

var elm = productDialogPage.createTaskButton;

而且,根据症状判断,elm 得到一个 undefined 值,这意味着 productDialogPage 中没有 createTaskButton 字段 页面对象.

And, judging by the symptoms, elm gets an undefined value which means that there is no createTaskButton field in the productDialogPage Page Object.

这篇关于“失败:无法读取未定义的属性‘isPresent’"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆