我用来触发菜单的代码如下:
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
答案 0 :(得分:0)
尝试在鼠标操作之前使用browser.sleep('几毫秒')或在此处显示完整代码。