티스토리 뷰

Yes it is fine to be using multiple types of waiting, I use implicit waits 95% of the time but need to use explicit waits for some conditions. If you app is fully Angular and properly synchronizes (i.e. no outstanding $http calls - more info) you shouldn't need too many waits as Protractor tends to know when Angular/your app is ready. However I don't know your app and this could very well not be true for your case, I'll give a few thoughts on the topic:

Implicit: These are your best bet, for both consistency and stability. I would challenge you and say most of your wait problems could probably be resolved with a proper use of Implicit waits (stronger use cases, compounded across multiple conditions etc). But again, I don't know your app, I think it's worth revisiting though. You can review the list here, the ones I frequently use are presenceOf(), visibilityOf() and their counterparts stalenessOf() and invisibilityOf().

Explicit: I try very hard to avoid these, however I have found it necessary in some cases. Such as an animation occurring over a few seconds and there is nothing to track with an implicit wait. I have created a few methods of my own to try and capture these scenarios and use a more implicit wait approach, such as the one below:

// wait for an attribute to be present i.e. "ng-invalid" to be added to a class
// el = element, attr = attribute to check (i.e. class, id etc), target = attribute value to look for
Util.prototype.waitForAttributePresent = function (el, attr, target, time) {
    var timeout = time || 0;
        return browser.wait(function () {
                return el.getAttribute(attr).then(function (val) {
                            return ~val.indexOf(target) < 0;
                                    });
                                        }, timeout);
                                        };
                                        

Use case:

// waits 5 seconds for the elements class to contain "active"
var el = $('div');
Util.waitForAttributePresent(el, 'class', 'active', 5000);
expect(true).toBe(true); 

Static: Not sure what you mean by static, that sounds the same as an explicit wait. You are stopping it for a set amount of time, not based on any conditions.

-------------------

Perhaps sharing more details about why the implicit waits were not working would enable the community to help you more technically speaking.

The short answer to your question is that it is correct to use both types of waits (not sure what is the difference between "Explicit" and "Static), depending on the SUT, your goals for automation, your project priorities and your technical knowledge.

명시 적 대기가 사용되었지만보다 효율적인 암시 적 대기를 구현하는 방법이있는 경우를 많이 보았습니다. 그러나 때때로 그렇게하려는 노력이 이점보다 중요하므로 항상 "큰 성과"를 먼저 추구합니다. 암시 적으로 대기하는 방법을 파악하면 실행 시간이 가장 많이 절약되거나 실행 안정성이 향상됩니다. 일반적으로 해당 영역이 어디에 있는지 확인하려면 먼저 일부 분석 작업이 필요합니다.

주목해야 할 또 다른 점은 대부분의 경우 실행 안정성이 실행 시간보다 중요하다는 것입니다. 명시 적 대기를 사용하여 더 안정적인 테스트를 수행하면 명시 적으로 대기하는 것이 절대적으로 유효합니다. 안정성을 유지하면서 대기 시간을 줄이는 방법을 찾기 위해 최적화 라운드 중에 나중에 언제든지 이러한 사례로 돌아올 수 있습니다.

테스트 자동화에 접근하는 순서는 다음과 같습니다.

  1. 작동하는 테스트 작성
  2. 테스트 안정화
  3. 최적화

1 단계와 2 단계는 필수 사항이지만 3 단계는 필수 사항이 아니며 프로젝트 우선 순위에 따라 다릅니다. 예를 들어 기존 테스트를 최적화하는 것보다 새 테스트를 추가하는 것이 더 중요 할 수 있습니다. 반면에 실행 시간이 매우 길어 CI 시스템이 제공하는 이점이 저하 될 수 있습니다. 이러한 경우 기존 테스트를 최적화하는 것이 더 중요 할 수 있습니다.

마지막으로, 명시 적 대기와 암시 적 대기를 혼합하지 않는 것이 좋습니다. 참조 -http://docs.seleniumhq.org/docs/04_webdriver_advanced.jsp#explicit-and-implicit-waits

암시 적 대기와 명시 적 대기를 함께 사용하면 예기치 않은 대기 시간이 발생합니다.

Selenium doc의 암시 적 및 명시 적 대기 혼합 원인에 대한 설명



출처
https://stackoverflow.com/questions/39970039
댓글
공지사항
Total
Today
Yesterday
«   2024/05   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31