Skip to content

Commit

Permalink
automated tests for create profile, login, scan_species, and saved sp…
Browse files Browse the repository at this point in the history
…ecies
  • Loading branch information
hzmann committed Aug 15, 2024
1 parent 8812968 commit 08869b1
Show file tree
Hide file tree
Showing 4 changed files with 159 additions and 0 deletions.
15 changes: 15 additions & 0 deletions e2e/test_create_profile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import pytest
from playwright.sync_api import expect, Page

#fixture that sets up browser page at our URL, provides a setup page for tests to use,
@pytest.fixture
def setup_page(page: Page):
page.goto('http://localhost:3000/create-profile')
return page

def test_successful_profile_creation(setup_page: Page):
page = setup_page
page.fill('input[placeholder="Username"]', 'new_username')
page.fill('input[placeholder="Password"]', 'new_password')
page.click('button:has-text("Create Profile")')
expect(page).to_have_url('http://localhost:3000/login')
29 changes: 29 additions & 0 deletions e2e/test_login.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import pytest
from playwright.sync_api import expect, Page

@pytest.fixture
def setup_page(page: Page):
page.goto('http://localhost:3000/login')
return page

#have test fill in valid (existing) credentials
def test_successful_login(setup_page: Page):
page = setup_page
page.fill('input[placeholder="Username"]', 'moo')
page.fill('input[placeholder="Password"]', 'moo')
page.click('button:has-text("Login")')
expect(page).to_have_url('http://localhost:3000/scan-species')

#have test fill in invalid credentials
def test_unsuccessful_login(setup_page: Page):
page = setup_page
page.fill('input[placeholder="Username"]', 'invalid_username')
page.fill('input[placeholder="Password"]', 'invalid_password')
page.click('button:has-text("Login")')
expect(page.locator('h3')).to_have_text('Incorrect username or password')

#ensures after selecting create profile button, user gets directed to create profile page
def test_navigate_to_create_profile(setup_page: Page):
page = setup_page
page.click('button:has-text("Create Profile")')
expect(page).to_have_url('http://localhost:3000/create-profile')
36 changes: 36 additions & 0 deletions e2e/test_saved_species.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
from playwright.sync_api import Page, expect
import pytest

@pytest.fixture(scope='function')
def setup_page(page: Page):
#log in before accessing the saved-species page
page.goto('http://localhost:3000/login')

#fill in login credentials
page.fill('input[placeholder="Username"]', 'moo')
page.fill('input[placeholder="Password"]', 'moo')
page.click('button:has-text("Login")')

#ensure login is successful
expect(page).to_have_url('http://localhost:3000/scan-species')

#proceed to saved-species page
page.goto('http://localhost:3000/saved-species')
return page

def test_saved_species_page(setup_page):
page = setup_page

#verify that the "Plants" and "Insects" buttons exist
plant_button = page.locator('text=Plants')
insect_button = page.locator('text=Insects')
expect(plant_button).to_be_visible()
expect(insect_button).to_be_visible()

#click on the "Plants" button and verify navigation
plant_button.click()
expect(page).to_have_url('http://localhost:3000/saved-species')

#click on the "Insects" button and verify navigation
insect_button.click()
expect(page).to_have_url('http://localhost:3000/saved-species')
79 changes: 79 additions & 0 deletions e2e/test_scan_species.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
from playwright.sync_api import Page, expect
import pytest

@pytest.fixture(scope='function')
def setup_page(page: Page):
#log in before accessing the scan-species page
page.goto('http://localhost:3000/login')

#fill in login credentials
page.fill('input[placeholder="Username"]', 'moo')
page.fill('input[placeholder="Password"]', 'moo')
page.click('button:has-text("Login")')

#ensure login is successful
expect(page).to_have_url('http://localhost:3000/scan-species')

#proceed to scan-species page
page.goto('http://localhost:3000/scan-species')
return page

def test_display_scan_options(setup_page):
page = setup_page

#verify that "Scan a Plant" button exists and has the correct text
scan_plant_button = page.locator('text=Scan a Plant')
expect(scan_plant_button).to_be_visible()

#verify that "Scan an Insect" button exists and has the correct text
scan_insect_button = page.locator('text=Scan an Insect')
expect(scan_insect_button).to_be_visible()

def test_navigate_to_scan_plant(setup_page):
page = setup_page

#click on "Scan a Plant" button
page.locator('text=Scan a Plant').click()

#verify the navigation
expect(page).to_have_url('http://localhost:3000/scan-plant')

def test_navigate_to_scan_insect(setup_page):
page = setup_page

#click on "Scan an Insect" button
page.locator('text=Scan an Insect').click()

#verify the navigation
expect(page).to_have_url('http://localhost:3000/scan-insect')

def test_navigate_to_saved_species(setup_page):
page = setup_page

#click on "Saved Species" button
page.locator('text=Saved Species').click()

#verify the navigation
expect(page).to_have_url('http://localhost:3000/saved-species')

def test_logout_success(setup_page):
page = setup_page

#click on "Logout" button
page.locator('text=Logout').click()

#verify the navigation to the login page
expect(page).to_have_url('http://localhost:3000/login')

def test_logout_failure(setup_page):
page = setup_page

#mock the logout API response to return an error
page.route('http://localhost:3000/api/logout', lambda route: route.fulfill(status=500))

#click on "Logout" button
page.locator('text=Logout').click()

#verify that the error message is displayed
error_message = page.locator('text=Something went wrong')
expect(error_message).to_be_visible()

0 comments on commit 08869b1

Please sign in to comment.