Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Unit testing 使用selenium验证下载框弹出窗口_Unit Testing_Selenium_Webdriver - Fatal编程技术网

Unit testing 使用selenium验证下载框弹出窗口

Unit testing 使用selenium验证下载框弹出窗口,unit-testing,selenium,webdriver,Unit Testing,Selenium,Webdriver,我有一个网站,我正在使用selenium进行集成测试 我有一个链接,它是使用页面中的多个变量生成的。 我想验证下载弹出框是否显示,如果有可能的话,当我模拟点击链接下载文件 我知道我可以让JsUnit帮我做到这一点 有什么想法吗?Selenium在处理下载时很糟糕。点击链接会给你带来麻烦 但是,您可以为指定的链接发出请求(或者可能只是一个文件),并断言200ok响应。或者尝试获取该文件-对于Selenium。Thnx到Slanec我已经介绍了您的示例 好的,经过调查,我决定最好的解决方案是 沿着这

我有一个网站,我正在使用selenium进行集成测试

我有一个链接,它是使用页面中的多个变量生成的。 我想验证下载弹出框是否显示,如果有可能的话,当我模拟点击链接下载文件

我知道我可以让JsUnit帮我做到这一点


有什么想法吗?

Selenium在处理下载时很糟糕。点击链接会给你带来麻烦


但是,您可以为指定的链接发出请求(或者可能只是一个文件),并断言
200ok
响应。或者尝试获取该文件-对于Selenium。

Thnx到Slanec我已经介绍了您的示例

好的,经过调查,我决定最好的解决方案是 沿着这条线

    public int GetFileLenghtFromUrlLocation(string location)
    {
        int len = 0;
        int timeoutInSeconds = 5;

        // paranoid check for null value
        if (string.IsNullOrEmpty(location)) return 0;

        // Create a web request to the URL
        HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(location);
        myRequest.Timeout = timeoutInSeconds * 1000;
        myRequest.AddRange(1024);
        try
        {
            // Get the web response
            HttpWebResponse myResponse = (HttpWebResponse)myRequest.GetResponse();

            // Make sure the response is valid
            if (HttpStatusCode.OK == myResponse.StatusCode)
            {
                // Open the response stream
                using (Stream myResponseStream = myResponse.GetResponseStream())
                {
                    if (myResponseStream == null) return 0;

                    using (StreamReader rdr = new StreamReader(myResponseStream))
                    {
                        len = rdr.ReadToEnd().Length;
                    }
                }
            }
        }
        catch (Exception err)
        {
            throw new Exception("Error saving file from URL:" + err.Message, err);
        }

        return len;
    }

你知道C#中的相似吗(我想我可以写一些相似的东西,但仍然)哦,对不起,你没有指定语言。我对C#一无所知,但肯定有很多C#HttpRequest库(以及相关的SO问题)。祝你好运