|
|
@ -1,3 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
namespace PlaywrightStudy.Test
|
|
|
|
namespace PlaywrightStudy.Test
|
|
|
|
{
|
|
|
|
{
|
|
|
|
public class PlaywrightTest
|
|
|
|
public class PlaywrightTest
|
|
|
@ -416,5 +417,81 @@ namespace PlaywrightStudy.Test
|
|
|
|
//});
|
|
|
|
//});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endregion
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#region WebAPI
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
|
|
/// 使用免费接口
|
|
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
|
|
|
public async Task WebAPI_TestAsync()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
//https://docs.tenapi.cn/ 免费接口
|
|
|
|
|
|
|
|
//IP查询 https://tenapi.cn/v2/getip?ip=192.168.1.1
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
using var playwright = await Playwright.CreateAsync();
|
|
|
|
|
|
|
|
var apiRequestContext = await playwright.APIRequest.NewContextAsync(new APIRequestNewContextOptions()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
BaseURL="https://tenapi.cn",
|
|
|
|
|
|
|
|
ExtraHTTPHeaders = new Dictionary<string, string>()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
{ "Accept","text/html"},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//全局认证
|
|
|
|
|
|
|
|
{ "Authorization","Bear a.b.c"}
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
//HttpCredentials = new HttpCredentials() { Origin="http://localhost:8060",Username="admin",Password="123456" },
|
|
|
|
|
|
|
|
//IgnoreHTTPSErrors = true, //设置代理时,忽略证书错误
|
|
|
|
|
|
|
|
Timeout = 30*1000,
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var apiResponse = await apiRequestContext.GetAsync("v2/getip?ip=192.168.1.1");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Assert.True(apiResponse.Ok);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var ipResult = await apiResponse.JsonAsync<TenApiReturnBase<GetIP>>();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Assert.NotNull(ipResult);
|
|
|
|
|
|
|
|
Assert.IsType<TenApiReturnBase<GetIP>>(ipResult);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Assert.Equal("获取成功", ipResult.msg);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
|
|
/// 使用Fiddler抓包:设置Fiddler为代理服务器,必须先启动Fiddler
|
|
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
|
|
|
public async Task WebAPI_FiddleProxy_TestAsync()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
//https://docs.tenapi.cn/ 免费接口
|
|
|
|
|
|
|
|
//IP查询 https://tenapi.cn/v2/getip?ip=192.168.1.1
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
using var playwright = await Playwright.CreateAsync();
|
|
|
|
|
|
|
|
var apiRequestContext = await playwright.APIRequest.NewContextAsync(new APIRequestNewContextOptions()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
BaseURL = "https://tenapi.cn",
|
|
|
|
|
|
|
|
ExtraHTTPHeaders = new Dictionary<string, string>()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
{ "Accept","text/html"},
|
|
|
|
|
|
|
|
{ "Authorization","Bear a.b.c"}
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
IgnoreHTTPSErrors = true, //设置代理时,忽略证书错误
|
|
|
|
|
|
|
|
Timeout = 30 * 1000,
|
|
|
|
|
|
|
|
Proxy = new Proxy() { Server = "http://127.0.0.1:8888" }
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var apiResponse = await apiRequestContext.GetAsync("v2/getip?ip=192.168.1.1");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Assert.True(apiResponse.Ok);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var ipResult = await apiResponse.JsonAsync<TenApiReturnBase<GetIP>>();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Assert.NotNull(ipResult);
|
|
|
|
|
|
|
|
Assert.IsType<TenApiReturnBase<GetIP>>(ipResult);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Assert.Equal("获取成功", ipResult.msg);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|