mirror of
https://forge.fsky.io/oneflux/omegafox.git
synced 2026-02-10 18:32:06 -08:00
Makefile: Add run-pw to test Playwright
This commit is contained in:
parent
e155a3285e
commit
eeb9cb3b60
2 changed files with 64 additions and 1 deletions
7
Makefile
7
Makefile
|
|
@ -60,7 +60,7 @@ dir:
|
|||
@if [ ! -d $(cf_source_dir) ]; then \
|
||||
make setup; \
|
||||
fi
|
||||
make clean
|
||||
make revert
|
||||
python3 scripts/patch.py $(version) $(release)
|
||||
touch $(cf_source_dir)/_READY
|
||||
|
||||
|
|
@ -137,6 +137,11 @@ package-windows:
|
|||
--arch $(arch) \
|
||||
--fonts macos linux
|
||||
|
||||
run-pw:
|
||||
python3 scripts/run-pw.py \
|
||||
--version $(version) \
|
||||
--release $(release)
|
||||
|
||||
run:
|
||||
cd $(cf_source_dir) && rm -rf ~/.camoufox && ./mach run
|
||||
|
||||
|
|
|
|||
58
scripts/run-pw.py
Normal file
58
scripts/run-pw.py
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
import argparse
|
||||
import os
|
||||
import time
|
||||
|
||||
from _mixin import find_src_dir, get_moz_target, temp_cd
|
||||
from playwright.sync_api import sync_playwright
|
||||
|
||||
|
||||
def launch_playwright(executable_path):
|
||||
"""Launch playwright Firefox with unlimited time"""
|
||||
with sync_playwright() as p:
|
||||
print('Launching browser.')
|
||||
browser = p.firefox.launch(executable_path=executable_path, headless=False)
|
||||
page = browser.new_page()
|
||||
url = os.getenv('URL') or 'https://google.com'
|
||||
page.goto(url)
|
||||
try:
|
||||
time.sleep(1e9)
|
||||
except:
|
||||
print('Closing...')
|
||||
finally:
|
||||
browser.close()
|
||||
|
||||
|
||||
def get_args():
|
||||
"""Get CLI parameters"""
|
||||
parser = argparse.ArgumentParser(
|
||||
description='Package Camoufox for different operating systems.'
|
||||
)
|
||||
parser.add_argument('--version', required=True, help='Camoufox version')
|
||||
parser.add_argument('--release', required=True, help='Camoufox release number')
|
||||
return parser.parse_args()
|
||||
|
||||
|
||||
def main():
|
||||
"""Run the browser with Playwright"""
|
||||
args = get_args()
|
||||
|
||||
src_dir = find_src_dir('.', args.version, args.release)
|
||||
moz_target = get_moz_target(target='linux', arch='x86_64')
|
||||
|
||||
with temp_cd(src_dir):
|
||||
print(f'Looking for file: obj-{moz_target}/dist/bin/camoufox-bin')
|
||||
with temp_cd(f'obj-{moz_target}/dist/bin'):
|
||||
if os.path.exists('camoufox-bin'):
|
||||
file_name = 'camoufox-bin'
|
||||
elif os.path.exists('firefox-bin'):
|
||||
file_name = 'firefox-bin'
|
||||
else:
|
||||
raise FileNotFoundError(f'Binary not found: obj-{moz_target}/dist/bin')
|
||||
file_path = os.path.abspath(f'obj-{moz_target}/dist/bin/{file_name}')
|
||||
|
||||
with temp_cd(os.path.dirname(file_path)):
|
||||
launch_playwright(file_path)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
Loading…
Add table
Reference in a new issue