问题描述
我需要一种在WebAPI自动化上对自己进行身份验证的方法。我已经提取了承载令牌并将json传递到.net对象中,如何在打开JWT / Bearer Token的同时传递所需的标头并将其注入ChromeDriver会话中,以便当我的应用导航至https:// localhost时: 5000 /登录,它应自动重定向到-> https:// localhost:5000 / Dashboard。
class Program
{
//private static IWebDriver driver;
// ******->Selenium Specific Code<-******
// Instantiate the Chrome Driver
var driver = new ChromeDriver("/usr/local/bin/");
static IJavaScriptExecutor jsDriver = driver as IJavaScriptExecutor;
public static string setItemInLocalStorage(string item,string value)
{
var js = ((IJavaScriptExecutor)driver).ExecuteScript(String.Format(
"window.localStorage.setItem('userDetails','" + value + "');"));
return "";
}
//Method to Authenticate & GET Bearer Token from API.
public static async void GetAllWorkshopData(int WorkshopId)
{
UserAuth ua = new UserAuth();
ua.EmailAddress = "example@mail.com";
ua.Password = "Strongest!!!Pwd";
ua.WorkshopId = WorkshopId;
using (var client = new HttpClient())
{
var uri = "https://localhost:5001/api/userauth/Login";
string json = JsonConvert.SerializeObject(ua);
StringContent content = new StringContent(json,Encoding.UTF8,"application/json");
var res = await client.PostAsync(uri,content);
string datar = await res.Content.ReadAsstringAsync();
Example details = JsonConvert.DeserializeObject<Example>(datar);
// Navigate to the Endpoint
///here inject basic-auth token before selenium opens browser
driver.Navigate().GoToUrl("http://localhost:5000/Login");
setItemInLocalStorage("",datar);
driver.Navigate().GoToUrl("http://localhost:5000/Dashboard");
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)