IE9/FF/Chrome 的 Javascript/JQuery 浏览器测试框架

发布于 2024-12-15 12:20:39 字数 529 浏览 1 评论 0原文

如果之前已经问过这个问题,我深表歉意,但我在谷歌上找不到答案。

我正在为每个浏览器寻找一个测试插件,我可以在其中简单地记录测试(单击各种内容),然后只需单击“运行测试”即可运行此测试。如果我能写一些关于我需要什么样的答案的代码(即生成最终的html),那就最好了,但如果可能的话那就没问题了。

我无法使用 JUnit 等内容的原因是因为我的代码使用外部 Web 服务(例如我无法访问的外部服务器上的付款)并且我在测试期间被重定向到不同的页面,所以我假设它必须是一个测试插件。

如果这些插件能够与 Visual Studio 2010(或者至少是 IE 插件)集成,那就太棒了,但没有它我也能生活。

我正在阅读 iMacros(Chrome,但不幸的是 beta)和 Selenium(Firefox),但我想知道最标准的方法是什么(我认为它已经完成了很长时间)。另外我还需要一个 IE9 版,但我还没有找到。

提前致谢, 约瑟夫

附言。我创建了 AJAX 重型网页,因此简单的基于 URL 的测试是不够的(如 Adob​​eBrowser 实验室)

I apologize if this question was asked already before but I could not find an answer on google.

I am looking for a testing plugin for each browser, where I could simply record a test (click on a variety of things) and then simply run this test just by clicking 'run test'. The best if I could write some code about what sort of answers I require (i.e. generated final html), but if that is possible it is ok.

The reason I can't use stuff like JUnit etc. is because my code uses external webservices (such as payment on an external server, that I can't access) and I am redirected to different pages during the test, so I assume it has to be a test plugin.

If the plugins would be intergrated with Visual Studio 2010 (or at least the IE plugin) it would be awesome, but I can live without it.

I am reading into iMacros (Chrome, but unfortunately beta) and Selenium(Firefox), but I wanted to know what is the mostly standart way to do that (I assume it was done for ages now). Additionally I need one for IE9, which I did not find yet.

Thanks in advance,
Jozef

ps. I create AJAX heavy webpage, so simple URL based testing is not enough (like AdobeBrowser lab)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

如梦 2024-12-22 12:20:39

Selenium 非常适合 Web 浏览器自动化测试,最新版本适用于几乎所有版本的 IE ( 7 - 9)(我目前无法查看工作中的文档)以及 Firefox 3 - 8 和 Chrome 12 及以上版本。

selenium 网站和 http://code.google.com/p/ 上有一些很好的示例selenium/ 站点也是如此。

(对于 Chrome 浏览器,您还需要下载 ChromeiumServer

这是我前一段时间一直在搞乱的一些粗略且现成的源代码

using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using OpenQA.Selenium;
using OpenQA.Selenium.Firefox;
using OpenQA.Selenium.Chrome;
using OpenQA.Selenium.IE;
using OpenQA.Selenium.Remote;
using System.Threading;

namespace ConsoleApplication1
{
    class Program
    {
        const string Path = @"H:\Selenium\chromedriver_win_16.0.902.0\";

        static void Main(string[] args)
        {
            TestMethodChromeViaServer();

            WebBrowser(TestMethodFf());
            WebBrowser(TestMethodIe());
            WebBrowser(TestMethodChromeDefault());
        }

        /// <summary>
        /// Runs the code in the browser.
        /// </summary>
        /// <param name="webDriver">The Web Driver to use to initiate a web browser.</param>
        public static void WebBrowser(IWebDriver webDriver)
        {
            webDriver.Navigate().GoToUrl("http://nerddinner.com/Account/LogOn?returnUrl=%2F#");

            IWebElement query = webDriver.FindElement(By.Id("UserName"));
            query.Submit();

            var foo = webDriver.FindElement(By.CssSelector("span[for='UserName']"));

            webDriver.Quit();
        }

        /// <summary>
        /// Launches Google Chrome via the service so multiple tests can be run before closing the service.
        /// </summary>
        public static void TestMethodChromeViaServer()
        {
            var service = ChromeDriverService.CreateDefaultService(Path);
            service.Start();

            IWebDriver driver = new RemoteWebDriver(service.ServiceUrl, DesiredCapabilities.Chrome());

            WebBrowser(driver);

            service.Dispose();
        }

        /// <summary>
        /// Creates a Web Driver using Google Chrome.
        /// </summary>
        /// <returns>Web driver with ChromeDriver setup to the correct path.</returns>
        public static IWebDriver TestMethodChromeDefault()
        {
            IWebDriver driver = new ChromeDriver(Path);

            return driver;
        }

        /// <summary>
        /// Creates a Web Driver using Firefox.
        /// </summary>
        /// <returns>Web driver with FirefoxDriver profile setup.</returns>
        public static IWebDriver TestMethodFf()
        {
            var foxProfile = new FirefoxProfile
                {
                    AcceptUntrustedCertificates = true
                };

            IWebDriver driver = new FirefoxDriver(foxProfile);

            return driver;
        }

        /// <summary>
        /// Creates a Web Driver using Internet Explorer.
        /// </summary>
        /// <returns>Web driver with InternetExplorerDriver setup.</returns>
        public static IWebDriver TestMethodIe()
        {
            //// Must set the protected mode on each zone to be the same (on or off), under tools -> security tab
            IWebDriver driver = new InternetExplorerDriver();

            return driver;
        }
    }
}

Selenium is quite good for web browser automated testing and the latest version works with almost all versions of IE (7 - 9) (I can't view the documentation at work at the moment) and Firefox 3 - 8, and Chrome 12 upwards.

There are some good examples on the selenium website and on the http://code.google.com/p/selenium/ site too.

(For the Chrome browser you'll also need to download the ChromeiumServer

Here's some rough and ready sourcecode I've been messing about a while back

using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using OpenQA.Selenium;
using OpenQA.Selenium.Firefox;
using OpenQA.Selenium.Chrome;
using OpenQA.Selenium.IE;
using OpenQA.Selenium.Remote;
using System.Threading;

namespace ConsoleApplication1
{
    class Program
    {
        const string Path = @"H:\Selenium\chromedriver_win_16.0.902.0\";

        static void Main(string[] args)
        {
            TestMethodChromeViaServer();

            WebBrowser(TestMethodFf());
            WebBrowser(TestMethodIe());
            WebBrowser(TestMethodChromeDefault());
        }

        /// <summary>
        /// Runs the code in the browser.
        /// </summary>
        /// <param name="webDriver">The Web Driver to use to initiate a web browser.</param>
        public static void WebBrowser(IWebDriver webDriver)
        {
            webDriver.Navigate().GoToUrl("http://nerddinner.com/Account/LogOn?returnUrl=%2F#");

            IWebElement query = webDriver.FindElement(By.Id("UserName"));
            query.Submit();

            var foo = webDriver.FindElement(By.CssSelector("span[for='UserName']"));

            webDriver.Quit();
        }

        /// <summary>
        /// Launches Google Chrome via the service so multiple tests can be run before closing the service.
        /// </summary>
        public static void TestMethodChromeViaServer()
        {
            var service = ChromeDriverService.CreateDefaultService(Path);
            service.Start();

            IWebDriver driver = new RemoteWebDriver(service.ServiceUrl, DesiredCapabilities.Chrome());

            WebBrowser(driver);

            service.Dispose();
        }

        /// <summary>
        /// Creates a Web Driver using Google Chrome.
        /// </summary>
        /// <returns>Web driver with ChromeDriver setup to the correct path.</returns>
        public static IWebDriver TestMethodChromeDefault()
        {
            IWebDriver driver = new ChromeDriver(Path);

            return driver;
        }

        /// <summary>
        /// Creates a Web Driver using Firefox.
        /// </summary>
        /// <returns>Web driver with FirefoxDriver profile setup.</returns>
        public static IWebDriver TestMethodFf()
        {
            var foxProfile = new FirefoxProfile
                {
                    AcceptUntrustedCertificates = true
                };

            IWebDriver driver = new FirefoxDriver(foxProfile);

            return driver;
        }

        /// <summary>
        /// Creates a Web Driver using Internet Explorer.
        /// </summary>
        /// <returns>Web driver with InternetExplorerDriver setup.</returns>
        public static IWebDriver TestMethodIe()
        {
            //// Must set the protected mode on each zone to be the same (on or off), under tools -> security tab
            IWebDriver driver = new InternetExplorerDriver();

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