Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/lifailon/deploy-selenium

Deploy drivers selenium and chrome via PowerShell.
https://github.com/lifailon/deploy-selenium

deploy deployment devops devops-tools devtools install installer powershell selenium testing windows

Last synced: 7 days ago
JSON representation

Deploy drivers selenium and chrome via PowerShell.

Awesome Lists containing this project

README

        

## Deploy Selenium ✅ via ▶️ PowerShell

![Image alt](https://github.com/Lifailon/Deploy-Selenium/blob/rsa/Images/logo.jpg)

Automated deployment and updating of all dependencies (Chromium browser, Selenium and Chrome drivers) to be able to work with Selenium library using PowerShell language.

Modules with working examples can be found here ➡️ [Selenium-Modules](https://github.com/Lifailon/Selenium-Modules)

🚀 To quickly install or update all drivers and chromium of the appropriate version, use the following command in your terminal:

```PowerShell
Invoke-Expression(New-Object Net.WebClient).DownloadString("https://raw.githubusercontent.com/Lifailon/Deploy-Selenium/rsa/Deploy-Selenium-Drivers.ps1")
```

### 🎉 Example:

![Image alt](https://github.com/Lifailon/Deploy-Selenium/blob/rsa/Images/example.gif)

### 📚 File composition:

```PowerShell
PS C:\Users\lifailon\Documents\Selenium> Get-ChildItem

Directory: C:\Users\lifailon\Documents\Selenium

Mode LastWriteTime Length Name
---- ------------- ------ ----
d---- 18.10.2023 12:39 chrome-win32
-a--- 26.05.2023 18:39 12273664 chromedriver.exe
-a--- 15.10.2023 16:47 4276224 WebDriver.dll
-a--- 15.10.2023 16:47 33792 WebDriver.Support.dll
```

### 📑 Example connection and work

Example of connecting a set of drivers and working with selenium via PowerShell:

```PowerShell
$path = "$home\Documents\Selenium\"
$log = "$path\ChromeDriver.log"
$ChromeDriver = "$path\ChromeDriver.exe"
$WebDriver = "$path\WebDriver.dll"
$SupportDriver = "$path\WebDriver.Support.dll"
$Chromium = (Get-ChildItem $path -Recurse | Where-Object Name -like chrome.exe).FullName
Add-Type -Path $WebDriver
Add-Type -Path $SupportDriver
try {
$ChromeOptions = New-Object OpenQA.Selenium.Chrome.ChromeOptions # создаем объект с настройками запуска браузера
$ChromeOptions.BinaryLocation = $Chromium # передаем путь до исполняемого файла, который отвечает за запуск браузера
$ChromeOptions.AddArgument("start-maximized") # добавляем аргумент, который позволяет запустить браузер на весь экран
$ChromeOptions.AcceptInsecureCertificates = $True # игнорировать предупреждение на сайтах с не валидным сертификатом
#$ChromeOptions.AddArgument("headless") # скрывать окно браузера при запуске
$ChromeDriverService = [OpenQA.Selenium.Chrome.ChromeDriverService]::CreateDefaultService($ChromeDriver) # создаем объект настроек службы драйвера
$ChromeDriverService.HideCommandPromptWindow = $True # отключаем весь вывод логирования драйвера в консоль (этот вывод нельзя перенаправить)
$ChromeDriverService.LogPath = $log # указать путь до файла с журналом
$ChromeDriverService.EnableAppendLog = $True # не перезаписывать журнал при каждом новом запуске
#$ChromeDriverService.EnableVerboseLogging = $True # кроме INFO и ошибок, записывать DEBUG сообщения
$Selenium = New-Object OpenQA.Selenium.Chrome.ChromeDriver($ChromeDriverService, $ChromeOptions) # инициализируем запуск с указанными настройками

$Selenium.Navigate().GoToUrl("https://google.com")
$Search = $Selenium.FindElements([OpenQA.Selenium.By]::Id('APjFqb'))
$Search = $Selenium.FindElements([OpenQA.Selenium.By]::XPath('//*[@id="APjFqb"]'))
$Search = $Selenium.FindElements([OpenQA.Selenium.By]::Name('q'))
$Search = $Selenium.FindElements([OpenQA.Selenium.By]::XPath('//*[@name="q"]'))
$Search = $Selenium.FindElements([OpenQA.Selenium.By]::ClassName('gLFyf'))
$Search = $Selenium.FindElements([OpenQA.Selenium.By]::CssSelector('[jsname="yZiJbe"]'))
$Search = $Selenium.FindElements([OpenQA.Selenium.By]::TagName('textarea')) | Where-Object ComputedAccessibleRole -eq combobox
$Search.SendKeys("calculator online")
$Search.SendKeys([OpenQA.Selenium.Keys]::Enter)

Start-Sleep 1
$div = $Selenium.FindElements([OpenQA.Selenium.By]::TagName("div"))
$2 = $div | Where-Object {($_.ComputedAccessibleRole -eq "button") -and ($_.ComputedAccessibleLabel -eq "2")}
$2.Click()
$2.Click()
$plus = $div | Where-Object {($_.ComputedAccessibleRole -eq "button") -and ($_.Text -eq "+")}
$plus.Click()
$3 = $Selenium.FindElement([OpenQA.Selenium.By]::CssSelector('[jsname="KN1kY"]'))
$3.Click()
$3.Click()
$sum = $Selenium.FindElement([OpenQA.Selenium.By]::CssSelector('[jsname="Pt8tGc"]'))
$sum.Click()
$result = $Selenium.FindElement([OpenQA.Selenium.By]::CssSelector('[jsname="VssY5c"]')).Text
Write-Host "Result: $result" -ForegroundColor Green
}
finally {
$Selenium.Close()
$Selenium.Quit()
}
```

Search for calculator online in the search string, execute **22+33** using the clicks and output the result to the console:

```PowerShell
PS C:\Users\lifailon> . 'C:\Users\lifailon\Documents\Git\Deploy-Selenium\Selenium-Example.ps1'
Result: 55
```