[英]The browser is not opened Visual Studio C# Selenium
Although I have no errors, the Browser does not open when I want to run the tests虽然我没有错误,但当我想运行测试时浏览器没有打开
I want to run an older project, I fixed the errors but I don't know why the browser is not open.我想运行一个较旧的项目,我修复了错误,但我不知道为什么浏览器没有打开。
I have: selenium Chrome Selenium Firefox我有:硒 Chrome Selenium Firefox
Console: C:\Program Files\dotnet\dotnet.exe (process 23320) exited with code 0. To automatically close the console when debugging stops, enable Tools->Options->Debugging->Automatically close the console when debugging stops.控制台:C:\Program Files\dotnet\dotnet.exe (process 23320) exited with code 0. 要在调试停止时自动关闭控制台,请启用工具->选项->调试->调试停止时自动关闭控制台。 Press any key to close this window .
按任意键关闭此窗口。 .
. .
.
Output: 'dotnet.exe' (CoreCLR: DefaultDomain): Loaded 'C:\Program Files\dotnet\shared\Microsoft.NETCore.App\3.1.25\System.Private.CoreLib.dll'.输出:“dotnet.exe”(CoreCLR:DefaultDomain):加载“C:\Program Files\dotnet\shared\Microsoft.NETCore.App\3.1.25\System.Private.CoreLib.dll”。 Skipped loading symbols.
跳过加载符号。 Module is optimized and the debugger option 'Just My Code' is enabled.
模块已优化,调试器选项“仅我的代码”已启用。 'dotnet.exe' (CoreCLR: clrhost): Loaded 'C:\Users\Ariana\OneDrive\Desktop\AutomationPractice\AutomationPractice\bin\Debug\netcoreapp3.1\AutomationPractice.dll'.
“dotnet.exe”(CoreCLR:clrhost):已加载“C:\Users\Ariana\OneDrive\Desktop\AutomationPractice\AutomationPractice\bin\Debug\netcoreapp3.1\AutomationPractice.dll”。 Symbols loaded.
已加载符号。 'dotnet.exe' (CoreCLR: clrhost): Loaded 'C:\Program Files\dotnet\shared\Microsoft.NETCore.App\3.1.25\System.Runtime.dll'.
“dotnet.exe”(CoreCLR:clrhost):已加载“C:\Program Files\dotnet\shared\Microsoft.NETCore.App\3.1.25\System.Runtime.dll”。 Skipped loading symbols.
跳过加载符号。 Module is optimized and the debugger option 'Just My Code' is enabled.
模块已优化,调试器选项“仅我的代码”已启用。 The program '[8276]
程序'[8276]
Hooks class:挂钩类:
using NUnit.Framework;
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using OpenQA.Selenium.Firefox;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using TestingProjectWebsite.StepDefinitions;
using Microsoft.Azure.WebJobs.Description;
using TechTalk.SpecFlow;
namespace TestingProjectWebsite
{
public enum BrowserType
{
Chrome,
Firefox
}
[TechTalk.SpecFlow.Binding]
public class Hooks
{
private BrowserType _browserType;
protected static IWebDriver Driver;
[BeforeScenario]
public void BeforeScenario()
{
var browserType = TestContext.Parameters.Get("Browser", "Chrome");
_browserType = (BrowserType)Enum.Parse(typeof(BrowserType), browserType);
if (Driver is null)
{
ChooseDriverInstance(_browserType);
Driver.Manage().Window.Maximize();
}
Driver.Navigate().GoToUrl("http://automationpractice.com/index.php");
}
public void ChooseDriverInstance(BrowserType browserType)
{
switch (browserType)
{
case BrowserType.Chrome:
Driver = new ChromeDriver();
break;
case BrowserType.Firefox:
Driver = new FirefoxDriver();
break;
}
}
[AfterScenario]
public void AfterScenario()
{
if (!(Driver is null))
{
Driver.Quit();
Driver = null;
}
}
}
}
What is strange, in Tes Explorer, my tests are not displayed奇怪的是,在 Tes Explorer 中,我的测试没有显示
Run the test code in debug mode and place the breakpoint at the line where you're initializing the driver.在调试模式下运行测试代码并将断点放置在初始化驱动程序的行。 Chances are that your code is not even going inside the case statement you want it to go.
很有可能您的代码甚至没有进入您希望它进入的 case 语句中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.