使用 selenium 验证弹出下载框 [英] Verifying download box pop up using selenium

查看:23
本文介绍了使用 selenium 验证弹出下载框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用 selenium 进行集成测试的网站.

I have a website where I am using selenium for integration testing.

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

I have link there that is generated using multiple variables from page. I would like to verify the download pop up box is displaying if at all possible, when i am simulating click on link to download the file.

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

I know i can have JsUnit that will do that for me.

有什么想法吗?

推荐答案

感谢 Slanec,我已经接受了您的示例.

Thnx to Slanec i have took up your examples.

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

Ok after investigation I have decided that best solution will be something along this line.

    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;
    }

这篇关于使用 selenium 验证弹出下载框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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