- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我知道有很多关于此错误代码的主题。但是,我正在努力寻找任何有帮助的解决方案(或者我可能只是愚蠢)。
我正在为网页构建 Protractor 测试,我的原始 JavaScript 运行良好。但我想将其全部转换为使用页面对象,以便于编辑和理解以及避免代码重复。
我用于登录的第一个页面对象工作得很好,但是我用于添加新用户的第二个页面对象却没有。
我从中链接页面对象的主测试文档分别包含有效和无效的代码实例。
第一个有效的实例是第 12 行。
第二个不存在的实例在第 23 行。
如下所示:
var util = require('util')
describe ('This is to test the functionality of the Admin page.', function()
{
beforeEach(function(){
browser.ignoreSynchronization = true;
browser.get('https://website');
});
it ('Should log in and move to the Users page.', function() {
var login_page = require('../page/login_page.js');
var loginPage = new login_page;
loginPage.login('user', 'pass');
beforeEach(function () {
expect(browser.getCurrentUrl()).toEqual('https://website');
});
describe('This should hold all the tests while logged in to Admin site', function () {
it('Should create first new User.', function() {
var users_page = require('../page/users_page.js');
var usersPage = new login_page;
usersPage.addUserButton().click();
usersPage.addUser('Test', 'Smith', 'Test100@testing.co.nz', 'Password', 'Password', '0')
usersPage.userRole[0];
usersPage.confirm().click();
usersPage.back().click();
});
it('Should logout', function () {
element(by.cssContainingText('span', 'Logout')).element(by.linkText('Logout')).click();
});
});
});
});
我在 cmd 中运行 Protractor 测试时得到的错误是:
1) This should hold all the tests while logged in to Admin site Should create first new User.
Message:
TypeError: undefined is not a function
Stacktrace:
TypeError: undefined is not a function
at [object Object].<anonymous> (C:\\\\\\test
04_spec.js:25:27)
第一个引用的页面是:
require ('../page/users_page.js');
var login_page = function(){
this.username = element(by.id('username'));
this.password = element(by.id('password'));
this.get = function(urlVal){
browser.get(urlVal);
};
this.login = function(un, pass){
this.username.sendKeys(un);
this.password.sendKeys(pass);
element(by.tagName('button')).click();
};
};
module.exports = login_page;
而第二个实例引用的页面是:
require ('../page/users_page.js');
var users_page = function(){
this.addUserButton = element(by.css('[role="button"]'));
this.firstName = element(by.model('firstname'));
this.lastName = element(by.model('lastname'));
this.userName = element(by.model('username'));
this.password = element(by.model('password'));
this.confirmPassword = element(by.model('confirmpassword'));
this.confirm = element(by.css('[class="btn btn-success marginRight10px floatLeft"]'));
this.back = element(by.css('[class="btn floatLeft"]'));
this.addUser = function(fn, ln, un, pw, cpw){
this.firstname.sendKeys(fn);
this.lastword.sendKeys(ln);
this.username.sendKeys(un);
this.password.sendKeys(pw);
this.confirmpassword.sendKeys(cpw);
};
this.userRole = function(index){
element(by.model('tes.userRole')).$('[value="'+index+'"]').click();
};
return require('./users_page.js');
};
module.exports = new users_page();
最佳答案
至少有一个问题:addUserButton
不是函数。替换:
usersPage.addUserButton().click();
与:
usersPage.addUserButton.click();
对于 confirm
和 back
页面对象字段也是如此。
此外,代替:
usersPage.userRole[0];
您可能打算调用底层页面对象函数:
usersPage.userRole(0);
除此之外,您可能打算实例化一个新的“用户页面”对象。替换:
var usersPage = new login_page;
与:
var usersPage = new users_page;
关于javascript - '类型错误 : undefined is not a function' using Protractor,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28665841/
我只是有一个更琐碎的问题。 为什么undefined == undefined 返回true,而undefined >= undefined 为false? undefined 等于 undefine
用PHP 7.2编写套接字服务器。根据Firefox 60中的“网络”选项卡,服务器的一些HTTP响应的第一行随机变为undefined undefined undefined。因此,我尝试记录套接字
在 JavaScript 中这是真的: undefined == undefined 但这是错误的: undefined <= undefined 起初我以为<=运算符包含第一个,但我猜它试图将其转换
在回答这个问题 (Difference between [Object, Object] and Array(2)) 时,我在 JavaScript 数组中遇到了一些我以前不知道的东西(具有讽刺意味的
来自https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Array/of , Note: thi
我正在运行 PHP 脚本并继续收到如下错误: Notice: Undefined variable: my_variable_name in C:\wamp\www\mypath\index.php
我正在运行 PHP 脚本并继续收到如下错误: Notice: Undefined variable: my_variable_name in C:\wamp\www\mypath\index.php
当我添加 到我的 PrimeFaces Mobile 页面,然后我在服务器日志中收到以下警告 WARNING: JSF1064: Unable to find or serve resource, u
我正在运行 PHP 脚本并继续收到如下错误: Notice: Undefined variable: my_variable_name in C:\wamp\www\mypath\index.php
我正在运行 PHP 脚本并继续收到如下错误: Notice: Undefined variable: my_variable_name in C:\wamp\www\mypath\index.php
我正在运行 PHP 脚本并继续收到如下错误: Notice: Undefined variable: my_variable_name in C:\wamp\www\mypath\index.php
我正在运行 PHP 脚本并继续收到如下错误: Notice: Undefined variable: my_variable_name in C:\wamp\www\mypath\index.php
我正在运行 PHP 脚本并继续收到如下错误: Notice: Undefined variable: my_variable_name in C:\wamp\www\mypath\index.php
我正在运行 PHP 脚本并继续收到如下错误: Notice: Undefined variable: my_variable_name in C:\wamp\www\mypath\index.php
我正在运行 PHP 脚本并继续收到如下错误: Notice: Undefined variable: my_variable_name in C:\wamp\www\mypath\index.php
我正在运行 PHP 脚本并继续收到如下错误: Notice: Undefined variable: my_variable_name in C:\wamp\www\mypath\index.php
我正在运行 PHP 脚本并继续收到如下错误: Notice: Undefined variable: my_variable_name in C:\wamp\www\mypath\index.php
我正在运行 PHP 脚本并继续收到如下错误: Notice: Undefined variable: my_variable_name in C:\wamp\www\mypath\index.php
我正在运行 PHP 脚本并继续收到如下错误: Notice: Undefined variable: my_variable_name in C:\wamp\www\mypath\index.php
我正在运行 PHP 脚本并继续收到如下错误: Notice: Undefined variable: my_variable_name in C:\wamp\www\mypath\index.php
我是一名优秀的程序员,十分优秀!