我正在使用Protractor 3.1.1和Angular2运行一个简单的HelloWorld示例,但这件事一直告诉我无法找到元素的可测试性.我在网上搜索了有关错误的一些信息,但没有运气,这似乎是一个新的例外,没有那么多人面临过.
这是我正在使用的组件:
import {Component} from 'angular2/core';
@Component({
selector: 'my-app',
template: '<h1>My First Angular 2 App</h1>' +
'<h2>{{myName}}</h2>' +
'<input id="someId" [(ngModel)]="myName"/>'
})
export class AppComponent {
myName = 'Joe';
}
Run Code Online (Sandbox Code Playgroud)
这是Protractor配置文件:
exports.config = {
framework: 'jasmine',
seleniumAddress: 'http://localhost:4444/wd/hub',
specs: [
'e2e/*.js'
],
baseUrl: 'http://localhost:3000'
};
Run Code Online (Sandbox Code Playgroud)
这是我正在运行的量角器场景:
describe('angularjs homepage', function() {
it('should say my name', function() {
browser.get('/index.html');
var greeting = element(by.id('someId'));
expect(greeting.getAttribute('value')).toEqual('Joe');
});
});
Run Code Online (Sandbox Code Playgroud)
网页正常加载模板HTML,但是Protractor认为生成的网页不是Angular网页,现在,为什么呢?显然,如果我检查生成的网页,它只是处理过的Angular代码的结果HTML,我做错了吗?
这是完整的错误:
Error: Failed: Error while waiting for Protractor to sync with the …
Run Code Online (Sandbox Code Playgroud) 在MdDialog的md-dialog-actions块中,是否可以对齐左边的按钮,而右边有两个按钮?
这里有一个plnkr的一些东西,我想要做的事.比如说,在第一个模态中,如何分离是和否按钮?(参见common-model.component.ts文件)(这个plnkr还有其他一些问题,我还在研究它.但它不涉及这个问题.)
import { Component } from '@angular/core';
import { MdDialogRef } from "@angular/material";
@Component({
selector: 'common-modal',
template: `
<h2 md-dialog-title id="modal-title">{{ title }}</h2>
<md-dialog-content>
<p class="dialog-body" id="modal-message">{{ message }}</p>
</md-dialog-content>
<md-dialog-actions align="right">
<button md-raised-button
md-dialog-close
id="modal-close-btn">
{{ buttonOptions.closeText }}
</button>
<button md-raised-button
*ngIf="buttonOptions.enableNext"
id="modal-next-button"
(click)="dialogRef.close(true)">
{{ buttonOptions?.nextText }}
</button>
</md-dialog-actions>`,
})
export class CommonModalComponent {
/**
* {string} The text for the header or title of the dialog.
*/
title: string;
/**
* {string} The text for …
Run Code Online (Sandbox Code Playgroud) 是否有可能只从父元素获取文本而不是Selenium中的子元素?
示例:假设我有以下代码:
<div class="linksSection>
<a href="https://www.google.com/" id="google">Google Link
<span class="helpText">This link will take you to Google's home page.</span>
</a>
...
</div>
Run Code Online (Sandbox Code Playgroud)
在C#(或任何语言)中,我将:
string linktext = driver.FindElement(By.CssSelector(".linksSection > a#google")).Text;
Assert.AreEqual(linkText, "Google Link", "Google Link fails text test.");
Run Code Online (Sandbox Code Playgroud)
但是,linktext将具有"谷歌链接此链接将带您到谷歌的主页."
没有做一堆字符串操作(比如获取所有子节点的文本并从父节点的结果文本中减去它),有没有办法从父元素中获取文本?
我正在使用剧作家nodejs。我自己编写了一个动态选择器函数来选择数据表上的页码按钮。
pageNumberButton(page, table_id, page_number) {
page.locator(`[aria-controls=${table_id}]`, {hasText: page_number});
}
Run Code Online (Sandbox Code Playgroud)
我也尝试过:
pageNumberButton(page, table_id, page_number) {
page.locator(`[aria-controls=${table_id}] text=${page_number}`);
}
Run Code Online (Sandbox Code Playgroud)
但是,我似乎无法使其完全匹配。
假设我的数据表有 13 页:
我希望单击第 1 页。因此我发出以下命令:await pageNumberButton(page, "resultsTable", "1").click();
但我收到严格模式错误,因为有两个结果:1 和 13。
动态创建这个小选择器以便我可以对按钮进行精确匹配的最佳或好的方法是什么?
我做了一些搜索,但我要么没有问正确的问题,要么没有正确记住.在任何情况下,在Java中,我想知道是否可以将超类对象作为参数传递给子类,以及将该对象的数据提供给类的超类的最有效方法.
代码示例:
public class superclass {
String myparm1;
String myParm2;
int myParmN;
public superclass(String p1, String p2, int pn)
{
this.myparm1 = p1;
this.myparm2 = p2;
this.myParmN = pn;
}
// other methods here
}
public class subclass extends superclass {
double b1;
double b2;
public subclass(superclass sc, double b1, double b2) {
// easy way to make sc data available to this class?
// Do I create a copy or clone method, or some other way?
// calling super(sc); …
Run Code Online (Sandbox Code Playgroud) 在试图弄清楚如何使某些茉莉花期望语句依赖于先前的期望声明时,我发现在Jasmine 2.3.0之前,没有办法.(请参阅第一次预期失败后停止茉莉花测试)但是,Jasmine 2.3.0添加了一个选项stopSpecOnExpectationFailure
,当设置为true时将停止第一次失败的测试.
对此前景感到兴奋,我修改了我的conf.js以包含选项:
/*
* conf.js
*/
exports.config = {
framework: 'jasmine',
specs: ['search-spec.js'],
useAllAngular2AppRoots: true,
jasmineNodeOpts: {
stopSpecOnExpectationFailure: true
}
};
Run Code Online (Sandbox Code Playgroud)
但这对我不起作用.
在我的测试中,我有:
/**
* Test option from select element is selected
*/
function verifyOptionSelected(option) {
var myEl = $('select[value="' + option + '"]';
expect(myEl.isPresent()).toBe(true, 'Option, ' + option + ', is not a value in the dropdown list. (It might be the text.)');
expect(myEl.isSelected()).toBe(true, 'Option, ' + option + ', is not selected …
Run Code Online (Sandbox Code Playgroud) 是否可以通过路由器发送复杂对象?这是我正在做的和尝试做的事情:
在搜索页面中,用户可以单击其中一个结果上的按钮,该结果调用导致此行触发的方法. this.router.navigate(['profile-detail', selection]);
该selection
物体看起来像这样只是导航之前.
{
profile: {
id: number,
fname: string,
lname: string
},
contact: {
type: string,
address: string
},
books: [{
title: string,
author: string
}]
}
Run Code Online (Sandbox Code Playgroud)
但是,当我们到达profile-detail页面时,将this.route.snapshot.params
其作为实际数据:
{
profile: "[object Object]",
contact: "[object Object]",
books: "[object Object]"
}
Run Code Online (Sandbox Code Playgroud) 所以我正在尝试使用MdDialog来显示错误消息.不幸的是,它似乎不是一个弹出窗口,而是作为页面底部的一个块.
我需要查看或更改以使其正常工作?
代码如下
共modal.component.html
<h2 md-dialog-title>{{ title }}</h2>
<md-dialog-content>
<p>{{ message }}</p>
</md-dialog-content>
<md-dialog-actions align="right">
<button md-raised-button md-dialog-close>{{ closeText }}</button>
<button md-raised-button *ngIf="enableNext" id="sm-next-button"
(click)="dialogRef.close(true)">{{ nextText }}</button>
</md-dialog-actions>
Run Code Online (Sandbox Code Playgroud)
共modal.component.ts
import { Component } from '@angular/core';
import { MdDialogRef } from "@angular/material";
@Component({
selector: 'common-modal',
templateUrl: 'common-modal.component.html',
styleUrls: [ '../modal.component.scss']
})
export class CommonModalComponent {
/**
* The text for the header or title of the dialog.
*/
title: string;
/**
* The text for the body or content of the …
Run Code Online (Sandbox Code Playgroud) 我正在使用页面对象模型来开发剧作家的自动化测试。因此,我正在构建一个类来保存我的定位器并公开定位器,但不一定是使用的选择器。定位器是否有办法共享其选择器?
exports.MyWebPageModel = class MyWebPageModel {
constructor(page) {
this.myMultiSelect = page.locator('#select-group select');
this.submitButton = page.locator('#submit-btn');
}
}
Run Code Online (Sandbox Code Playgroud)
test('validate multi-select submission', ({page}) -> {
const myPage = new MyWebPageModel(page);
const selectChoices = ['choice1', 'choice2', 'choice4'];
await myPage.myMultiSelect.selectOptions(selectedChoices);
Promise.all([
page.waitForNavigation(),
myPage.submitButton.click()
]);
/* do tests on new page, click it's back button to return to previous page */
const allSelectedValues = await page.$eval(myPage.myMultiSelect.???, e => Array.from(e.selectedOptions).map(option => option.value)); // get the selected options from select element
expect(allSelectedValues).toEqual(selectedChoices); // verify the selected options …
Run Code Online (Sandbox Code Playgroud) 我正在使用角 2.3。而且,是的,我已经看到了六个左右的其他类似问题,但我无法在其中任何一个中找到解决我问题的答案。
我有一个名为 LabelSpanComponent 的组件:
// label-span.component.ts
import {Component, Input} from "@angular/core";
import {LabelSpan} from "../models/label-span";
@Component({
selector: 'label-span',
template: `
<label *ngIf="entry.labelValue">{{entry.labelValue}} </label>
<span>{{entry.spanValue}}</span>`
})
export class LabelSpanComponent {
@Input() entry: LabelSpan
}
Run Code Online (Sandbox Code Playgroud)
标签跨度是:
// label-span.ts
export interface LabelSpan {
labelValue: string,
spanValue: string
}
Run Code Online (Sandbox Code Playgroud)
当我在页面上使用它时,这很好用。但是当我尝试在两个不同的页面中使用它时,每个页面都有自己的模块,我收到了一个来自 angular 的错误:
类型 LabelSpanComponent 是 2 个模块声明的一部分:ThisDetailModule 和 ThatDetailModule!请考虑将 LabelSpanComponent 移至导入 ThisDetailModule 和 ThatDetailModule 的更高模块。您还可以创建一个新的 NgModule 来导出并包含 LabelSpanComponent,然后在 ThisDetailModule 和 ThatDetailModule 中导入该 NgModule。
所以,我决定我应该为 LabelSpanComponent 创建一个模块:
// label-span.module.ts
import {NgModule} from "@angular/core";
import …
Run Code Online (Sandbox Code Playgroud) angular ×5
javascript ×3
playwright ×2
protractor ×2
automation ×1
c# ×1
inheritance ×1
jasmine ×1
jasmine-node ×1
java ×1
selenium ×1