7

我正在评估 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,它不会强制依赖特定支持的浏览器或操作系统?

4

3 回答 3

5

目前,您需要访问并获取底层驱动程序实例。这适用于 TinyMCE 示例页面

b = Watir::Browser.new
b.goto "http://tinymce.moxiecode.com/tryit/full.php"

d = b.driver
d.switch_to.frame "content_ifr"
d.switch_to.active_element.send_keys "hello world"

这实际上在 watir-webdriver 中并没有很好地暴露出来,但我会解决这个问题。在下一个版本(0.1.9)之后,您应该能够简单地执行以下操作:

b.frame(:id => "content_ifr").send_keys "hello world"
于 2011-01-13T10:58:37.680 回答
2

我发现自动化 TinyMCE 编辑器的更好方法是直接调用 JavaScript API,这样可以避免使用我觉得很麻烦的 iFrame。

例如:

require 'watir-webdriver'
b = Watir::Browser.new
b.goto 'http://tinymce.moxiecode.com/tryit/full.php'
b.execute_script("tinyMCE.get('content').execCommand('mceSetContent',false, 'hello world' );")

见:http ://watirwebdriver.com/wysiwyg-editors/

于 2011-09-18T12:08:42.323 回答
0

在最新版本的 TinyMCE 上(尤其是上面示例中使用的 Moxiecode Full Featured 示例中的当前版本),您似乎需要在脚本中添加一个 .click 以选择退格后的文本区域,因此您可能需要使用就像是:

browser.frame(:id, "content_ifr").send_keys [:control, "a"], :backspace
browser.frame(:id, "content_ifr").click
browser.frame(:id, "content_ifr").send_keys("Hello World")
于 2011-06-14T20:54:21.897 回答