【问题标题】:Protractor - right clicking within chrome shows wrong menu量角器 - 在 chrome 中右键单击显示错误的菜单
【发布时间】:2015-11-15 17:43:51
【问题描述】:

在 Chrome 中手动测试上下文菜单时,结果如预期:

但是当量角器试图模仿同样的情况时,浏览器的菜单出现了:

我用来触发菜单的代码如下:

browser.actions().mouseMove(element(by.id(word2Id))).perform();
browser.actions().click(protractor.Button.RIGHT).perform();

任何人都可以提出解决此问题的方法或解决方案吗?因为我现在很难过。

编辑:在鼠标移动之前和之后添加睡眠会使测试有时有效。我将睡眠时间更改为 10 秒,但没有任何改善。我在下面添加了一个测试(有些代码很奇怪,因为我删除了方法调用)。

var module = testData.modules[3];
loginPage.login(process.env.TDC_TEST_USER, process.env.TDC_TEST_PASS);

var url = resourcePage.buildModuleResourceUrl(module._id, module.resources[1], "title");
url = TestConfig.BASE_URL + "/test/iframe?url=" + encodeURIComponent(url) + "&width=991px&height=1000px";
browser.driver.get(url);

// load the module/resource in a iframe to simulate a small screen
browser.switchTo().frame(browser.driver.findElement(by.id("embeddedPlayerFrame")));
expect(element(by.id("btnClassCommentsLeftPanel")).getAttribute("class")).toContain("active");
expect(element(by.id("btnPersonalCommentsLeftPanel")).getAttribute("class")).not.toContain("active");

var type = "personal";
var startWordIndex = 11; 

var pagedMenuBtn = type === "class" ? "pagedMenuClassComment" : "pagedMenuPersonalNote";
var saveBtnTxt = type === "class" ? "Comment" : "Create Note";
var word1Id = "ocr_word_0_" + startWordIndex;
var word2Id = "ocr_word_0_" + (startWordIndex + 1); 
var word3Id = "ocr_word_0_" + (startWordIndex + 2); 

expect(element(by.id(word1Id)).isDisplayed()).toBe(true);
expect(element(by.id(word2Id)).isDisplayed()).toBe(true);
expect(element(by.id(word3Id)).isDisplayed()).toBe(true);

browser.actions()
    .mouseDown(element(by.id(word1Id)))
    .mouseMove(element(by.id(word1Id)))
    .mouseMove(element(by.id(word2Id)))
    .mouseMove(element(by.id(word3Id)))
    .mouseUp(element(by.id(word3Id)))
    .perform();

browser.sleep(1000);
browser.actions().mouseMove(element(by.id(word2Id))).perform();
browser.sleep(100);

// create a new class comment annotation by right clicking
browser.actions().click(protractor.Button.RIGHT).perform();

编辑:这在 Firefox 中完美运行,但不是 chrome

【问题讨论】:

    标签: javascript google-chrome selenium protractor


    【解决方案1】:

    尝试在鼠标操作之前使用 browser.sleep('somemilliseconds') 或在此处显示完整代码。

    【讨论】:

    • 更新了上面的描述。添加睡眠会略微提高可靠性,但不会提高很多。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-04-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-10-11
    • 2017-12-02
    • 1970-01-01
    相关资源
    最近更新 更多