Skip to content

Commit

Permalink
gh #330 add brave selenium test and brave browser to CI
Browse files Browse the repository at this point in the history
- adopt for brave beta and nightly channels for linux
- determine compatible chromedriver for Brave by browser's major version
- add selemium test for brave
- to snake_case naming of Brave test functions
- add Brave installation on Mac/Win/Linux in CI for selenium test
  • Loading branch information
aleksandr-kotlyar committed Feb 28, 2022
1 parent a28e1bb commit aec5bcb
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 13 deletions.
12 changes: 9 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ jobs:
if: runner.os == 'Linux'
run: |
sudo apt-get update
sudo apt-get install software-properties-common apt-transport-https wget
sudo apt-get install software-properties-common apt-transport-https wget curl
wget -q https://packages.microsoft.com/keys/microsoft.asc -O- | sudo apt-key add -
sudo add-apt-repository "deb [arch=amd64] https://packages.microsoft.com/repos/edge stable main"
Expand All @@ -76,19 +76,25 @@ jobs:
sudo apt-get install chromium-browser
chromium --version
sudo curl -fsSLo /usr/share/keyrings/brave-browser-archive-keyring.gpg https://brave-browser-apt-release.s3.brave.com/brave-browser-archive-keyring.gpg
echo "deb [signed-by=/usr/share/keyrings/brave-browser-archive-keyring.gpg arch=amd64] https://brave-browser-apt-release.s3.brave.com/ stable main"|sudo tee /etc/apt/sources.list.d/brave-browser-release.list
sudo apt-get update
sudo apt-get install brave-browser
brave-browser --version
- name: Install browsers on Windows
if: runner.os == 'Windows'
shell: powershell
run: |
choco install chromium opera --no-progress -y --force
choco install chromium opera brave --no-progress -y --force
- name: Install browsers on MacOS
if: startsWith(runner.os, 'macOS')
run: |
brew tap domt4/chromium
brew update
brew install --cask mac-chromium opera
brew install --cask mac-chromium opera brave-browser
- name: Install Python dependencies
run: |
Expand Down
24 changes: 20 additions & 4 deletions tests/test_brave_driver.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import os

import pytest
from selenium import webdriver

from webdriver_manager.chrome import ChromeDriverManager
from webdriver_manager.utils import ChromeType
from webdriver_manager.utils import ChromeType, os_name, OSType


def test_driver_with_ssl_verify_disabled_can_be_downloaded(ssl_verify_enable):
Expand All @@ -21,11 +22,26 @@ def test_driver_with_ssl_verify_disabled_can_be_downloaded(ssl_verify_enable):
assert os.path.exists(driver_path)


def test_BRAVE_manager_with_specific_version():
def test_brave_manager_with_specific_version():
bin_path = ChromeDriverManager("2.27", chrome_type=ChromeType.BRAVE).install()
assert os.path.exists(bin_path)


def test_brave_manager_with_selenium():
binary_location = {
OSType.LINUX: "/usr/bin/brave-browser",
OSType.MAC: "/Applications/Brave Browser.app/Contents/MacOS/Brave Browser",
OSType.WIN: "$env:LOCALAPPDATA\\AppData\\Local\\BraveSoftware\\Brave-Browser\\Application",
}[os_name()]
option = webdriver.ChromeOptions()
option.binary_location = binary_location
driver_path = ChromeDriverManager(chrome_type=ChromeType.BRAVE).install()
driver = webdriver.Chrome(driver_path, options=option)

driver.get("http://automation-remarks.com")
driver.close()


def test_driver_can_be_saved_to_custom_path():
custom_path = os.path.join(os.path.dirname(os.path.dirname(__file__)), "custom")

Expand All @@ -35,14 +51,14 @@ def test_driver_can_be_saved_to_custom_path():
assert custom_path in path


def test_BRAVE_manager_with_wrong_version():
def test_brave_manager_with_wrong_version():
with pytest.raises(ValueError) as ex:
ChromeDriverManager("0.2", chrome_type=ChromeType.BRAVE).install()
assert "There is no such driver by url" in ex.value.args[0]


@pytest.mark.parametrize('os_type', ['win32', 'win64'])
def test_can_get_BRAVE_for_win(os_type):
def test_can_get_brave_for_win(os_type):
path = ChromeDriverManager(version="83.0.4103.39", os_type=os_type,
chrome_type=ChromeType.BRAVE).install()
assert os.path.exists(path)
15 changes: 9 additions & 6 deletions webdriver_manager/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,11 +154,14 @@ def windows_browser_apps_to_cmd(*apps: str) -> str:

def get_browser_version_from_os(browser_type=None):
"""Return installed browser version."""
pattern = (
r'(\d+.\d+)'
if browser_type == 'firefox'
else r'\d+\.\d+\.\d+'
)

pattern = {
ChromeType.CHROMIUM: r'\d+\.\d+\.\d+',
ChromeType.GOOGLE: r'\d+\.\d+\.\d+',
ChromeType.MSEDGE: r'\d+\.\d+\.\d+',
'brave-browser': r'(\d+)',
'firefox': r'(\d+.\d+)',
}[browser_type]

cmd_mapping = {
ChromeType.GOOGLE: {
Expand All @@ -184,7 +187,7 @@ def get_browser_version_from_os(browser_type=None):
),
},
ChromeType.BRAVE: {
OSType.LINUX: linux_browser_apps_to_cmd('brave-browser', 'brave-browser-stable', 'brave-browser-beta', 'brave-browser-dev'),
OSType.LINUX: linux_browser_apps_to_cmd('brave-browser', 'brave-browser-beta', 'brave-browser-nightly'),
OSType.MAC: r'/Applications/Brave\ Browser.app/Contents/MacOS/Brave\ Browser --version',
OSType.WIN: windows_browser_apps_to_cmd(
r'(Get-Item -Path "$env:PROGRAMFILES\BraveSoftware\Brave-Browser\Application\brave.exe").VersionInfo.FileVersion',
Expand Down

0 comments on commit aec5bcb

Please sign in to comment.