Skip to content

Commit

Permalink
feat: download and unpack extension file
Browse files Browse the repository at this point in the history
  • Loading branch information
alicechaitea committed Feb 12, 2024
1 parent 6dfbd94 commit 0171a7a
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 220 deletions.
43 changes: 43 additions & 0 deletions tests/wallet-automation/typhon/convert-to-zip.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import os
import sys
import zipfile

def crx_to_zip(crx_file_path, zip_file_path=None):
if not zip_file_path:
# If no zip file path is provided, use the same location and name as the crx file
zip_file_path = os.path.splitext(crx_file_path)[0] + '.zip'

with open(crx_file_path, 'rb') as crx_file:
# Read the CRX file's header (first 16 bytes)
crx_header = crx_file.read(16)

# The actual zip content starts after the header, so we can skip the header
zip_content = crx_file.read()

# Save the zip content to a new zip file
with open(zip_file_path, 'wb') as zip_file:
zip_file.write(zip_content)

print(f"converted CRX to ZIP: {zip_file_path}")
return zip_file_path

def unzip_file(zip_path, extract_to=None):
if extract_to is None:
extract_to = os.path.dirname(zip_path)

if not os.path.exists(extract_to):
os.makedirs(extract_to)

with zipfile.ZipFile(zip_path, 'r') as zip_ref:
zip_ref.extractall(extract_to)
print(f"Extracted all files in {zip_path} to {extract_to}")

# Combine the operations
if __name__ == "__main__":
if len(sys.argv) != 2:
print("Usage: python script.py <path_to_crx_file>")
sys.exit(1)

crx_path = sys.argv[1]
zip_path = crx_to_zip(crx_path) # Convert CRX to ZIP
unzip_file(zip_path) # Unzip the converted file
4 changes: 2 additions & 2 deletions tests/wallet-automation/typhon/typhon-wallet-download.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as fs from 'fs/promises';
import * as path from 'path';

const url = 'https://clients2.google.com/service/update2/crx?response=redirect&os=win&arch=x64&os_arch=x86_64&nacl_arch=x86-64&prod=chromiumcrx&prodchannel=beta&prodversion=79.0.3945.53&lang=ru&acceptformat=crx3&x=id%3Dkfdniefadaanbjodldohaedphafoffoh%26installsource%3Dondemand%26uc';
const downloadPath = './downloads'; // Ensure this directory exists or add logic to create it
const downloadPath = path.resolve(__dirname, 'extensions'); // Ensure this directory exists or add logic to create it

test('downloadFile test', async ({ page }) => {
// Ensure the download directory exists
Expand All @@ -25,7 +25,7 @@ test('downloadFile test', async ({ page }) => {
timeout: 10000
});
} catch (error) {
console.log('Navigation caused an exception, likely due to immediate download:', error);
console.log('Navigation caused an exception, likely due to immediate download:', 'directDownload');
}

// Wait for the download to complete
Expand Down
50 changes: 0 additions & 50 deletions tests/wallet-automation/typhon/typhon-wallet-logout.ts

This file was deleted.

168 changes: 0 additions & 168 deletions tests/wallet-automation/typhon/typhon-wallet-registration.ts

This file was deleted.

0 comments on commit 0171a7a

Please sign in to comment.