【问题标题】:Swith to an iframe with protractor 3.x.x使用量角器 3.x.x 切换到 iframe
【发布时间】:2016-04-27 14:18:29
【问题描述】:

我正在尝试在我的 e2e 测试中切换到 iframe。

我的代码是

var el = element(by.id('iframe-container')).element(by.tagName('iframe'));

browser.switchTo().frame(el);

$('.top-bar-right .btn-primary').click();

browser.switchTo().defaultContent();

由于某种原因这不起作用,有人知道他们在 selenium/protractor 的最新版本中是否有任何变化。

我有 selenium 版本 2.5.x 和量角器版本 3.1.x。

我的测试出错了,给了我这个错误:

FATER ERROR: CALL_AND_RETRY_LAST Allocation failed - process out of memory

谢谢!

【问题讨论】:

  • 你能检查 chrome 和 firefox - 两个浏览器都出现同样的错误吗?
  • 是的,两者都有同样的问题

标签: angularjs selenium iframe protractor e2e-testing


【解决方案1】:

你可以这样写:

browser.ignoreSynchronization=true;
      browser.switchTo().frame('iframe-container').then(function(){
          expect('something').not.toBeNull();
          $('.top-bar-right .btn-primary').click().then(function(){
              browser.switchTo().defaultContent().then(function(){
                  expect('something').not.toBeNull();
              });
          });
      });

【讨论】:

    【解决方案2】:

    这对我有用。我的示例是在测试 TinyMCE 时访问 body 元素。

    var test = function(){
        var iframe = element(by.tagName('iframe'));
    
        // iframe doesn't have angular... 
        browser.ignoreSynchronization = true;
    
        // must enter the iframe with the WebElement? 
        // or it crashes with out of memory error!! 
        return browser.switchTo().frame(iframe.getWebElement())
              .then(function(){
                  // in the iframe.. 
                  var editor_body = element(by.tagName('body'));
                  editor_body.sendKeys('test');
              })
              .then(function(){
                  // restore sync for angular
                  browser.ignoreSynchronization = false;
                  return browser.switchTo().defaultContent();
              });
    };
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-03-02
      • 1970-01-01
      • 2021-06-19
      • 2018-12-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多