Skip to content

Commit

Permalink
feat: add slur detection test for chrome. fixes #181 and closes #186
Browse files Browse the repository at this point in the history
  • Loading branch information
Bhargav-Dave authored Oct 10, 2022
1 parent a571bfd commit 905428b
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
11 changes: 11 additions & 0 deletions ogbv-ml-rest/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,14 @@ Note that if you are on windows and are using PowerShell, you might need to run
```
Invoke-RestMethod -Method 'Post' -Uri http://localhost:8080/predict -Body (@{"text"="The food in this restaurant is disgusting"}|ConvertTo-Json) -ContentType "application/json"
```
## Testing

1. Go to the following url and download the extension zip file present in the release: https://github.com/tattle-made/OGBV/releases
2. Extract the files locally and put the path to the dist folder present in the newly extracted files in the "options.add_argument" function in the slur_detection_tester.py file
3. Run the following in your test environment (in order):

```
pip install selenium
pip install webdriver-manager
```
4. Find a tweet with a known slur, you can look them up here: https://github.com/tattle-made/OGBV/blob/main/browser-extension/plugin/src/slur-replace.js. You'll need to hardcode the url in the "driver.get()" function. A known url is the following: https://twitter.com/jackantonoff/status/1579311659742416896. This should set you up for running the code.
35 changes: 35 additions & 0 deletions ogbv-ml-rest/slur_detection_tester.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager
from selenium.common.exceptions import NoSuchElementException

from time import sleep
from selenium.webdriver.remote.webelement import WebElement





# 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\dist_folder_of_extension')

# installing chromedriver
driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()), options = options)
sleep(2)
# add a hardcoded url leading to a particular tweet which you are using for testing
driver.get('your url here')
sleep(5)
# Check if the extension worked and log the result.
try:
# logic to check if the slur is replaced
ele = driver.find_element('xpath','//span[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()

0 comments on commit 905428b

Please sign in to comment.