我正在评估watir-webdriver,以决定是否可以切换为浏览器测试(主要来自watir),关键因素之一就是与Tinymce Wysiwyg编辑器进行交互的能力,作为许多应用程序I使用使用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,并且可以运行测试的能力跨平台是Web Driver的景点之一。

我注意到一些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,这不会强制对特定支持的浏览器或操作系统的依赖?

有帮助吗?

解决方案

目前,您需要到达并获取基础驾驶员实例。这对我有用的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"

其他提示

我发现一种更好的方法来自动化Tinymce编辑器是直接调用JavaScript API,这样您就可以避免使用我觉得麻烦的IFRAMES。

例如:

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/

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

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")
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top