我是selenium和C#的初学者。
我已经设置了一个selenium集线器,还有6个远程selenium节点注册到这个中心(在我的自动化框架中使用C# )。
当我运行测试时,我需要记录每个测试运行的远程节点的IP地址。这在程序上可以使用C#吗?
发布于 2017-06-01 03:23:39
请从RestSharp中将NuGetpackage添加到项目中,然后粘贴代码片段:
private static void GetNodeIp(string hostName , string port , string sessionId)
{
try
{
RestClient client = new RestClient("http://" + hostName + ":" + port + "/grid/api/testsession?session=" + sessionId);
RestRequest req = new RestRequest(Method.GET);
var resp = client.Execute(req);
dynamic jsonData = JsonConvert.DeserializeObject(resp.Content);
Console.WriteLine("Test Will run on Machine : {0}" ,new Uri(jsonData.proxyId.ToString()));
}
catch (Exception ex)
{
}
}然后像这样调用上面的方法:
GetNodeIp("localhost", "4444", "ffgfdg-fgfgf-fgdfgfg-sdsdfdsf");您应该能够使用下面的代码片段获得会话id:
RemoteWebDriver driver = new RemoteWebDriver(new Uri(hubUrl), _capabilities, TimeSpan.FromSeconds(180));
string session = driver.SessionId.ToString();不要忘记初始化期望能力对象。
发布于 2015-05-09 00:00:31
为什么你现在需要他们的IP地址?在节点注册到集线器之后,它们已经连接起来了。使用RemoteWebDriver运行测试时,RemoteWebDriver会自动与集线器连接,并将测试传输到已经注册的节点。要确保节点已经注册,如果集线器驻留在系统中,则通过浏览器http://localhost:4444调用集线器。您应该会看到每个节点的配置选项卡,如果在一个节点中调用了多个浏览器,则应该只看到一个带有多个浏览器的配置选项卡。节点需要集线器的IP地址,但如果这有意义,则不需要相反的方式。
https://stackoverflow.com/questions/29284859
复制相似问题