<tfoot id='AgLwB'></tfoot>

  1. <small id='AgLwB'></small><noframes id='AgLwB'>

    <i id='AgLwB'><tr id='AgLwB'><dt id='AgLwB'><q id='AgLwB'><span id='AgLwB'><b id='AgLwB'><form id='AgLwB'><ins id='AgLwB'></ins><ul id='AgLwB'></ul><sub id='AgLwB'></sub></form><legend id='AgLwB'></legend><bdo id='AgLwB'><pre id='AgLwB'><center id='AgLwB'></center></pre></bdo></b><th id='AgLwB'></th></span></q></dt></tr></i><div id='AgLwB'><tfoot id='AgLwB'></tfoot><dl id='AgLwB'><fieldset id='AgLwB'></fieldset></dl></div>

  2. <legend id='AgLwB'><style id='AgLwB'><dir id='AgLwB'><q id='AgLwB'></q></dir></style></legend>

      • <bdo id='AgLwB'></bdo><ul id='AgLwB'></ul>

      断言元素被聚焦

      Asserting an element is focused(断言元素被聚焦)
    1. <small id='Ix93h'></small><noframes id='Ix93h'>

          <bdo id='Ix93h'></bdo><ul id='Ix93h'></ul>

            <tbody id='Ix93h'></tbody>
          • <i id='Ix93h'><tr id='Ix93h'><dt id='Ix93h'><q id='Ix93h'><span id='Ix93h'><b id='Ix93h'><form id='Ix93h'><ins id='Ix93h'></ins><ul id='Ix93h'></ul><sub id='Ix93h'></sub></form><legend id='Ix93h'></legend><bdo id='Ix93h'><pre id='Ix93h'><center id='Ix93h'></center></pre></bdo></b><th id='Ix93h'></th></span></q></dt></tr></i><div id='Ix93h'><tfoot id='Ix93h'></tfoot><dl id='Ix93h'><fieldset id='Ix93h'></fieldset></dl></div>
              <tfoot id='Ix93h'></tfoot>

              1. <legend id='Ix93h'><style id='Ix93h'><dir id='Ix93h'><q id='Ix93h'></q></dir></style></legend>
                本文介绍了断言元素被聚焦的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                根据我如何断言一个元素是有焦点的? 线程,您可以通过切换到 activeElement() 来检查元素是否获得焦点,并断言这是您期望获得焦点的同一元素:

                According to the How do I assert an element is focused? thread, you can check if an element is focused by switching to an activeElement() and assert this is the same element you've expected to have the focus:

                expect(page.element.getAttribute('id')).toEqual(browser.driver.switchTo().activeElement().getAttribute('id'));
                

                在我的例子中,当前聚焦的元素没有id属性.

                In my case, the currently focused element does not have an id attribute.

                我应该怎么做而不是检查 id?

                What should I do instead of checking an id?

                奖励问题:此外,正如您从我尝试解决它的尝试中看到的那样,看起来我不能期望/断言一个元素(或 Web 元素)作为一个完整的对象.为什么?

                Bonus question: Also, as you can see from my tries to solve it, it looks like I cannot expect/assert an element (or web element) as a complete object. Why?

                我试过了:

                expect(page.element).toEqual(browser.driver.switchTo().activeElement());
                

                但是由于我什至无法理解的错误而失败 - 有一个巨大的回溯(在控制台中滚动大约需要 10 分钟),但内部没有用户友好的错误.

                But is is failing with an error I cannot even understand - there is a huge traceback (it is about 10 minutes to scroll in the console), but no user-friendly error inside.

                我也尝试过使用 getWebElement():

                expect(page.element.getWebElement()).toEqual(browser.driver.switchTo().activeElement());
                

                但这导致了以下错误:

                错误:期望使用 WebElement 参数调用,期望一个 Promise.做过你的意思是使用 .getText()?

                Error: expect called with WebElement argument, expected a Promise. Did you mean to use .getText()?

                使用最新的量角器开发版本.

                Using the latest protractor development version.

                推荐答案

                在我的回答中,我将假设 activeElempageElem 都是量角器元素查找器,并且指向同一个网络元素.

                In my answer I'm going to assume activeElem and pageElem are both protractor element finders, and are pointing to the same web element.

                首先回答你关于为什么的问题

                First to answer your question about why

                expect(activeElem).toEqual(pageElem);
                

                进入一个无限循环,这是因为量角器在断言之前修补了jasmine的 expect 以解决promise,因此 expect(activeElem.getText()).toEqual('text'); 无需执行即可工作

                Gets into an infinite loop, it's because protractor patched jasmine's expect to resolve the promise before asserting, so that things like expect(activeElem.getText()).toEqual('text'); works without having to do

                activeElem.getText().then(function(text) {
                  expect(text).toEqual('text');
                })
                

                你可以说,为什么不只解决一次承诺呢?但是还有嵌套的 Promise.

                You could say, why not just resolve the promise once? But then there are nested promises.

                所以现在您可能会认为这是一个问题,但实际上并不是因为您永远不会在实际用例中比较两个 elementFinder.Jasmine 的 toEqual 进行引用检查,而不是深度比较,因此 expect(activeElem).toEqual(pageElem) 与简单的引用比较相同:(activeElem === pageElem).toToTruthy(),这样做真的没有意义.(注意 element(by.css('html')) === element(by.css('html')) 是假的,因为它不是同一个引用.)

                So now you might be thinking this is an issue, but it really isn't because you would never compare two elementFinders in a real use case. Jasmine's toEqual does a reference check, and not a deep compare, so expect(activeElem).toEqual(pageElem), is just the same as a simple reference comparison: (activeElem === pageElem).toToTruthy(), and there's really no point doing that. (Note element(by.css('html')) === element(by.css('html')) is false because it's not the same reference.)

                所以,回答这个线程的真正问题:如何查看两个 elementFinder 是否具有相同的底层 web 元素:

                So, to answer the real question for this thread: how to see if two elementFinders have the same underlying webelements:

                expect(activeElem.getId()).toEqual(pageElem.getId());
                

                这篇关于断言元素被聚焦的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                What are valid deviceNames for Chrome emulation testing with Protractor?(使用 Protractor 进行 Chrome 模拟测试的有效设备名称是什么?)
                Protractor Check if Element Does Not Exist(量角器检查元素是否不存在)
                Protractor e2e Tests Login Redirection(Protractor e2e 测试登录重定向)
                Explain about async/ await in Protractor(解释 Protractor 中的 async/await)
                Protractor browser.wait doesn#39;t wait(量角器 browser.wait 不等待)
                How to use Protractor with Angular 2?(如何在 Angular 2 中使用量角器?)
                <tfoot id='ArnVK'></tfoot>
                  <tbody id='ArnVK'></tbody>
                1. <small id='ArnVK'></small><noframes id='ArnVK'>

                    <bdo id='ArnVK'></bdo><ul id='ArnVK'></ul>

                    • <legend id='ArnVK'><style id='ArnVK'><dir id='ArnVK'><q id='ArnVK'></q></dir></style></legend>
                    • <i id='ArnVK'><tr id='ArnVK'><dt id='ArnVK'><q id='ArnVK'><span id='ArnVK'><b id='ArnVK'><form id='ArnVK'><ins id='ArnVK'></ins><ul id='ArnVK'></ul><sub id='ArnVK'></sub></form><legend id='ArnVK'></legend><bdo id='ArnVK'><pre id='ArnVK'><center id='ArnVK'></center></pre></bdo></b><th id='ArnVK'></th></span></q></dt></tr></i><div id='ArnVK'><tfoot id='ArnVK'></tfoot><dl id='ArnVK'><fieldset id='ArnVK'></fieldset></dl></div>