使用 watir-webdriver 进行自动化时如何处理tinyMCE?

发布于 2024-10-11 09:20:36 字数 1374 浏览 4 评论 0原文

我正在评估 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

倾`听者〃 2024-10-18 09:20:36

目前,您需要进入并获取底层驱动程序实例。这在 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"

At the moment, you'll need to reach in and get the underlying driver instance. This works for me on the TinyMCE example page

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"

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:

b.frame(:id => "content_ifr").send_keys "hello world"
赴月观长安 2024-10-18 09:20:36

我发现自动化 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/

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:

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' );")

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

暗地喜欢 2024-10-18 09:20:36

在 TinyMCE 的最新版本(尤其是上例中使用的 Moxiecode Full Features 示例中当前的版本)上,您似乎需要在脚本中添加 .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")

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:

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")
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文