Angular Protractor e2e case 学习总结

首先附上 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

发布了69 篇原创文章 · 获赞 35 · 访问量 7万+

猜你喜欢

转载自blog.csdn.net/qyl_0316/article/details/101027146
今日推荐