Skip to content

Commit

Permalink
Добавлена автоматическая установка WebDriver
Browse files Browse the repository at this point in the history
  • Loading branch information
Валерий Гуров authored and Valeriy Gourov committed Mar 11, 2022
1 parent 39c2536 commit cbd6827
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 22 deletions.
1 change: 1 addition & 0 deletions Downloader/Downloader.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,6 @@
<PackageReference Include="AngleSharp.Io" Version="0.16.0" />
<PackageReference Include="Jint" Version="2.11.58" />
<PackageReference Include="Selenium.WebDriver" Version="4.1.0" />
<PackageReference Include="WebDriverManager" Version="2.12.3" />
</ItemGroup>
</Project>
11 changes: 9 additions & 2 deletions Downloader/Engine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
using OpenQA.Selenium;
using OpenQA.Selenium.Edge;

using WebDriverManager;
using WebDriverManager.DriverConfigs.Impl;

namespace Downloader;

/// <summary>
Expand Down Expand Up @@ -269,11 +272,15 @@ private bool SetCookies()
/// Создаёт новый экземпляр Selenium WebDriver с требуемыми настройками.
/// </summary>
/// <returns>Новый экземпляр Selenium WebDriver.</returns>
private IWebDriver CreateWebDriver()
private static IWebDriver CreateWebDriver()
{
Console.WriteLine("Установка последней версии WebDriver...");
new DriverManager().SetUpDriver(new EdgeConfig());

Console.WriteLine("Создание экземпляра WebDriver...");
try
{
return new EdgeDriver(_settings.WebDriversPath);
return new EdgeDriver();
}
catch
//catch (DriverServiceNotFoundException exception)
Expand Down
15 changes: 1 addition & 14 deletions Downloader/EngineSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,6 @@ public sealed class EngineSettings : IValidatableObject
[Required]
public string SavePath { get; set; }

/// <summary>
/// Путь к папке с файлами веб-драйверов для Selenium WebDriver.
/// </summary>
[Required]
public string WebDriversPath { get; set; }

/// <inheritdoc/>
public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
{
Expand All @@ -57,13 +51,6 @@ public IEnumerable<ValidationResult> Validate(ValidationContext validationContex
new[] { nameof(SavePath) }));
}

if (!Directory.Exists(WebDriversPath))
{
errors.Add(new ValidationResult(
$"Указанная папка веб-драйверов '{WebDriversPath}' не существует.",
new[] { nameof(WebDriversPath) }));
}

return errors;
}
}
}
6 changes: 0 additions & 6 deletions ItvdnCoursesDownloaderConsole/App.config

This file was deleted.

0 comments on commit cbd6827

Please sign in to comment.