通过Selenium WebDriver C#获取HTTP状态代码 [英] Getting HTTP Status Code by Selenium WebDriver C#

查看:477
本文介绍了通过Selenium WebDriver C#获取HTTP状态代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Selenium,C#,NUnit编写自动化测试。

I'm using Selenium, C#, NUnit to write automated tests.

是否可以使用WebDriver获取HTTP状态代码,以便测试失败,因为可以向用户发出HTTP请求吗?

Is it possible to get the HTTP status code with WebDriver so that tests that fail due to HTTP requests can be alerted to the user?

推荐答案

不使用外部工具编号

你知道,这在过去已被提出过多次,也是Selenium中最大的问题之一官方问题跟踪器特定问题已被反弹,并且基本上认为它超出了Selenium的范围。

You see, this has been brought up a number of times in the past and is one of the largest "issues" within Selenium's official issue tracker. The particular issue has been bounced around and essentially decided that it's outside the scope of Selenium.

然而,这并不意味着它是不可能的。值得庆幸的是,你正在使用C#,所以它比你想象的容易一些。

This however, does not mean that it is not possible. Thankfully, you are using C#, so it's a little easier than you may think.

最近,一位Selenium开发人员撰写了一篇博文,其中概述了确切地说如何在C#中执行此操作。这是一篇由三部分组成的博客文章,帮助解释每个步骤,并使用一个名为 Fiddler 的外部工具(顺便说一下,这是一个很棒的工具) )。

Recently, one of the Selenium developers wrote a blog post outlining exactly how to do this in C#. It is a three part blog post to help explain each step and uses an external tool, called Fiddler (which, by the way, is one awesome tool).

Fiddler是一个代理,有一个C#API,允许你拦截请求。因此,它意味着您可以简单地指出Selenium使用该代理,然后挂钩到Fiddler的API以确切地检查请求的状态代码。

Fiddler is a proxy and has a C# API that allows you to intercept requests. It therefore means you can simply "point" Selenium to use that proxy, and then hook into Fiddler's API to check exactly what status code the request has.

我只是链接到博客文章而不是给你代码,因为在这些帖子中对它进行了彻底的解释。

I am merely linking to the blog post rather than giving you code to this since it's pretty thoroughly explained in those posts.

也许尝试一下,然后如果你在实施他的任何问题时回来设计。顺便提一下,这个人也是StackOverflow的会员,所以也可以看到你的帖子。

Perhaps try it, and then come back if you get any issues implementing his design. Incidentally the guy is also a member here at StackOverflow, so may also see your post.

这篇关于通过Selenium WebDriver C#获取HTTP状态代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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