-
Notifications
You must be signed in to change notification settings - Fork 76
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
365 additions
and
21 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
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,26 @@ | ||
#!/usr/bin/env python | ||
import os | ||
import sys | ||
import json | ||
|
||
project_path = os.path.abspath(os.path.dirname(os.path.dirname(__file__))) | ||
browser_test_path = os.path.join(project_path, 'browser-test') | ||
test_data_file = open(os.path.join(browser_test_path, 'testData.json')) | ||
test_data = json.loads(test_data_file.read()) | ||
test_data_file.close() | ||
|
||
OPENWISP_RADIUS_PATH = os.getenv('OPENWISP_RADIUS_PATH', '') | ||
|
||
if OPENWISP_RADIUS_PATH == '': | ||
print('OPENWISP_RADIUS_PATH is needed for initializing data.') | ||
sys.exit(0) | ||
|
||
test_user_email = test_data['testuser']['email'] | ||
print( | ||
os.popen( | ||
f''' | ||
echo "User.objects.get(username='{test_user_email}').delete()"\ | ||
| {OPENWISP_RADIUS_PATH}/tests/manage.py shell_plus | ||
''' | ||
).read() | ||
) |
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,30 @@ | ||
#!/usr/bin/env python | ||
import os | ||
import sys | ||
import json | ||
|
||
project_path = os.path.abspath(os.path.dirname(os.path.dirname(__file__))) | ||
browser_test_path = os.path.join(project_path, 'browser-test') | ||
test_data_file = open(os.path.join(browser_test_path, 'testData.json')) | ||
test_data = json.loads(test_data_file.read()) | ||
test_data_file.close() | ||
|
||
OPENWISP_RADIUS_PATH = os.getenv('OPENWISP_RADIUS_PATH', '') | ||
|
||
if OPENWISP_RADIUS_PATH == '': | ||
print('OPENWISP_RADIUS_PATH is needed for initializing data.') | ||
sys.exit(0) | ||
|
||
test_user_email = test_data['testuser']['email'] | ||
test_user_password = test_data['testuser']['password'] | ||
test_user_organization = test_data['testuser']['organization'] | ||
print( | ||
os.popen( | ||
f''' | ||
echo "user=User.objects.create_user(username='{test_user_email}', password='{test_user_password}', email='{test_user_email}')\n | ||
org = Organization.objects.get(name='{test_user_organization}')\n | ||
OrganizationUser.objects.create(organization=org, user=user)"\ | ||
| {OPENWISP_RADIUS_PATH}/tests/manage.py shell_plus | ||
''' | ||
).read() | ||
) |
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,71 @@ | ||
import {Builder, By, until} from "selenium-webdriver"; | ||
import { | ||
getDriver, | ||
getElementByXPath, | ||
urls, | ||
initialData, | ||
executeCommand, | ||
} from "./utils"; | ||
|
||
const firefox = require("selenium-webdriver/firefox"); | ||
|
||
describe("Selenium tests for <Login />", () => { | ||
let driver; | ||
beforeAll(async () => { | ||
jest.setTimeout(30000); | ||
await executeCommand("./browser-test/initialize_data.py", () => {}); | ||
driver = await getDriver(Builder, new firefox.Options().headless()); | ||
}); | ||
|
||
afterAll(async () => { | ||
await executeCommand("./browser-test/clear_data.py", () => {}); | ||
driver.close(); | ||
}); | ||
|
||
it("should render login page and submit login form", async () => { | ||
await driver.get(urls.login); | ||
const data = initialData(); | ||
const username = await getElementByXPath( | ||
driver, | ||
"//INPUT[@id='username']", | ||
until, | ||
By, | ||
); | ||
username.sendKeys(data.testuser.email); | ||
|
||
const password = await getElementByXPath( | ||
driver, | ||
"//INPUT[@id='password']", | ||
until, | ||
By, | ||
); | ||
password.sendKeys(data.testuser.password); | ||
|
||
const submitBtn = await getElementByXPath( | ||
driver, | ||
"/html/body/div[1]/div[2]/div[3]/div/form/div[4]/input", | ||
until, | ||
By, | ||
); | ||
submitBtn.click(); | ||
|
||
await getElementByXPath(driver, "//DIV[@id='status']", until, By); | ||
const emailElement = await getElementByXPath( | ||
driver, | ||
"(//SPAN)[2]", | ||
until, | ||
By, | ||
); | ||
expect(await emailElement.getText()).toEqual(data.testuser.email); | ||
|
||
const successToastDiv = await getElementByXPath( | ||
driver, | ||
"//DIV[@role='alert']", | ||
until, | ||
By, | ||
); | ||
await driver.wait(until.elementIsVisible(successToastDiv)); | ||
await driver.wait(until.urlContains("status"), 10000); | ||
expect(await successToastDiv.getText()).toEqual("Login successful"); | ||
}); | ||
}); |
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,70 @@ | ||
import {Builder, By, until} from "selenium-webdriver"; | ||
import { | ||
getDriver, | ||
getElementByXPath, | ||
urls, | ||
initialData, | ||
executeCommand, | ||
} from "./utils"; | ||
|
||
const firefox = require("selenium-webdriver/firefox"); | ||
|
||
describe("Selenium tests for <Register />", () => { | ||
let driver; | ||
beforeAll(async () => { | ||
jest.setTimeout(30000); | ||
driver = await getDriver(Builder, new firefox.Options().headless()); | ||
}); | ||
|
||
afterAll(async () => { | ||
await executeCommand("./browser-test/clear_data.py", () => {}); | ||
driver.close(); | ||
}); | ||
|
||
it("should render registration page and submit registration form", async () => { | ||
await driver.get(urls.registration); | ||
const data = initialData(); | ||
const username = await getElementByXPath( | ||
driver, | ||
"//INPUT[@id='email']", | ||
until, | ||
By, | ||
); | ||
username.sendKeys(data.testuser.email); | ||
|
||
const password = await getElementByXPath( | ||
driver, | ||
"//INPUT[@id='password']", | ||
until, | ||
By, | ||
); | ||
password.sendKeys(data.testuser.password); | ||
|
||
const confirmPassword = await getElementByXPath( | ||
driver, | ||
"//INPUT[@id='password-confirm']", | ||
until, | ||
By, | ||
); | ||
confirmPassword.sendKeys(data.testuser.password); | ||
|
||
const submitBtn = await getElementByXPath( | ||
driver, | ||
"//INPUT[@type='submit']", | ||
until, | ||
By, | ||
); | ||
submitBtn.click(); | ||
|
||
await getElementByXPath(driver, "//DIV[@id='status']", until, By); | ||
const successToastDiv = await getElementByXPath( | ||
driver, | ||
"//DIV[@role='alert']", | ||
until, | ||
By, | ||
); | ||
await driver.wait(until.elementIsVisible(successToastDiv)); | ||
await driver.wait(until.urlContains("status"), 10000); | ||
expect(await successToastDiv.getText()).toEqual("Registration success"); | ||
}); | ||
}); |
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,7 @@ | ||
{ | ||
"testuser": { | ||
"email": "testuser@openwisp.org", | ||
"password": "testuser", | ||
"organization": "default" | ||
} | ||
} |
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,39 @@ | ||
import {exec} from "child_process"; | ||
import testData from "./testData.json"; | ||
|
||
const waitTime = 20000; | ||
const orgSlug = "default"; | ||
|
||
export const getDriver = async (Builder, options) => { | ||
const driver = await new Builder() | ||
.forBrowser("firefox") | ||
.setFirefoxOptions(options) | ||
.build(); | ||
return driver; | ||
}; | ||
|
||
export const getElementByXPath = async (driver, xpath, until, By) => { | ||
const el = await driver.wait(until.elementLocated(By.xpath(xpath)), waitTime); | ||
driver.wait(until.stalenessOf(el), waitTime); | ||
return el; | ||
}; | ||
|
||
export const sleep = async (ms) => { | ||
return new Promise((resolve) => setTimeout(resolve, ms)); | ||
}; | ||
|
||
export const initialData = () => testData; | ||
|
||
export const executeCommand = async (command, callback) => { | ||
await exec(command, (error, stdout, stderr) => { | ||
if (error) return callback(error.message); | ||
if (stderr) return callback(stderr); | ||
return callback(stdout); | ||
}); | ||
}; | ||
|
||
export const urls = { | ||
registration: `http://0.0.0.0:8080/${orgSlug}/registration`, | ||
login: `http://0.0.0.0:8080/${orgSlug}/login`, | ||
status: `http://0.0.0.0:8080/${orgSlug}/status`, | ||
}; |
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
Oops, something went wrong.