Angular Protractor e2e case 学习总结

本文详细介绍了使用Protractor进行端到端(e2e)测试的方法,包括配置项目、编写测试用例及解决常见问题的技巧。通过具体案例,展示了如何利用Protractor的API进行页面元素定位、操作及断言验证。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

首先附上 Protractor 的学习网址:http://www.protractortest.org/#/ 里面有一些学习的API和如何配置项目e2e Test.

命名:Eg:welcome-to-angular-protractor-test.e2e-spec.ts // 具体的case实例

hello-angular-protractor.po.ts //集中放置angular 类,元素定位,方法,实例

举个例子:welcome-to-angular-protractor-test.e2e-spec.ts

import { browser, by, element } from 'protractor';  //按需导入proctractor需要的实例对象

import { HelloWorld } from '../../angular-test/hello-world.po';  // 导入其他所需实例

import { Timeouts } from '../../shared/protractor-utils/test-utils'; // 导入工具类超时处理对象

describe('This case to test and verify the form content right', async () => {

const helloAngularProtractorTest = new HelloAngularProtractorTest();

const PAGE_PAGE_URL = '/#/hello-world/form-table';

//一些钩子函数

beforeAll(async () => {

await browser.get(SUPPLIER_DISQUALIFICATION_URL);

});

beforeEach(async () => {});

afterEach(async () => {});

// Test case instance,一个it 就是一个测试的最小单元,而一个descirbe就是若干个it的集合

it('Verify form data is validate', async => {

await(element(by.linkText('hello'))).click();

expect(element(by.css('span.section-text.selected')).getAttribute('color')).toBe('rgb(10, 110, 209)');

expect(element(by.css('div.hello-header')).getText()).toBe('hello');

expect(await browser.getCurrentUrl()).toContain('/hello');

expect(element(by.css('div.hello')).getText()).toContain('hellworld');

expect(element.all(by.css('.value-container > div > span.text')).getText()).toBe('hello');

 

await element.all(by.css('i.material-icons.search-icon')).get(2).click();

expect(await element(by.css('i.row-middle-icon.row-vertical-icon')).isPresent()).toBe(true);

element(by.xpath('//*[@id="hello-angular-protractor-case"]/div/div[2]/button/span/span'));

$$('mat-checkbox-layout');

});

});

hello-world.po.ts

public async clickViewIcon() {

        await this.scrollIntoView(this.viewDetailIcon);

        await this.viewDetailIcon.click();

    }

    public async clickEditButton() {

        await this.scrollIntoView(this.editButton);

        await this.editButton.click();

    }

 

Issues:

点击一个按钮本地路由的跳转无法模拟,有些页面元素获取不到,本地master-data.service.ts 文件的配置,连续状态的数据的获取,即有start->doing->pending->complete这些连续状态的数据的本地获取,然后来模拟去test

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值