[英]Run Selenium Grid C# Project in Visual Studio
I'm implemented Nunit selenium C# testing in visual studio (Console Application n Class Library).我在 Visual Studio(控制台应用程序 n 类库)中实现了 Nunit selenium C# 测试。 My project in visual studio is console application.
我在 Visual Studio 中的项目是控制台应用程序。 I started the selenium grid using
我开始使用硒网格
java -Dwebdriver.gecko.driver="..\jar\geckodriver.exe" -Dwebdriver.chrome.driver="..\jar\chromedriver.exe" -Dwebdriver.ie.driver="..\jar\IEDriverServer.exe" -jar ..\jar\selenium-server-standalone-3.14.0.jar -role hub -port 4444
Code:代码:
using Automation_Framework.Manager;
using NUnit.Framework;
using OpenQA.Selenium;
using System;
using System.Collections.Generic;
using System.Text;
namespace Automation_Framework.TestManager
{
[TestFixture]
class ChromeTestManager
{
private WebDriverManager webDriverManager;
private IWebDriver driver;
public ChromeTestManager()
{
webDriverManager = new WebDriverManager();
}
[SetUp]
public void setup()
{
webDriverManager.createDriver("chrome");
driver = webDriverManager.getDriver();
}
[Test]
public void test()
{
driver.Url = "http://www.google.com.my";
driver.Navigate();
}
[TearDown]
public void shutdown()
{
driver.Close();
}
}
}
I had tried execute using Test Explorer but it does not open any browser.我曾尝试使用测试资源管理器执行,但它没有打开任何浏览器。 I"m following this tutorial .
我正在关注本教程。
Questions:问题:
Please help me.请帮我。 Thanks.
谢谢。
I haven't used grid in .Net but here my answer:我没有在 .Net 中使用过网格,但我的回答是:
you need to register your nodes under that hub (different ports) (open a browser and test it is working)您需要在该集线器(不同端口)下注册您的节点(打开浏览器并测试它是否正常工作)
in your code, you should use "RemoteWebDriver" to connect to the hub.在您的代码中,您应该使用“RemoteWebDriver”连接到集线器。 something along these lines (it is in java but I hope it gives you a starting point)
沿着这些路线的东西(它是在java中,但我希望它给你一个起点)
public class Gmail { public WebDriver driver=null; @Parameters("browser") //testng.xml @Test() public void GmailTest(String browser) { System.out.println("Gmail " + browser); // RemoteWebdriver DesiredCapabilities cap = null; if(browser.equals("firefox")){ cap = DesiredCapabilities.firefox(); cap.setBrowserName("firefox"); cap.setPlatform(Platform.ANY); }else if (browser.equals("iexplore")){ cap = DesiredCapabilities.internetExplorer(); cap.setBrowserName("iexplore"); cap.setPlatform(Platform.WINDOWS); } driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"),cap); driver.get("http://gmail.com"); driver.findElement(By.id("Email")).sendKeys("abcd"); driver.quit(); }
I hope this helps.good luck我希望这会有所帮助。祝你好运
I assume that:我假设:
1. You have tried your code locally and your test is opening the browser when you run it on your machine without the grid. 1. 你已经在本地尝试过你的代码,当你在没有网格的机器上运行它时,你的测试正在打开浏览器。
2. Your nodes are set up and registered with the hub. 2. 您的节点已设置并注册到集线器。
You need to:你需要:
1. Use RemoteWebDriver: 1. 使用 RemoteWebDriver:
var uri = 'uri_to_your_grid_hub';
var capabilities = new ChromeOptions().ToCapabilities();
var commandTimeout = TimeSpan.FromMinutes(5);
var driver = new RemoteWebDriver(new Uri(uri),capabilities,commandTimeout)
[Parallelizable(ParallelScope.Self)]
in order to run your tests in parallel with other test classes.[Parallelizable(ParallelScope.Self)]
以便与其他测试类并行运行您的测试。 Sources:资料来源:
How can I run NUnit(Selenium Grid) tests in parallel?
如何并行运行 NUnit(Selenium Grid)测试?
Selenium Grid in C#C#中的硒网格
Useful C# WebDriver examples有用的 C# WebDriver 示例
Selenium Grid set up硒网格设置
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.