Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create antmedia-samples.py #211

Merged
merged 25 commits into from
Jul 17, 2023
Merged
Changes from 24 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
20a08fe
Create antmedia-samples.py
yashtandon113 Feb 6, 2023
7f73283
Update antmedia-samples.py
yashtandon113 Feb 20, 2023
0deeac9
Merge branch 'master' into selenium
yashtandon113 Feb 28, 2023
fbe276c
Update antmedia-samples.py
yashtandon113 Mar 5, 2023
3764eaf
Merge branch 'master' into selenium
yashtandon113 Mar 5, 2023
c48898f
Update antmedia-samples.py
yashtandon113 Mar 5, 2023
2a6140e
Update antmedia-samples.py
yashtandon113 Mar 5, 2023
2ab9078
Update antmedia-samples.py
yashtandon113 Mar 18, 2023
be91c82
Update antmedia-samples.py
yashtandon113 Mar 18, 2023
5a093a3
Update antmedia-samples.py
yashtandon113 Mar 18, 2023
162a912
Update antmedia-samples.py
yashtandon113 Mar 21, 2023
466d675
Update antmedia-samples.py
yashtandon113 Mar 21, 2023
7852de5
Merge branch 'master' into selenium
yashtandon113 Mar 25, 2023
3bc1203
Update antmedia-samples.py
yashtandon113 Apr 14, 2023
7bdc34d
Merge branch 'master' into selenium
yashtandon113 Apr 14, 2023
9ff13a4
Update antmedia-samples.py
yashtandon113 Apr 14, 2023
4b99af7
Update antmedia-samples.py
yashtandon113 Apr 14, 2023
1b0def7
Update antmedia-samples.py
yashtandon113 Apr 20, 2023
55a71f4
Update antmedia-samples.py
yashtandon113 Apr 20, 2023
80ea48e
Update antmedia-samples.py
yashtandon113 Jun 19, 2023
3220810
Merge branch 'master' into selenium
yashtandon113 Jun 19, 2023
c0f3164
Update antmedia-samples.py
yashtandon113 Jun 19, 2023
d0fcbde
Update antmedia-samples.py
yashtandon113 Jun 19, 2023
cc28a1f
Update antmedia-samples.py
yashtandon113 Jun 26, 2023
1f5bda5
Update antmedia-samples.py
yashtandon113 Jul 2, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
311 changes: 311 additions & 0 deletions Selenium/antmedia-samples.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,311 @@
import os
import time
import json
import shlex
import requests
import subprocess
import urllib.parse
from selenium import webdriver
yashtandon113 marked this conversation as resolved.
Show resolved Hide resolved
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.options import Options


# Function to send notification to Slack
def send_slack_message(webhook_url, message, icon_emoji=":x:"):
muratugureminoglu marked this conversation as resolved.
Show resolved Hide resolved
payload = {
"text": message,
"icon_emoji": icon_emoji
}
response = requests.post(webhook_url, data={"payload": json.dumps(payload)})
muratugureminoglu marked this conversation as resolved.
Show resolved Hide resolved

if response.status_code != 200:
print("Error sending Slack message: ", response.text)
else:
print("Slack message sent successfully!")


# Function to start FFMPEG process
def publish_with_ffmpeg(url, protocol='rtmp'):
if protocol == 'rtmp':
# Start FFmpeg process for RTMP streaming
quoted_url = shlex.quote(url)
ffmpeg_command = 'ffmpeg -re -f lavfi -i smptebars -c:v libx264 -preset veryfast -tune zerolatency -profile:v baseline -c:a aac -b:a 128k -t 30 -f flv' + ' ' + quoted_url
ffmpeg_args = shlex.split(ffmpeg_command)
ffmpeg_process = subprocess.Popen(ffmpeg_args, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
muratugureminoglu marked this conversation as resolved.
Show resolved Hide resolved
stdout, stderr = ffmpeg_process.communicate()

elif protocol == 'srt':
# Start FFmpeg process for SRT streaming
quoted_url = urllib.parse.quote(url, safe=':/?=')
ffmpeg_command = 'ffmpeg -f lavfi -re -i smptebars=duration=60:size=1280x720:rate=30 -f lavfi -re -i sine=frequency=1000:duration=60:sample_rate=44100 -pix_fmt yuv420p -c:v libx264 -b:v 1000k -g 30 -keyint_min 120 -profile:v baseline -preset veryfast -t 30 -f mpegts udp://127.0.0.1:5000?pkt_size=1316'
ffmpeg_args = shlex.split(ffmpeg_command)
ffmpeg_process = subprocess.Popen(ffmpeg_args, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
muratugureminoglu marked this conversation as resolved.
Show resolved Hide resolved
srt_command = ['srt-live-transmit', 'udp://127.0.0.1:5000', '-t', '30', quoted_url]
srt_process = subprocess.Popen(srt_command, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
stdout, stderr = ffmpeg_process.communicate()
srt_stdout, srt_stderr = srt_process.communicate()
srt_exit_code = srt_process.returncode
return srt_exit_code


# Function to close the previous tabs before starting the new test
def switch_to_first_tab(driver):
if len(driver.window_handles) > 1:
driver.close()
driver.switch_to.window(driver.window_handles[0])


# Function to switch to new window and close the advertisement block
def switch_window_and_frame(driver):
driver.switch_to.window(driver.window_handles[1])
time.sleep(10)
driver.switch_to.frame(0)
time.sleep(3)


webhook_url = os.environ['WEBHOOK_URL']
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

0% of developers fix this issue

E305: expected 2 blank lines after class or function definition, found 1


ℹ️ Expand to see all @sonatype-lift commands

You can reply with the following commands. For example, reply with @sonatype-lift ignoreall to leave out all findings.

Command Usage
@sonatype-lift ignore Leave out the above finding from this PR
@sonatype-lift ignoreall Leave out all the existing findings from this PR
@sonatype-lift exclude <file|issue|path|tool> Exclude specified file|issue|path|tool from Lift findings by updating your config.toml file

Note: When talking to LiftBot, you need to refresh the page to see its response.
Click here to add LiftBot to another repo.


Help us improve LIFT! (Sonatype LiftBot external survey)

Was this a good recommendation for you? Answering this survey will not impact your Lift settings.

[ 🙁 Not relevant ] - [ 😕 Won't fix ] - [ 😑 Not critical, will fix ] - [ 🙂 Critical, will fix ] - [ 😊 Critical, fixing now ]

icon_emoji = ":x:"

options = Options()
options.add_argument('--headless')
options.add_argument("--use-fake-ui-for-media-stream")
options.add_argument("--use-fake-device-for-media-stream")
driver = webdriver.Chrome(options=options)
driver.maximize_window()

driver.get("https://antmedia.io/webrtc-samples/")

# Testing Virtual Background Sample Page
for i in range(2):
try:
driver.execute_script("window.open('https://antmedia.io/webrtc-samples/webrtc-virtual-background/', '_blank');")
driver.switch_to.window(driver.window_handles[1])
time.sleep(20)
driver.switch_to.frame(0)
time.sleep(3)
driver.find_element(By.XPATH, "/html/body/div/div/div[4]/div[3]/img").click()
yashtandon113 marked this conversation as resolved.
Show resolved Hide resolved
time.sleep(5)
driver.find_element(By.XPATH, "/html/body/div/div/div[7]/button[1]").click()
time.sleep(15)
driver.find_element(By.XPATH, "/html/body/div/div/div[7]/button[2]").click()
time.sleep(3)
print("WebRTC virtual background is successful")
break

except:
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

0% of developers fix this issue

E722: do not use bare 'except'

❗❗ 9 similar findings have been found in this PR

🔎 Expand here to view all instances of this finding
File Path Line Number
Selenium/antmedia-samples.py 124
Selenium/antmedia-samples.py 142
Selenium/antmedia-samples.py 162
Selenium/antmedia-samples.py 187
Selenium/antmedia-samples.py 204
Selenium/antmedia-samples.py 219
Selenium/antmedia-samples.py 237
Selenium/antmedia-samples.py 255
Selenium/antmedia-samples.py 275

Visit the Lift Web Console to find more details in your report.


ℹ️ Expand to see all @sonatype-lift commands

You can reply with the following commands. For example, reply with @sonatype-lift ignoreall to leave out all findings.

Command Usage
@sonatype-lift ignore Leave out the above finding from this PR
@sonatype-lift ignoreall Leave out all the existing findings from this PR
@sonatype-lift exclude <file|issue|path|tool> Exclude specified file|issue|path|tool from Lift findings by updating your config.toml file

Note: When talking to LiftBot, you need to refresh the page to see its response.
Click here to add LiftBot to another repo.


Help us improve LIFT! (Sonatype LiftBot external survey)

Was this a good recommendation for you? Answering this survey will not impact your Lift settings.

[ 🙁 Not relevant ] - [ 😕 Won't fix ] - [ 😑 Not critical, will fix ] - [ 🙂 Critical, will fix ] - [ 😊 Critical, fixing now ]

if i==1:
muratugureminoglu marked this conversation as resolved.
Show resolved Hide resolved
message = "Virtual background test is failed, check -> https://antmedia.io/webrtc-samples/webrtc-virtual-background/"
send_slack_message(webhook_url, message, icon_emoji)
continue

switch_to_first_tab(driver)

# Testing WebRTC and HLS Comparison Live Demo Page
try:
driver.execute_script("window.open('https://antmedia.io/live-demo/', '_blank');")
driver.switch_to.window(driver.window_handles[1])
time.sleep(20)
driver.find_element(By.XPATH, "/html/body/div/div/article[2]/div[2]/div[1]/div[1]/div/div/p/button[1]").click()
time.sleep(15)
driver.find_element(By.XPATH, "/html/body/div/div/article[2]/div[2]/div[1]/div[1]/div/div/p/button[1]").click()
time.sleep(3)
print("Live demo is successful")

except:
message = "Livedemo test is failed, check -> https://antmedia.io/live-demo/"
send_slack_message(webhook_url, message, icon_emoji)

switch_to_first_tab(driver)

# Testing WebRTC to WebRTC Sample Page
try:
driver.execute_script("window.open('https://antmedia.io/webrtc-samples/webrtc-publish-webrtc-play/', '_blank');")
switch_window_and_frame(driver)
driver.find_element(By.XPATH, "/html/body/div/div/div[8]/button[1]").click()
time.sleep(10)
driver.find_element(By.XPATH, "/html/body/div/div/div[7]/div[1]/a").click()
time.sleep(5)
driver.find_element(By.XPATH, "/html/body/div/div/div[8]/button[2]").click()
time.sleep(3)
print("WebRTC to WebRTC is successful")

except:
message = "WebRTC to WebRTC test is failed, check -> https://antmedia.io/webrtc-samples/webrtc-publish-webrtc-play/"
send_slack_message(webhook_url, message, icon_emoji)

driver.close()
driver.switch_to.window(driver.window_handles[1])
switch_to_first_tab(driver)

# Testing WebRTC to HLS Sample Page
try:
driver.execute_script("window.open('https://antmedia.io/webrtc-samples/webrtc-publish-hls-play/', '_blank');")
switch_window_and_frame(driver)
driver.find_element(By.XPATH, "/html/body/div/div/div[8]/button[1]").click()
time.sleep(10)
driver.find_element(By.XPATH, "/html/body/div/div/div[7]/div[1]/a").click()
time.sleep(5)
driver.find_element(By.XPATH, "/html/body/div/div/div[8]/button[2]").click()
time.sleep(5)
print("WebRTC to HLS is successful")

except:
message = "WebRTC to HLS test is failed, check -> https://antmedia.io/webrtc-samples/webrtc-publish-hls-play/"
send_slack_message(webhook_url, message, icon_emoji)

driver.close()
driver.switch_to.window(driver.window_handles[1])
switch_to_first_tab(driver)

# Testing WebRTC audio publish sample page
try:
driver.execute_script("window.open('https://antmedia.io/webrtc-samples/webrtc-audio-publish-play/', '_blank');")
switch_window_and_frame(driver)
driver.find_element(By.XPATH, "/html/body/div/div/div[6]/button[1]").click()
time.sleep(3)
driver.find_element(By.XPATH, "/html/body/div/div/div[5]/div[1]/a").click()
driver.switch_to.window(driver.window_handles[2])
time.sleep(2)
driver.switch_to.frame(0)
time.sleep(2)
driver.find_element(By.XPATH, "/html/body/div/div/div[4]/button[1]").click()
time.sleep(10)
driver.find_element(By.XPATH, "/html/body/div/div/div[4]/button[2]").click()
time.sleep(2)
print("WebRTC audio publish and play is successful")

except:
message = "WebRTC audio publish test is failed, check -> https://antmedia.io/webrtc-samples/webrtc-audio-publish-play/"
send_slack_message(webhook_url, message, icon_emoji)

driver.close()
driver.switch_to.window(driver.window_handles[1])
switch_to_first_tab(driver)

# Testing RTMP to WebRTC sample page
try:
driver.execute_script("window.open('https://antmedia.io/webrtc-samples/rtmp-publish-webrtc-play/', '_blank');")
yashtandon113 marked this conversation as resolved.
Show resolved Hide resolved
switch_window_and_frame(driver)
rtmp_element = driver.find_element(By.XPATH, "/html/body/div/div/div[3]/div[1]/div")
url = rtmp_element.text
publish_with_ffmpeg(url, protocol='rtmp')
print("RTMP to WebRTC is successful")

except:
message = "RTMP to WebRTC test is failed, check -> https://antmedia.io/webrtc-samples/rtmp-publish-wertc-play/"
send_slack_message(webhook_url, message, icon_emoji)

switch_to_first_tab(driver)

# Testing RTMP to HLS sample page
try:
driver.execute_script("window.open('https://antmedia.io/webrtc-samples/rtmp-publish-hls-play/', '_blank');")
switch_window_and_frame(driver)
rtmp_element = driver.find_element(By.XPATH, "/html/body/div/div/div[3]/div[1]/div")
url = rtmp_element.text
publish_with_ffmpeg(url, protocol='rtmp')
print("RTMP to HLS is successful")

except:
message = "RTMP to HLS test is failed, check -> https://antmedia.io/webrtc-samples/rtmp-publish-hls-play/"
send_slack_message(webhook_url, message, icon_emoji)

switch_to_first_tab(driver)

# Testing SRT to WebRTC sample page
try:
driver.execute_script("window.open('https://antmedia.io/webrtc-samples/srt-publish-webrtc-play/', '_blank');")
switch_window_and_frame(driver)
srt_element = driver.find_element(By.XPATH, "/html/body/div/div/div[3]/div[1]/div")
url = srt_element.text
srt_exit_code = publish_with_ffmpeg(url, protocol='srt')
if srt_exit_code == 0:
print("SRT to WebRTC is successful")
else:
raise Exception("SRT to WebRTC test is failed")

except:
message = "SRT to WebRTC test is failed, check -> https://antmedia.io/webrtc-samples/srt-publish-webrtc-play/"
send_slack_message(webhook_url, message, icon_emoji)

switch_to_first_tab(driver)

# Testing SRT to HLS sample page
try:
driver.execute_script("window.open('https://antmedia.io/webrtc-samples/srt-publish-hls-play/', '_blank');")
switch_window_and_frame(driver)
srt_element = driver.find_element(By.XPATH, "/html/body/div/div/div[3]/div[1]/div")
url = srt_element.text
srt_exit_code = publish_with_ffmpeg(url, protocol='srt')
if srt_exit_code == 0:
print("SRT to HLS is successful")
else:
raise Exception("SRT to HLS test is failed")

except:
message = "SRT to HLS test is failed, check -> https://antmedia.io/webrtc-samples/srt-publish-hls-play/"
send_slack_message(webhook_url, message, icon_emoji)

switch_to_first_tab(driver)

# Testing DeepAR sample page
try:
driver.execute_script("window.open('https://antmedia.io/webrtc-samples/deepar-publish-play/', '_blank');")
switch_window_and_frame(driver)
driver.find_element(By.XPATH, "/html/body/div/div/select").click()
time.sleep(1)
driver.find_element(By.XPATH, "/html/body/div[1]/div/select/option[6]").click()
time.sleep(1)
driver.find_element(By.XPATH, "/html/body/div[1]/div/div[5]/button[1]").click()
time.sleep(10)
driver.find_element(By.XPATH, "/html/body/div[1]/div/div[5]/button[2]").click()
print("WebRTC Deep AR test is successful")

except:
message = "WebRTC DeepAR sample test is failed, check -> https://antmedia.io/webrtc-samples/deepar-publish-play/"
send_slack_message(webhook_url, message, icon_emoji)

switch_to_first_tab(driver)

try:
driver.execute_script("window.open('https://antmedia.io/webrtc-samples/interactive-whiteboard-publish-play/', '_blank');")
yashtandon113 marked this conversation as resolved.
Show resolved Hide resolved
switch_window_and_frame(driver)
driver.switch_to.frame("webrtc-publish-frame")
time.sleep(1)
driver.find_element(By.XPATH, "/html/body/div[2]/div/div/div/div[2]/div[6]/button[1]").click()
time.sleep(5)
driver.switch_to.frame(0)
driver.find_element(By.XPATH, "/html/body/section[2]/canvas[4]").click()
time.sleep(2)
driver.switch_to.default_content()
driver.switch_to.frame(0)
driver.switch_to.frame("webrtc-play-frame")
driver.find_element(By.XPATH, "/html/body/div[2]/div/div/div/div[3]/div[4]/button[1]").click()
time.sleep(10)
print("WebRTC white board test is successful")

except:
message = "WebRTC whiteboard test is failed, check -> https://antmedia.io/webrtc-samples/interactive-whiteboard-publish-play/"
send_slack_message(webhook_url, message, icon_emoji)

switch_to_first_tab(driver)

# Testing WebRTC data channel sample page
try:
driver.execute_script("window.open('https://antmedia.io/webrtc-samples/webrtc-data-channel-only/', '_blank');")
switch_window_and_frame(driver)
driver.find_element(By.XPATH, "/html/body/div/div/div[6]/button[1]").click()
time.sleep(5)
text = driver.find_element(By.ID, 'dataTextbox')
text.send_keys("Hello, how are you ?")
driver.find_element(By.XPATH, "/html/body/div/div/div[3]/div/div[2]/button").click()
time.sleep(20)
driver.find_element(By.XPATH, "/html/body/div/div/div[6]/button[2]").click()
time.sleep(3)
print("WebRTC data channel is successful")

except:
message = "WebRTC data channel test is failed, check -> https://antmedia.io/webrtc-samples/webrtc-data-channel-only/"
send_slack_message(webhook_url, message, icon_emoji)

driver.quit()