我正在评估 Watir-webdriver,以决定是否可以切换到使用它进行浏览器测试(主要来自 Watir),其中一个关键是能够与 TinyMCE WYSIWYG 编辑器进行交互,作为我的一些应用程序使用 TinyMCE。我设法使以下解决方案起作用-
@browser = Watir::Browser.new(:firefox)
@browser.goto("http://tinymce.moxiecode.com/tryit/full.php")
autoit = WIN32OLE.new('AutoITX3.Control')
autoit.WinActivate('TinyMCE - TinyMCE - Full featured example')
@browser.frame(:index, 0).body.click
autoit.Send("^a") # CTRL + a to select all
autoit.Send("{DEL}")
autoit.Send("Some new text")
这种方法的缺点是,通过使用 autoit,我仍然依赖于 Windows,并且跨平台运行测试的能力是 webdriver 的吸引力之一。
我注意到一些 webdriver 特定的解决方案,例如来自这个线程的以下内容:
String tinyMCEFrame = "TextEntryFrameName" // Replace as necessary
this.getDriver().switchTo().frame(tinyMCEFrame);
String entryText = "Testing entry\r\n";
this.getDriver().findElement(By.id("tinymce")).sendKeys(entryText);
//Replace ID as necessary
this.getDriver().switchTo().window(this.getDriver().getWindowHandle());
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
e.printStackTrace();
}
this.getDriver().findElement(By.partialLinkText("Done")).click();
看起来它可能跨平台工作,但我不知道是否可以从 Watir-webdriver 中访问相同的功能。我的问题是,有没有办法使用 watir-webdriver 编写、删除和提交到 TinyMCE,它不会强制依赖特定支持的浏览器或操作系统?