From 98c4347db3d682c97acdb6209ddeae858f6b2600 Mon Sep 17 00:00:00 2001 From: Ayushman Chhabra <14110965+ayushmanchhabra@users.noreply.github.com> Date: Sat, 20 Apr 2024 13:12:52 +0530 Subject: [PATCH] hope --- py/selenium/service_builder/test.py | 39 ++++++++++++++++++++++++++--- requirements.txt | 1 + 2 files changed, 37 insertions(+), 3 deletions(-) diff --git a/py/selenium/service_builder/test.py b/py/selenium/service_builder/test.py index 5371c93..f5f4c3d 100644 --- a/py/selenium/service_builder/test.py +++ b/py/selenium/service_builder/test.py @@ -1,5 +1,9 @@ +import json +import platform import os import sys +import semver + from unittest import TestCase from selenium import webdriver @@ -15,15 +19,44 @@ class TestWindow(TestCase): Setup Selenium driver. ''' def setUp(self): + + with open('./package.json') as f: + pkg = json.load(f) + + dependencies = pkg.get('devDependencies', {}) + version = dependencies['nw'] + version = semver.VersionInfo.parse(version[1:]) + version = f"{version.major}.{version.minor}.{version.patch}" + + host_platform = '' + if (sys.platform == 'linux'): + host_platform = 'linux' + if (sys.platform == 'win32'): + host_platform = 'win' + if (sys.platform == 'darwin'): + host_platform = 'osx' + + host_arch = '' + if (platform.machine() == 'x86_64' or platform.machine() == 'AMD64'): + host_arch = 'x64' + if (platform.machine() == 'i686'): + host_arch = 'ia32' + if (platform.machine() == 'arm64'): + host_arch = 'arm64' + + nwjs_dir = f"nwjs-sdk-v{version}-{host_platform}-{host_arch}" # We are using the nw node module to download NW.js # Change the path as necessary - # "./node_modules/nw/nwjs/chromedriver" - chromedriver_path = Path('node_modules', 'nw', 'nwjs', 'chromedriver') + + chromedriver_path = Path('node_modules', 'nw', nwjs_dir, 'chromedriver') chromedriver_path = str(chromedriver_path.resolve()) - if sys.platform == "win": + if sys.platform == "win32": chromedriver_path += ".exe" + print(platform.machine()) + print(chromedriver_path) + options = webdriver.ChromeOptions() # File path to NW.js project options.add_argument("nwapp=" + str(Path('py', 'selenium', 'service_builder').resolve())) diff --git a/requirements.txt b/requirements.txt index 9207bf5..eadca1b 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,4 @@ selenium == 4.16.0 +semver == 3.0.2 pytest == 7.4.3 urllib3 == 2.2.1