简体   繁体   English

浏览器未打开 Visual Studio C# Selenium

[英]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.

相关问题 在C#中使用Selenium而不在Visual Studio 2013中打开浏览器 - Using Selenium in C# without opening a browser in Visual Studio 2013 在Visual Studio中使用Selenium C#关闭和打开浏览器 - Close and open browser with Selenium C# in Visual Studio Selenium Webdriver带有C#和Visual Studio的dependsOnMethod - Selenium Webdriver dependsOnMethod with C# and Visual Studio 如何使用Visual Studio中的Selenium在C#中的私有IE浏览器中运行测试? - How can I run a test in a private IE browser in C#, using Selenium in Visual Studio? Visual Studio 2010 C#中不受支持的浏览器 - Unsupported browser in visual studio 2010 C# 可以使用Microsoft Visual Studio 2005 C#打开其他版本的Microsoft Visual Studio吗? - Can other version of Microsoft Visual Studio be opened with Microsoft Visual Studio 2005 C#? 使用C#与Selenium WebDriver和NUnit一起调试Visual Studio 2013 - Debug Visual Studio 2013 Using C# with Selenium WebDriver and NUnit 如何使用Visual Studio在C#中创建硒测试 - how to create a test for selenium in C# using visual studio C# Visual Studio selenium for edge OS version18362 - C# visual studio selenium for edge OS version18362 Selenium WebDriver C#Visual Studio N单元测试名称 - Selenium WebDriver C# Visual Studio N Unit Test Name
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM