-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test using requests and API instead of selenium and web UI
- Loading branch information
1 parent
d53814a
commit 1c4df16
Showing
4 changed files
with
13 additions
and
85 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
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,21 +1,12 @@ | ||
import pytest | ||
|
||
from selenium.webdriver.common.by import By | ||
from selenium.webdriver.common.keys import Keys | ||
import requests | ||
|
||
def test_search(browser, app_url): | ||
browser.get(app_url + "/search") | ||
search_input = browser.find_element(By.ID, 'textInput') | ||
search_input.send_keys('aerospike') | ||
search_input.send_keys(Keys.RETURN) | ||
def test_search(app_url): | ||
|
||
results_div = browser.find_element(By.ID, 'results') | ||
assert results_div.is_displayed(), "Results div is not displayed" | ||
response = requests.post(app_url + "/rest/v1/search", data={"text": "aerospike"}) | ||
assert response.status_code == 200, f"Expected status code 200, but got {response.status_code}" | ||
|
||
# Find all elements within the search resultsgallery | ||
gallery_items = results_div.find_elements(By.CSS_SELECTOR, ".responsive .gallery .search-result") | ||
|
||
# Assert there are exactly 1 elements | ||
# This assumes that the app was started without adding any additional images to the data file | ||
# By default, there is 1 image in the data file | ||
assert len(gallery_items) == 1, f"Expected 1 elements in the gallery, but found {len(gallery_items)}." | ||
# by default there is 1 photo in the data dir so expect 1 | ||
results = response.json()["results"] | ||
assert len(results) == 1, f"Expected 1 results, but got {len(results)}" |
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 |
---|---|---|
@@ -1,20 +1,11 @@ | ||
import pytest | ||
|
||
from selenium.webdriver.common.by import By | ||
from selenium.webdriver.common.keys import Keys | ||
import requests | ||
|
||
def test_search(browser, app_url): | ||
browser.get(app_url + "/search") | ||
search_input = browser.find_element(By.ID, 'textInput') | ||
search_input.send_keys('dog') | ||
search_input.send_keys(Keys.RETURN) | ||
def test_search(app_url): | ||
|
||
results_div = browser.find_element(By.ID, 'results') | ||
assert results_div.is_displayed(), "Results div is not displayed" | ||
response = requests.post(app_url + "/rest/v1/search", data={"text": "dog"}) | ||
assert response.status_code == 200, f"Expected status code 200, but got {response.status_code}" | ||
|
||
# Find all elements within the results gallery | ||
gallery_items = results_div.find_elements(By.CSS_SELECTOR, ".gallery .responsive .quote") | ||
|
||
# Assert there are exactly 5 elements | ||
# By default the app returns 5 quotes | ||
assert len(gallery_items) == 5, f"Expected 5 elements in the gallery, but found {len(gallery_items)}." | ||
results = response.json()["results"] | ||
assert len(results) == 5, f"Expected 5 results, but got {len(results)}" |