-
-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Moved automated-testing to browser-extension - Added requirements.txt to reduce setup steps - Updated slur detection scripts for chrome, firefox - Added slur detection scripts for brave, chromium, edge - Updated gitignore
- Loading branch information
Showing
14 changed files
with
310 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
node_modules/ | ||
.scannerwork | ||
automated-testing/venv* | ||
automated-testing/firefox/geckodriver.log |
File renamed without changes.
75 changes: 75 additions & 0 deletions
75
browser-extension/automated-testing/brave/slur_detection_tester_brave.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
from selenium import webdriver | ||
from selenium.webdriver.chrome.service import Service | ||
from webdriver_manager.chrome import ChromeDriverManager | ||
from webdriver_manager.core.os_manager import ChromeType | ||
from selenium.common.exceptions import NoSuchElementException | ||
from selenium.webdriver.common.by import By | ||
|
||
from selenium.webdriver.common.alert import Alert | ||
from selenium.webdriver.support.ui import WebDriverWait | ||
from selenium.webdriver.support import expected_conditions as EC | ||
|
||
from time import sleep | ||
from selenium.webdriver.remote.webelement import WebElement | ||
|
||
|
||
# function to expand the shadow element to get the extension id on chrome://extensions | ||
def expand_shadow_element(element): | ||
shadow_root = driver.execute_script('return arguments[0].shadowRoot', element) | ||
print("expand_shadow_element executed!") | ||
return shadow_root | ||
|
||
# Configure the necessary command-line option | ||
options = webdriver.ChromeOptions() | ||
|
||
# TODO: Note that you will need to download the build of the extension and put the path to the dist folder | ||
options.add_argument(r'--load-extension=/path/to/extension/dist/') | ||
|
||
# installing chromedriver | ||
driver = webdriver.Chrome(service=Service(ChromeDriverManager(chrome_type=ChromeType.BRAVE).install()), options = options) | ||
sleep(2) | ||
|
||
# loading the extensions page to get extension id | ||
driver.get('chrome://extensions') | ||
sleep(5) | ||
|
||
# workflow with the chrome extensions page and its shadow elements | ||
root1 = driver.find_element(By.TAG_NAME, 'extensions-manager') | ||
shadow_root_1 = expand_shadow_element(root1) | ||
root2 = shadow_root_1.find_element(By.CSS_SELECTOR, 'extensions-item-list') | ||
shadow_root_2 = expand_shadow_element(root2) | ||
ele = shadow_root_2.find_element(By.CSS_SELECTOR, 'extensions-item') | ||
extension_id = ele.get_attribute("id") | ||
print(str(extension_id)) # printing the extension id | ||
|
||
# going to the extensions page | ||
url = "chrome-extension://" + extension_id + "/options.html" | ||
driver.get(url) | ||
|
||
# activate plugin | ||
activate_button = driver.find_element('id', 'app_btn_activate') #activating account | ||
activate_button.click() | ||
|
||
# Confirm page reload on activation | ||
WebDriverWait(driver, 10).until(EC.alert_is_present()) | ||
driver.switch_to.alert.accept() | ||
|
||
# Save settings | ||
save_button = driver.find_element('id', 'app_btn_save') #saving the settings | ||
save_button.click() | ||
|
||
# add a hardcoded url leading to a particular tweet which you are using for testing | ||
driver.get('https://twitter.com/jackantonoff/status/1579311659742416896') | ||
sleep(20) | ||
# Check if the extension worked and log the result. | ||
try: | ||
# logic to check if the slur is replaced | ||
ele = driver.find_element('xpath','//div[contains(text(),"▓")]') | ||
print('Success! :-)') | ||
# if no such span is present where the character - ▓ - is not present then the Failure message will show up | ||
# Note that this will return success if the tweet by default contains the replacement character | ||
except NoSuchElementException: | ||
print('Failure! :-(') | ||
finally: | ||
''' Clean up. ''' | ||
driver.quit() |
File renamed without changes.
File renamed without changes.
File renamed without changes.
76 changes: 76 additions & 0 deletions
76
browser-extension/automated-testing/chrome/slur_detection_tester_chrome.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
from selenium import webdriver | ||
from selenium.webdriver.chrome.service import Service | ||
from webdriver_manager.chrome import ChromeDriverManager | ||
from webdriver_manager.core.os_manager import ChromeType | ||
from selenium.common.exceptions import NoSuchElementException | ||
from selenium.webdriver.common.by import By | ||
|
||
from selenium.webdriver.common.alert import Alert | ||
from selenium.webdriver.support.ui import WebDriverWait | ||
from selenium.webdriver.support import expected_conditions as EC | ||
|
||
from time import sleep | ||
from selenium.webdriver.remote.webelement import WebElement | ||
|
||
|
||
# function to expand the shadow element to get the extension id on chrome://extensions | ||
def expand_shadow_element(element): | ||
shadow_root = driver.execute_script('return arguments[0].shadowRoot', element) | ||
print("expand_shadow_element executed!") | ||
return shadow_root | ||
|
||
|
||
# Configure the necessary command-line option | ||
options = webdriver.ChromeOptions() | ||
|
||
# TODO: Note that you will need to download the build of the extension and put the path to the dist folder | ||
options.add_argument(r'--load-extension=/path/to/extension/dist/') | ||
|
||
# installing chromedriver | ||
driver = webdriver.Chrome(service=Service(ChromeDriverManager(chrome_type=ChromeType.GOOGLE).install()), options = options) | ||
sleep(2) | ||
|
||
# loading the extensions page to get extension id | ||
driver.get('chrome://extensions') | ||
sleep(5) | ||
|
||
# workflow with the chrome extensions page and its shadow elements | ||
root1 = driver.find_element(By.TAG_NAME, 'extensions-manager') | ||
shadow_root_1 = expand_shadow_element(root1) | ||
root2 = shadow_root_1.find_element(By.CSS_SELECTOR, 'extensions-item-list') | ||
shadow_root_2 = expand_shadow_element(root2) | ||
ele = shadow_root_2.find_element(By.CSS_SELECTOR, 'extensions-item') | ||
extension_id = ele.get_attribute("id") | ||
print(str(extension_id)) # printing the extension id | ||
|
||
# going to the extensions page | ||
url = "chrome-extension://" + extension_id + "/options.html" | ||
driver.get(url) | ||
|
||
# activate plugin | ||
activate_button = driver.find_element('id', 'app_btn_activate') #activating account | ||
activate_button.click() | ||
|
||
# Confirm page reload on activation | ||
WebDriverWait(driver, 10).until(EC.alert_is_present()) | ||
driver.switch_to.alert.accept() | ||
|
||
# Save settings | ||
save_button = driver.find_element('id', 'app_btn_save') #saving the settings | ||
save_button.click() | ||
|
||
# add a hardcoded url leading to a particular tweet which you are using for testing | ||
driver.get('https://twitter.com/jackantonoff/status/1579311659742416896') | ||
sleep(20) | ||
# Check if the extension worked and log the result. | ||
try: | ||
# logic to check if the slur is replaced | ||
ele = driver.find_element('xpath','//div[contains(text(),"▓")]') | ||
print('Success! :-)') | ||
# if no such span is present where the character - ▓ - is not present then the Failure message will show up | ||
# Note that this will return success if the tweet by default contains the replacement character | ||
except NoSuchElementException: | ||
print('Failure! :-(') | ||
finally: | ||
''' Clean up. ''' | ||
driver.quit() |
75 changes: 75 additions & 0 deletions
75
browser-extension/automated-testing/chromium/slur_detection_tester_chromium.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
from selenium import webdriver | ||
from selenium.webdriver.chrome.service import Service | ||
from webdriver_manager.chrome import ChromeDriverManager | ||
from webdriver_manager.core.os_manager import ChromeType | ||
from selenium.common.exceptions import NoSuchElementException | ||
from selenium.webdriver.common.by import By | ||
|
||
from selenium.webdriver.common.alert import Alert | ||
from selenium.webdriver.support.ui import WebDriverWait | ||
from selenium.webdriver.support import expected_conditions as EC | ||
|
||
from time import sleep | ||
from selenium.webdriver.remote.webelement import WebElement | ||
|
||
|
||
# function to expand the shadow element to get the extension id on chrome://extensions | ||
def expand_shadow_element(element): | ||
shadow_root = driver.execute_script('return arguments[0].shadowRoot', element) | ||
print("expand_shadow_element executed!") | ||
return shadow_root | ||
|
||
|
||
# Configure the necessary command-line option | ||
options = webdriver.ChromeOptions() | ||
# TODO: Note that you will need to download the build of the extension and put the path to the dist folder | ||
options.add_argument(r'--load-extension=/path/to/extension/dist/') | ||
|
||
# installing chromedriver | ||
driver = webdriver.Chrome(service=Service(ChromeDriverManager(chrome_type=ChromeType.CHROMIUM).install()), options = options) | ||
sleep(2) | ||
|
||
# loading the extensions page to get extension id | ||
driver.get('chrome://extensions') | ||
sleep(5) | ||
|
||
# workflow with the chrome extensions page and its shadow elements | ||
root1 = driver.find_element(By.TAG_NAME, 'extensions-manager') | ||
shadow_root_1 = expand_shadow_element(root1) | ||
root2 = shadow_root_1.find_element(By.CSS_SELECTOR, 'extensions-item-list') | ||
shadow_root_2 = expand_shadow_element(root2) | ||
ele = shadow_root_2.find_element(By.CSS_SELECTOR, 'extensions-item') | ||
extension_id = ele.get_attribute("id") | ||
print(str(extension_id)) # printing the extension id | ||
|
||
# going to the extensions page | ||
url = "chrome-extension://" + extension_id + "/options.html" | ||
driver.get(url) | ||
|
||
# activate plugin | ||
activate_button = driver.find_element('id', 'app_btn_activate') #activating account | ||
activate_button.click() | ||
|
||
# Confirm page reload on activation | ||
WebDriverWait(driver, 10).until(EC.alert_is_present()) | ||
driver.switch_to.alert.accept() | ||
|
||
# Save settings | ||
save_button = driver.find_element('id', 'app_btn_save') #saving the settings | ||
save_button.click() | ||
|
||
# add a hardcoded url leading to a particular tweet which you are using for testing | ||
driver.get('https://twitter.com/jackantonoff/status/1579311659742416896') | ||
sleep(20) | ||
# Check if the extension worked and log the result. | ||
try: | ||
# logic to check if the slur is replaced | ||
ele = driver.find_element('xpath','//div[contains(text(),"▓")]') | ||
print('Success! :-)') | ||
# if no such span is present where the character - ▓ - is not present then the Failure message will show up | ||
# Note that this will return success if the tweet by default contains the replacement character | ||
except NoSuchElementException: | ||
print('Failure! :-(') | ||
finally: | ||
''' Clean up. ''' | ||
driver.quit() |
75 changes: 75 additions & 0 deletions
75
browser-extension/automated-testing/edge/slur_detection_tester_edge.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
from selenium import webdriver | ||
from selenium.webdriver.edge.service import Service | ||
from webdriver_manager.microsoft import EdgeChromiumDriverManager | ||
from webdriver_manager.core.os_manager import ChromeType | ||
from selenium.common.exceptions import NoSuchElementException | ||
from selenium.webdriver.common.by import By | ||
|
||
from selenium.webdriver.common.alert import Alert | ||
from selenium.webdriver.support.ui import WebDriverWait | ||
from selenium.webdriver.support import expected_conditions as EC | ||
|
||
from time import sleep | ||
from selenium.webdriver.remote.webelement import WebElement | ||
|
||
|
||
# function to expand the shadow element to get the extension id on chrome://extensions | ||
def expand_shadow_element(element): | ||
shadow_root = driver.execute_script('return arguments[0].shadowRoot', element) | ||
print("expand_shadow_element executed!") | ||
return shadow_root | ||
|
||
|
||
# Configure the necessary command-line option | ||
options = webdriver.ChromeOptions() | ||
# Note that you will need to download the build of the extension and put the path to the dist folder | ||
options.add_argument(r'--load-extension=/path/to/extension/dist/') | ||
|
||
# installing chromedriver | ||
driver = webdriver.Edge(service=Service(EdgeChromiumDriverManager().install()), options = options) | ||
sleep(2) | ||
|
||
# loading the extensions page to get extension id | ||
driver.get('chrome://extensions') | ||
sleep(5) | ||
|
||
# workflow with the chrome extensions page and its shadow elements | ||
root1 = driver.find_element(By.TAG_NAME, 'extensions-manager') | ||
shadow_root_1 = expand_shadow_element(root1) | ||
root2 = shadow_root_1.find_element(By.CSS_SELECTOR, 'extensions-item-list') | ||
shadow_root_2 = expand_shadow_element(root2) | ||
ele = shadow_root_2.find_element(By.CSS_SELECTOR, 'extensions-item') | ||
extension_id = ele.get_attribute("id") | ||
print(str(extension_id)) # printing the extension id | ||
|
||
# going to the extensions page | ||
url = "chrome-extension://" + extension_id + "/options.html" | ||
driver.get(url) | ||
|
||
# activate plugin | ||
activate_button = driver.find_element('id', 'app_btn_activate') #activating account | ||
activate_button.click() | ||
|
||
# Confirm page reload on activation | ||
WebDriverWait(driver, 10).until(EC.alert_is_present()) | ||
driver.switch_to.alert.accept() | ||
|
||
# Save settings | ||
save_button = driver.find_element('id', 'app_btn_save') #saving the settings | ||
save_button.click() | ||
|
||
# add a hardcoded url leading to a particular tweet which you are using for testing | ||
driver.get('https://twitter.com/jackantonoff/status/1579311659742416896') | ||
sleep(20) | ||
# Check if the extension worked and log the result. | ||
try: | ||
# logic to check if the slur is replaced | ||
ele = driver.find_element('xpath','//div[contains(text(),"▓")]') | ||
print('Success! :-)') | ||
# if no such span is present where the character - ▓ - is not present then the Failure message will show up | ||
# Note that this will return success if the tweet by default contains the replacement character | ||
except NoSuchElementException: | ||
print('Failure! :-(') | ||
finally: | ||
''' Clean up. ''' | ||
driver.quit() |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
selenium == 4.12.0 | ||
webdriver-manager == 4.0.0 |
35 changes: 0 additions & 35 deletions
35
ogbv-ml-rest/automated-testing/slur_detection_tester_chrome.py
This file was deleted.
Oops, something went wrong.