使用Selenium IDE在JavaScript文件中调用函数 [英] Calling a function in a JavaScript file with Selenium IDE

查看:61
本文介绍了使用Selenium IDE在JavaScript文件中调用函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,我正在针对我正在工作的站点运行这些Selenium IDE测试.关于测试本身的一切都运行良好,除了完成后我想进行一些清理.在我的基于MVC3 Razor的站点中,我有一个JavaScript文件,该文件的功能可以从我的控制器获取JsonResult.该Controller处理Selenium IDE否则无法处理的数据库清理.

So, I'm running these Selenium IDE tests against a site I'm working on. Everything about the tests themselves is running fine, except I would like to do a bit of clean-up once I'm done. In my MVC3 Razor based site, I have a JavaScript file with a function that gets a JsonResult from a Controller of mine. That Controller handles the database clean-up that Selenium IDE otherwise couldn't handle.

但是,我很难找到有关如何执行此操作的任何文档.我知道我可以做 JavaScript {myJavascriptGoesHere} 作为测试中一行的值之一,但是我似乎找不到找到告诉它去查找清理函数的方法.

However, I'm having a hard time finding any sort of documentation on how to do this. I know I can do JavaScript{ myJavascriptGoesHere } as one of the Values for a line in the test, but I can't seem to find a way to tell it to go find my clean-up function.

Selenium IDE甚至可以做这种事情吗?

Is it even possible for Selenium IDE to do this sort of thing?

如果涉及到这一点,我可以单独创建一个View来进行清理,但是确实我想尽可能避免这种情况.

If it comes down to it, I can just make a separate View to handle the clean-up, but I'd really like to avoid that if possible.

谢谢!

推荐答案

如果要从Selenium IDE执行测试页中存在的自己的JavaScript函数,则需要确保通过window对象访问它.例如,如果您查看 storeEval 的参考,它会说:

If you want to execute your own JavaScript function that exists in your test page from Selenium IDE, you need to make sure you access it via the window object. If you look at the reference for storeEval for instance, it says:

请注意,默认情况下,该代码段将在硒"对象本身,因此将引用硒对象.使用窗口指代应用程序的窗口,例如window.document.getElementById('foo')

Note that, by default, the snippet will run in the context of the "selenium" object itself, so this will refer to the Selenium object. Use window to refer to the window of your application, e.g. window.document.getElementById('foo')

因此,如果您有自己的功能,例如 myFunc().您需要将其称为 window.myFunc().

So if you have your own function e.g. myFunc(). You need to refer to it as window.myFunc().

这对于在不实际提交表单的情况下进行客户端验证非常方便.如果要测试各种无效和有效的表单字段值.

This can be very handy for exercising client-side validation without actually submitting the form, e.g. if you want to test a variety of invalid and valid form field values.

如果您使用 runScript ,则该脚本应该已经在窗口的上下文中运行.

If you use runScript, that should already run in the window's context.

这篇关于使用Selenium IDE在JavaScript文件中调用函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆