From 36e467b595df0754acb1c333f6a780340efb0f71 Mon Sep 17 00:00:00 2001
From: wanggaofeng <15601716045@163.com>
Date: Wed, 31 Jan 2024 12:30:10 +0800
Subject: [PATCH] =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E6=B5=8B=E8=AF=95?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
Docs/说明.md | 3 +
.../PlaywrightStudy.Core.csproj | 13 ++++
PlaywrightStudy.Core/TenAPI/GetIP.cs | 24 ++++++
.../TenAPI/TenApiReturnBase.cs | 17 ++++
PlaywrightStudy.Test/GlobalUsings.cs | 5 +-
.../PlaywrightStudy.Test.csproj | 4 +
PlaywrightStudy.Test/PlaywrightTest.cs | 77 +++++++++++++++++++
PlaywrightStudy.sln | 13 +++-
8 files changed, 154 insertions(+), 2 deletions(-)
create mode 100644 Docs/说明.md
create mode 100644 PlaywrightStudy.Core/PlaywrightStudy.Core.csproj
create mode 100644 PlaywrightStudy.Core/TenAPI/GetIP.cs
create mode 100644 PlaywrightStudy.Core/TenAPI/TenApiReturnBase.cs
diff --git a/Docs/说明.md b/Docs/说明.md
new file mode 100644
index 0000000..ed8001b
--- /dev/null
+++ b/Docs/说明.md
@@ -0,0 +1,3 @@
+# Ŀ˵
+
+Playwright˵˲Կѧϰʹԭ.net(MSTestNUnitԪԿܼ)xUnitԿܡ
\ No newline at end of file
diff --git a/PlaywrightStudy.Core/PlaywrightStudy.Core.csproj b/PlaywrightStudy.Core/PlaywrightStudy.Core.csproj
new file mode 100644
index 0000000..60384ec
--- /dev/null
+++ b/PlaywrightStudy.Core/PlaywrightStudy.Core.csproj
@@ -0,0 +1,13 @@
+
+
+
+ net6.0
+ enable
+ enable
+
+
+
+
+
+
+
diff --git a/PlaywrightStudy.Core/TenAPI/GetIP.cs b/PlaywrightStudy.Core/TenAPI/GetIP.cs
new file mode 100644
index 0000000..b76994e
--- /dev/null
+++ b/PlaywrightStudy.Core/TenAPI/GetIP.cs
@@ -0,0 +1,24 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace PlaywrightStudy.Core.TenAPI
+{
+ ///
+ /// 获取IP信息 响应类
+ ///
+ public class GetIP
+ {
+ public string ip { get; set; }
+ public string country { get; set; }
+ public string province { get; set; }
+ public string city { get; set; }
+ public string area { get; set; }
+ public string isp { get; set; }
+ public string os { get; set; }
+ public string browser { get; set; }
+ }
+}
+
diff --git a/PlaywrightStudy.Core/TenAPI/TenApiReturnBase.cs b/PlaywrightStudy.Core/TenAPI/TenApiReturnBase.cs
new file mode 100644
index 0000000..227b225
--- /dev/null
+++ b/PlaywrightStudy.Core/TenAPI/TenApiReturnBase.cs
@@ -0,0 +1,17 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace PlaywrightStudy.Core.TenAPI
+{
+ public class TenApiReturnBase
+ {
+ public int code { get; set; }
+
+ public string msg { get; set; }
+
+ public T data { get; set; }
+ }
+}
diff --git a/PlaywrightStudy.Test/GlobalUsings.cs b/PlaywrightStudy.Test/GlobalUsings.cs
index 1035ba8..82fcb1c 100644
--- a/PlaywrightStudy.Test/GlobalUsings.cs
+++ b/PlaywrightStudy.Test/GlobalUsings.cs
@@ -2,4 +2,7 @@ global using Xunit;
global using Microsoft.Playwright;
global using Microsoft.Playwright.Core;
-global using Microsoft.Playwright.Transport;
\ No newline at end of file
+global using Microsoft.Playwright.Transport;
+
+global using PlaywrightStudy.Core;
+global using PlaywrightStudy.Core.TenAPI;
\ No newline at end of file
diff --git a/PlaywrightStudy.Test/PlaywrightStudy.Test.csproj b/PlaywrightStudy.Test/PlaywrightStudy.Test.csproj
index f361b30..de25c21 100644
--- a/PlaywrightStudy.Test/PlaywrightStudy.Test.csproj
+++ b/PlaywrightStudy.Test/PlaywrightStudy.Test.csproj
@@ -23,4 +23,8 @@
+
+
+
+
diff --git a/PlaywrightStudy.Test/PlaywrightTest.cs b/PlaywrightStudy.Test/PlaywrightTest.cs
index 4d0f4de..3527434 100644
--- a/PlaywrightStudy.Test/PlaywrightTest.cs
+++ b/PlaywrightStudy.Test/PlaywrightTest.cs
@@ -1,3 +1,4 @@
+
namespace PlaywrightStudy.Test
{
public class PlaywrightTest
@@ -416,5 +417,81 @@ namespace PlaywrightStudy.Test
//});
}
#endregion
+
+ #region WebAPI
+ ///
+ /// ʹѽӿ
+ ///
+ [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()
+ {
+ { "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>();
+
+ Assert.NotNull(ipResult);
+ Assert.IsType>(ipResult);
+
+ Assert.Equal("ȡɹ", ipResult.msg);
+
+ }
+
+ ///
+ /// ʹFiddlerץFiddlerΪ,Fiddler
+ ///
+ [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()
+ {
+ { "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>();
+
+ Assert.NotNull(ipResult);
+ Assert.IsType>(ipResult);
+
+ Assert.Equal("ȡɹ", ipResult.msg);
+
+ }
+ #endregion
}
}
\ No newline at end of file
diff --git a/PlaywrightStudy.sln b/PlaywrightStudy.sln
index 7495dee..b09820e 100644
--- a/PlaywrightStudy.sln
+++ b/PlaywrightStudy.sln
@@ -3,7 +3,14 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.9.34518.117
MinimumVisualStudioVersion = 10.0.40219.1
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PlaywrightStudy.Test", "PlaywrightStudy.Test\PlaywrightStudy.Test.csproj", "{809E556A-9E9E-4110-A2ED-586CADBE6899}"
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PlaywrightStudy.Test", "PlaywrightStudy.Test\PlaywrightStudy.Test.csproj", "{809E556A-9E9E-4110-A2ED-586CADBE6899}"
+EndProject
+Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Docs", "Docs", "{91229A84-D283-4F4F-BA18-6CD45A874B4B}"
+ ProjectSection(SolutionItems) = preProject
+ Docs\说明.md = Docs\说明.md
+ EndProjectSection
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PlaywrightStudy.Core", "PlaywrightStudy.Core\PlaywrightStudy.Core.csproj", "{230AC9DC-D0E2-41F8-BAF2-D15A6978FC62}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -15,6 +22,10 @@ Global
{809E556A-9E9E-4110-A2ED-586CADBE6899}.Debug|Any CPU.Build.0 = Debug|Any CPU
{809E556A-9E9E-4110-A2ED-586CADBE6899}.Release|Any CPU.ActiveCfg = Release|Any CPU
{809E556A-9E9E-4110-A2ED-586CADBE6899}.Release|Any CPU.Build.0 = Release|Any CPU
+ {230AC9DC-D0E2-41F8-BAF2-D15A6978FC62}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {230AC9DC-D0E2-41F8-BAF2-D15A6978FC62}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {230AC9DC-D0E2-41F8-BAF2-D15A6978FC62}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {230AC9DC-D0E2-41F8-BAF2-D15A6978FC62}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE