量角器:switchTo()。帧问题,测试被阻止

时间:2017-05-13 11:34:39

标签: javascript iframe jasmine protractor

我正在尝试运行最大化和最小化聊天窗口的测试,它包含在iframe中:HTML here

带有测试的页面是:chat_features.js

const customerURL = "https://vps-web-utils.awsbrandembassy.com/livechat-window-gherkin/"

let agent = browser;
let customer = browser.forkNewDriverInstance();

describe('First interaction customer-agent', () => {

    beforeAll(function() {
        agent.ignoreSynchronization = true;
        customer.ignoreSynchronization = true;
        customer.get(customerURL);
        agent.driver.manage().window().maximize();
        customer.driver.manage().window().maximize();
    });

    it('should maximize and minimize chat window', () => {
        let elm1 = customer.$('[class="be-chat-wrap be-chat-wrap--minimize"]');
        expect(elm1.isPresent()).toBe(true);
        elm1.click(); 
        customer.sleep(3000);  
        // switching to iframe 
        browser.switchTo().frame($('.be-chat-frame'));
        // customer.sleep(1000);
        // expect(elm1.isPresent()).toBe(false);
        // let elm2 = customer.$('.control-panel__icon.control-panel__icon--minimize');
        // expect(elm2.isPresent()).toBe(true);
        // elm2.click();
        customer.sleep(3000);
    });

});

虽然conf.js文件是这样的:

exports.config = {
  framework: 'jasmine',
  specs: ['chat_features.js'],
  multiCapabilities: [{
    browserName: 'chrome'
  }],
  directConnect: 'true'
}

看起来当引入切换命令测试失败时,但我们没有记录错误,浏览器窗口保持打开状态,你必须使用CTRL+C

2 个答案:

答案 0 :(得分:0)

抱歉,我认为你的定位器很好......但它不是。 api声明你应该.getWebElement()使用switchTo() ......虽然无法解释原因。

这是关键:

browser.switchTo().frame($('.be-chat-frame').getWebElement());

这是您的工作代码:

const customerURL = "https://vps-web-utils.awsbrandembassy.com/livechat-window-gherkin/";

describe('angularjs homepage', function() {

    beforeAll(function() {
        browser.ignoreSynchronization = true;
        browser.get(customerURL);
    });

    it('should maximize the chat window', () => {
        let elm1 = $('[class="be-chat-wrap be-chat-wrap--minimize"]');
        expect(elm1.isPresent()).toBe(true);
        elm1.click();  
    });

    it('should switch to iFrame and minimize chat window', function() {
        // switch to iframe
        browser.switchTo().frame($('.be-chat-frame').getWebElement());
        // minimizing windows
        let elm2 = browser.$('.control-panel__text');
        expect(elm2.isPresent()).toBe(true);
        elm2.click();  
        // Switch back to Default Content
        browser.switchTo().defaultContent();
    });
});

答案 1 :(得分:0)

我设法找到解决方案,这是代码:

const customerURL = "https://vps-web-utils.awsbrandembassy.com/livechat-window-gherkin/"

describe('angularjs homepage', function() {

    beforeAll(function() {
        browser.ignoreSynchronization = true;
        browser.get(customerURL);
    });

    it('should maximize the chat window', () => {
        let elm1 = browser.$('[class="be-chat-wrap be-chat-wrap--minimize"]');
        expect(elm1.isPresent()).toBe(true);
        elm1.click();  
    });

    it('should switch to iFrame and minimize chat window', function() {
        // switch to iframe
        browser.switchTo().frame(browser.driver.findElement(protractor.By.css('.be-chat-frame')));
        // minimizing windows
        let elm2 = browser.$('.control-panel__text');
        expect(elm2.isPresent()).toBe(true);
        elm2.click();  
        // Switch back to Default Content
        browser.switchTo().defaultContent();
    });
});

关键是这里的语法:

browser.switchTo().frame(browser.driver.findElement(protractor.By.css('.be-chat-frame')));

在此页面找到解决方案:correct syntax