为什么49.90 % 0.10
在JavaScript中返回0.09999999999999581
?我预计它会是0.
我正在寻找推荐/最好的方法让Selenium测试一个接一个地在几个浏览器中执行.我正在测试的网站并不大,所以我还不需要并行解决方案.
我有一个通常的测试设置方法[SetUp]
,[TearDown]
和[Test]
.当然,SetUp可以ISelenium
使用我想要测试的任何浏览器来实例化一个新对象.
所以我想要的是以编程方式说:这个测试将按顺序在Chrome,IE和Firefox上运行.我怎么做?
编辑:
这可能会有所帮助.我们正在使用CruiseControl.NET在成功构建之后启动NUnit测试.有没有办法将参数传递给NUnit可执行文件,然后在测试中使用该参数?这样我们就可以使用不同的浏览器参数多次运行NUnit.
我有一个Web API项目,它返回一些产品数据.它根据请求的Accept标头(JSON/XML)正确协商返回类型.问题是,如果没有指定Accept头,它返回JSON,但我希望它默认返回XML.如何更改Global.asax中的内容协商默认值?
我正在尝试以编程方式将命令发送到Tor控制端口以使其刷新链.我无法在C#中找到任何示例,我的解决方案无法正常工作.请求超时.我运行了服务,我可以看到它在控制端口上监听.
public string Refresh()
{
TcpClient client = new TcpClient("localhost", 9051);
string response = string.Empty;
string authenticate = MakeTcpRequest("AUTHENTICATE\r\n", client);
if (authenticate.Equals("250"))
{
response = MakeTcpRequest("SIGNAL NEWNYM\r\n", client);
}
client.Close();
return response;
}
public string MakeTcpRequest(string message, TcpClient client)
{
client.ReceiveTimeout = 20000;
client.SendTimeout = 20000;
string proxyResponse = string.Empty;
try
{
// Send message
StreamWriter streamWriter = new StreamWriter(client.GetStream());
streamWriter.Write(message);
streamWriter.Flush();
// Read response
StreamReader streamReader = new StreamReader(client.GetStream());
proxyResponse = streamReader.ReadToEnd();
}
catch (Exception ex)
{
// Ignore …
Run Code Online (Sandbox Code Playgroud) 我创建了一个测试网站来调试我遇到的问题,看起来我要么传递JSON数据错误,要么MVC只能绑定可空的longs.当然,我正在使用最新的MVC 3版本.
public class GetDataModel
{
public string TestString { get; set; }
public long? TestLong { get; set; }
public int? TestInt { get; set; }
}
[HttpPost]
public ActionResult GetData(GetDataModel model)
{
// Do stuff
}
Run Code Online (Sandbox Code Playgroud)
我发布了一个具有正确JSON内容类型的JSON字符串:
{ "TestString":"test", "TestLong":12345, "TestInt":123 }
Run Code Online (Sandbox Code Playgroud)
长期没有约束,它总是空的.如果我把这个值放在引号中,它就可以工作,但我不应该这样做,不是吗?我需要为该值设置自定义模型绑定器吗?
我有一些代码可以下载gzip压缩文件并对其进行解压缩.问题是,我无法解压缩整个文件,它只读取前4096个字节,然后再读取大约500个字节.
Byte[] buffer = new Byte[4096];
int count = 0;
FileStream fileInput = new FileStream("input.gzip", FileMode.Open, FileAccess.Read, FileShare.Read);
FileStream fileOutput = new FileStream("output.dat", FileMode.Create, FileAccess.Write, FileShare.None);
GZipStream gzipStream = new GZipStream(fileInput, CompressionMode.Decompress, true);
// Read from gzip steam
while ((count = gzipStream.Read(buffer, 0, buffer.Length)) > 0)
{
// Write to output file
fileOutput.Write(buffer, 0, count);
}
// Close the streams
...
Run Code Online (Sandbox Code Playgroud)
我检查了下载的文件; 它在压缩时为13MB,包含一个XML文件.我手动解压缩了XML文件,内容就在那里.但是,当我使用此代码执行此操作时,它只输出XML文件的最开头.
任何人都有任何想法为什么会发生这种情况?
如果我将原始HTTP响应作为字符串:
HTTP/1.1 200 OK
日期:2010年5月11日星期二07:28:30 GMT
到期:-1
Cache-Control:private,max-age = 0
Content-Type:text/html; charset = UTF-8
服务器:gws
X-XSS-Protection:1; mode = block
连接:关闭
<!doctype html><html>...</html>
Run Code Online (Sandbox Code Playgroud)
有没有一种简单的方法可以将它解析为一个HttpListenerResponse
对象?或者至少是某种.NET对象,所以我不必使用原始响应.
我目前正在做的是提取标题键/值对并在HttpListenerResponse上设置它们.但是有些头文件无法设置,然后我必须剪切响应的主体并将其写入OutputStream.但是身体可以被gzipped,或者它可能是一个图像,我还无法工作.并且一些响应在任何地方都包含随机字符,这看起来像编码问题.这很麻烦.
我正在获得原始响应,因为我正在使用SOCKS发送HTTP请求.我正在处理的程序基本上是一个HTTP代理,它可以通过SOCKS代理路由请求,就像Privoxy那样.
我有一个 Firefox 扩展,可以修改用户正在查看的页面内容。作为该过程的一部分,扩展程序需要触发扩展程序本身添加到页面源的自定义事件。我无法将参数传递给该自定义事件。我究竟做错了什么?
插入head
页面的脚本块:
document.addEventListener("show-my-overlay", EX_ShowOverlay, false, false, true);
function EX_ShowOverlay(e) {
alert('Parameter: ' + e.index);
// ...
}
Run Code Online (Sandbox Code Playgroud)
扩展中的代码:
var event = content.document.createEvent("Events");
event.initEvent("show-my-overlay", true, true);
event['index'] = 123;
content.document.dispatchEvent(event);
Run Code Online (Sandbox Code Playgroud)
事件被成功触发,但e.index
未定义。
我设法通过在页面上创建一个元素然后让事件处理程序找到该元素并读取其属性来使其工作,但它并不优雅。我想在没有元素的情况下做到这一点。
编辑:
我也尝试用 触发事件CustomEvent
,但它在处理程序中引发异常:
var event = new CustomEvent('show-my-overlay', { detail: { index: 123 } });
content.document.dispatchEvent(event);
function EX_ShowOverlay(e) {
alert('Parameter: ' + e.detail.index);
// ...
}
Run Code Online (Sandbox Code Playgroud)
访问属性“详细信息”的权限被拒绝
我在CruiseControl.NET配置中有这个代码块:
<exec>
<executable>C:\Windows\System32\cmd.exe</executable>
<buildArgs>/C SETX SELENIUM_BROWSER googlechrome /M</buildArgs>
</exec>
Run Code Online (Sandbox Code Playgroud)
接下来是一个NUnit执行命令,它将在我的网站上运行一些Selenium测试.我们的想法是,在运行测试之前,此命令会更改测试浏览器(系统环境变量).
问题是该命令似乎不起作用.测试仍在使用默认浏览器Firefox.如果我手动更改环境变量,它可以工作.
我究竟做错了什么?
编辑:
我尝试将命令放在批处理文件中并执行它,但它仍然无效:
<exec executable="C:\CCNet\setChrome.bat" />
Run Code Online (Sandbox Code Playgroud)
批处理文件内容:
SETX SELENIUM_BROWSER googlechrome /M
Run Code Online (Sandbox Code Playgroud) 我有一个需要基本授权的Web服务和一个需要NTLM授权的Internet代理后面的用户.我还有一个表单应用程序,它调用Web服务并询问用户Web服务凭据(与NTLM凭据不同).
我得到了应用程序配置(WCF ServiceModel),它使用默认代理凭据,请求正在使用代理进行身份验证,但在使用Web服务进行身份验证后,由于某种原因它不会发送请求正文.
如果我在没有NTLM代理的情况下在本地测试,则该过程有效.对很长的例子感到抱歉,但我不得不包括它们.
第一次要求:
发送:
POST http://www.myservice.com/service.asmx HTTP/1.1
Content-Type: text/xml; charset=utf-8
SOAPAction: "http://tempuri.org/MyMethod"
Host: www.myservice.com
Content-Length: 329
Expect: 100-continue
Accept-Encoding: gzip, deflate
Proxy-Connection: Keep-Alive
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"><s:Body>[...]</s:Body></s:Envelope>
Run Code Online (Sandbox Code Playgroud)
接收:
HTTP/1.1 407 Proxy Authentication Required
Proxy-Authenticate: NTLM
Proxy-Authenticate: BASIC realm="corporaterealm"
Cache-Control: no-cache
Pragma: no-cache
Content-Type: text/html; charset=utf-8
Proxy-Connection: close
Set-Cookie: BCSI-CS-36204A5A7BBD24D9=2; Path=/
Connection: close
Content-Length: 1057
Proxy-Support: Session-Based-Authentication
[...]
Run Code Online (Sandbox Code Playgroud)
第二次请求:
发送:
POST http://www.myservice.com/service.asmx HTTP/1.1
Content-Type: text/xml; charset=utf-8
SOAPAction: "http://tempuri.org/MyMethod"
Accept-Encoding: gzip, deflate,gzip, deflate
Proxy-Authorization: NTLM TlRMTVNTUAABAAAAB7IIoggACAAxAAAACQAJACgAAAAFASgKAAAAD1dTUkswNDg3MENPTUVUTkVU
Host: www.myservice.com
Content-Length: 0
Run Code Online (Sandbox Code Playgroud)
接收:
HTTP/1.1 …
Run Code Online (Sandbox Code Playgroud) c# ×6
javascript ×2
nunit ×2
proxy ×2
selenium ×2
.net ×1
asp.net-mvc ×1
dom-events ×1
firefox ×1
gzipstream ×1
httplistener ×1
httpresponse ×1
modulus ×1
ntlm ×1
nullable ×1
socks ×1
tcpclient ×1
tor ×1
wcf ×1
web-services ×1
xml ×1