Reputation: 11
I tried to upload a mp4 files, but it's not working. When I tried changing the file from mp4 to mp3, it worked. I also tried using Firefox and Chrome browser to upload mp4 files, and it worked. However, when using Chromium, the mp4 file is neither uploading nor appearing on the screen. Does Chromium not support uploading mp4 files?
Note: The MP4 file without a thumbnail is working and uploading properly; however, if the MP4 file has a thumbnail, it's not working and can't even be attached on the screen.
These are my codes for the main file.
from playwright.sync_api import sync_playwright
from playwright.sync_api import expect
from PageObjectModel.Pages.UserLogin import Login
from PageObjectModel.Pages.VideosFilesUpload import VideosFilesUpload
from constant import STAGING
import json
import os
expect.set_options(timeout=1800000)
def main(playwright):
user_data_dir = './prefs'
pref_file_path = user_data_dir + '/Default/Preferences'
os.makedirs(os.path.dirname(pref_file_path), exist_ok=True)
if not os.path.exists(pref_file_path):
with open(pref_file_path, 'w') as pref_file:
json.dump({}, pref_file)
with open(pref_file_path, 'r') as pref_file:
try:
data = json.load(pref_file)
except json.JSONDecodeError:
data = {} # Initialize the data dictionary
data['devtools'] = {
'preferences': {
'network_log.preserve-log': True,
'network_log.filter': 'Fetch/XHR'
}
}
with open(pref_file_path, 'w') as pref_file:
json.dump(data, pref_file)
browser = playwright.chromium.launch_persistent_context(
user_data_dir,
headless=False,
no_viewport=True,
args=[
'--auto-open-devtools-for-tabs',
'--start-maximized'
]
)
page = browser.new_page()
page.goto(STAGING) #input the url!
#
Login(page)
VideosFilesUpload(page)
print("ENTIRE TEST CASE IS COMPLETED")
with sync_playwright() as playwright:
main(playwright)
These are my codes for the VideosFilesUpload
(Class) file.
from playwright.sync_api import expect
import time
expect.set_options(timeout=1800000)
class VideosFilesUpload():
def __init__(self,page):
self.page = page
self.final_videos_files_upload_execution()
def homepage_click_attachment_icon(self):
open_attachment = self.page.locator("#attachments-button-home")
expect(open_attachment).to_be_visible(timeout=1800000)
expect(open_attachment).to_be_enabled(timeout=1800000)
open_attachment.focus()
open_attachment.click(timeout=1800000)
def navigate_to_transcoder(self):
click_to_redirect_transcoder = self.page.locator("#upload-video-button-home")
expect(click_to_redirect_transcoder).to_be_visible(timeout=1800000)
expect(click_to_redirect_transcoder).to_be_enabled(timeout=1800000)
expect(click_to_redirect_transcoder).to_have_text("Video/Audio" , timeout=1800000)
click_to_redirect_transcoder.focus()
click_to_redirect_transcoder.click(timeout=1800000)
def upload_videos_files_process(self):
upload_process = self.page.locator("#transcoder-input-file-upload")
upload_process.set_input_files("C:\\Users\\Jerome\\Desktop\\Benchmarking\Markets in 3 Minutes_ The Pound's World-Beating Run 3.13.mp4")
expect(upload_process).to_be_attached(timeout=1800000)
def transcoder_click_upload_button(self):
click_upload_button = self.page.locator("#video-upload-btn-video-file")
expect(click_upload_button).to_be_visible(timeout=1800000)
expect(click_upload_button).to_be_enabled(timeout=1800000)
expect(click_upload_button).to_have_text("Upload" , timeout=1800000)
click_upload_button.focus()
click_upload_button.click(timeout=1800000)
def final_videos_files_upload_execution(self):
self.homepage_click_attachment_icon()
self.navigate_to_transcoder()
self.upload_videos_files_process()
self.transcoder_click_upload_button()
print("test videos completed".upper().strip())
Upvotes: 1
Views: 93