使用 watir-webdriver 进行自动化时如何处理tinyMCE?
我正在评估 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 的吸引力之一。
我注意到一些特定于网络驱动程序的解决方案,例如此线程:
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,而不会强制依赖于特定支持的浏览器或操作系统?
I'm evaluating Watir-webdriver, to decide if i can switch to using it for my browser tests (from Watir mostly) and one of the key things would be the ability to interact with TinyMCE WYSIWYG editors, as a number of the applications I work with use TinyMCE.
I've managed to get the following solution working -
@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")
The drawback of this approach, is that by using autoit, I remain dependent on Windows and the ability to run tests cross-platform is one of the attractions of webdriver.
I noticed some webdriver specific solutions such as the following from this thread:
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();
Which looks like it might work cross-platform but I don't know if the same functionality can be accessed from within Watir-webdriver. My question is, is there a way to write, delete and submit into TinyMCE using watir-webdriver, which will not enforce a dependency on a specific supported browser or operating system?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
目前,您需要进入并获取底层驱动程序实例。这在 TinyMCE 示例页面上对我有用。
这实际上在 watir-webdriver 中没有很好地暴露,但我会修复它。在下一个版本(0.1.9)之后,您应该能够简单地执行以下操作:
At the moment, you'll need to reach in and get the underlying driver instance. This works for me on the TinyMCE example page
This is actually not well exposed in watir-webdriver, but I'll fix that. After the next release (0.1.9) you should be able to simply do:
我发现自动化 TinyMCE 编辑器的更好方法是直接调用 JavaScript API,这样就可以避免使用我认为很麻烦的 iFrame。
例如:
请参阅:http://watirwebdriver.com/wysiwyg-editors/
I find a better way of automating TinyMCE editors is to call the JavaScript API directly, that way you avoid having the use the iFrames which I find troublesome.
For example:
See: http://watirwebdriver.com/wysiwyg-editors/
在 TinyMCE 的最新版本(尤其是上例中使用的 Moxiecode Full Features 示例中当前的版本)上,您似乎需要在脚本中添加 .click 以选择退格键后的文本区域,因此您可能需要使用像这样的东西:
On more recent versions of TinyMCE (notably the one currently on the Moxiecode Full Featured example used in the example above) it seems you need to add a .click into the script to select the text area after the backspace, so you might need to use something like: