量角器测试用例 [英] Protractor Test cases
问题描述
我是新来量角器端到端测试。我已经写了我的第一次测试code ..我想知道您的反馈和我的方法可以改善它。
I am new to protractor e2e testing. and i have written my first test code.. I would like to know your feedback and ways i can improve it.
describe("Map feedback Automation",function(){
it("Check if the Url works ",function()
{
browser.get(browser.params.url);
expect(browser.getCurrentUrl()).toContain("report");
});it("test browser should reach report road option",function()
{
element.all(by.css('div[ng-click="setLocation(\'report_road\')"]')).click();
expect(browser.getCurrentUrl()).toContain("report_road");
});
it("test browser should reach report road missing",function()
{
element.all(by.css('div[ ng-click="mapFeedBack.editObject= mapFeedBack.createMapObjectModel();setLocation(mapFeedBack.noMap?\'road_new\':\'choose_location_road_new/road_new\')"]')).click();
expect(browser.getCurrentUrl()).toContain("choose_location_road_new/road_new");
browser.sleep(browser.params.sleeptime);
});
it("test browser should zoom on map ",function() //manual
{
element.all(by.css('div[ng-click="zoomIn()"]')).click();
browser.sleep(browser.params.sleeptime);
element.all(by.css('div[ng-click="zoomIn()"]')).click();
browser.sleep(browser.params.sleeptime);
element.all(by.css('div[ng-click="zoomIn()"]')).click();
browser.sleep(browser.params.sleeptime);
element.all(by.css('div[ng-click="zoomIn()"]')).click();
browser.sleep(browser.params.sleeptime);
});
it("Should click on ok option",function()
{
element(by.buttonText('OK')).click();
expect(browser.getCurrentUrl()).toContain("road_new");
});
it("test browser should reach report road option",function()
{
browser.sleep(browser.params.sleeptime);
expect(browser.getCurrentUrl()).toContain("road_new");
});
it("should enter a road name",function()
{
browser.sleep(browser.params.sleeptime);
var testroadname = browser.params.testroadname;
element(by.model("mapFeedBack.editObject.roadName")).sendKeys(testroadname);
browser.sleep(browser.params.sleeptime);
});
it("should check the type of road is highway",function() //spec3
{
element(by.model("mapFeedBack.editObject[attrs.select].selected")).$("[value='string:app.road.roadType.highway']").click();
});
it("should submmit the map feedback",function()
{
element(by.css('button[ng-click="onSubmit({reportType: reportType})"]')).click();
browser.sleep(browser.params.sleeptime);
});});
我的一个同事告诉我,除去延迟
A colleague of mine told me to remove the delay
browser.sleep(browser.params.sleeptime);
和点击按钮,在变焦时添加一些事件。你可以建议我的方法,我能实现吗?
and add some event when the zoom in button is clicked. can you suggest me the ways i can achieve it?
推荐答案
正如他们所说,每个code有它自己的闻。一个接量角器专用code产生的气味最严重的是使用 browser.sleep()
的解决时序问题。 browser.sleep()
调用通常正在测试远远低于它是需要偶尔不添加延时足以使一个测试通过制作的作者code增加睡眠延迟,再次进行测试更慢。而且,顺便说一句,有一个相关的第三方的 ESLint
规则,这将有助于prevent您不必 browser.sleep()
在端到端codeBase的。
As they say, every code has it's own smell. One the worst smells produced by Protractor-specific code is the use of browser.sleep()
to tackle timing issues. browser.sleep()
calls usually are making the tests much slower than it is needed and occasionally don't add enough of a delay to make a test pass making the author of the code increase the sleep delay which again makes a test even more slower. And, by the way, there is a related third-party ESLint
rule that would help to prevent you from having browser.sleep()
in the e2e codebase.
要不好受code延迟更可靠的替代方法,就是使用的 browser.wait()
和一组内置的预计细则。这里的主要优点是的 browser.wait()
只要将等待,因为它是必要的的不断检查预期条件的状态。
A more robust alternative to having a hardcode delay, is to use browser.wait()
and a set of built-in Expected Conditions. The main advantage here is that browser.wait()
would wait as long as it is necessary continuously checking the state of the expected condition.
例如,你的情况,你可以让世界变得更美好通过做测试自动化 elementToBeClickable
状态:
For example, in your case, you might make the world a better place to do test automation by using elementToBeClickable
condition:
var EC = protractor.ExpectedConditions;
var elm = element(by.id("myid"));
browser.wait(EC.elementToBeClickable(elm), 10000);
elm.click();
在这里,量角器
将等待的最多的(高达
真的是什么使差),10秒钟(是的,你还需要一个超时值),将提高超时异常,如果该元素不会成为点击。
Here, Protractor
would wait up to (up to
is really what makes the difference) 10 seconds (yes, you still need a timeout value) and would raise a Timeout Exception if the element would not become clickable.
这篇关于量角器测试用例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!