Skip to content

Commit

Permalink
chore: Update tests files (#116)
Browse files Browse the repository at this point in the history
* chore: Update tests files

* fix: tests fail because span is not in document

Co-authored-by: Eric Crooks <eric.crooks@gmail.com>
Co-authored-by: Eric Crooks <crookse@users.noreply.github.com>
  • Loading branch information
3 people authored Apr 27, 2022
1 parent 1a2e483 commit 3361320
Show file tree
Hide file tree
Showing 10 changed files with 661 additions and 595 deletions.
70 changes: 36 additions & 34 deletions tests/integration/clicking_elements_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,40 +2,42 @@ import { buildFor } from "../../mod.ts";
import { assertEquals } from "../../deps.ts";
import { delay } from "https://deno.land/std/async/delay.ts";

Deno.test(
"[chrome] Clicking elements - Tutorial for this feature in the docs should work",
async () => {
const { browser, page } = await buildFor("chrome");
// Clicking an element that will open up a new page (tab)
await page.location("https://drash.land");
const githubElem = await page.querySelector(
"a",
);
await githubElem.click({
button: "middle", // Make sure when clicking an element that will open a new page, "middle" is used
});
await delay(1000);
const page2 = await browser.page(2);
const page2Location = await page2.location();

// Click an element that will change a pages location
const discordElem = await page.querySelector(
'a[href="https://discord.gg/RFsCSaHRWK"]',
);
await discordElem.click({
waitFor: "navigation",
});
const page1Location = await page.location();

await browser.close();

assertEquals(
page2Location,
"https://github.com/drashland",
);
assertEquals(page1Location, "https://discord.com/invite/RFsCSaHRWK");
},
);
Deno.test("chrome", async (t) => {
await t.step(
"Clicking elements - Tutorial for this feature in the docs should work",
async () => {
const { browser, page } = await buildFor("chrome");
// Clicking an element that will open up a new page (tab)
await page.location("https://drash.land");
const githubElem = await page.querySelector(
"a",
);
await githubElem.click({
button: "middle", // Make sure when clicking an element that will open a new page, "middle" is used
});
await delay(1000);
const page2 = await browser.page(2);
const page2Location = await page2.location();

// Click an element that will change a pages location
const discordElem = await page.querySelector(
'a[href="https://discord.gg/RFsCSaHRWK"]',
);
await discordElem.click({
waitFor: "navigation",
});
const page1Location = await page.location();

await browser.close();

assertEquals(
page2Location,
"https://github.com/drashland",
);
assertEquals(page1Location, "https://discord.com/invite/RFsCSaHRWK");
},
);
});

// Deno.test(
// "[firefox] Clicking elements - Tutorial for this feature in the docs should work",
Expand Down
33 changes: 19 additions & 14 deletions tests/integration/csrf_protected_pages_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,24 @@ import { buildFor } from "../../mod.ts";
import { browserList } from "../browser_list.ts";

for (const browserItem of browserList) {
Deno.test(`[${browserItem.name}] CSRF Protected Pages - Tutorial for this feature in the docs should work`, async () => {
const { browser, page } = await buildFor(browserItem.name);
await page.location("https://drash.land");
await page.cookie({
name: "X-CSRF-TOKEN",
value: "hi:)",
url: "https://drash.land",
});
await page.location("https://drash.land/drash/v1.x/#/"); // Going here to ensure the cookie stays
const cookieVal = await page.evaluate(() => {
return document.cookie;
});
await browser.close();
assertEquals(cookieVal, "X-CSRF-TOKEN=hi:)");
Deno.test(browserItem.name, async (t) => {
await t.step(
`CSRF Protected Pages - Tutorial for this feature in the docs should work`,
async () => {
const { browser, page } = await buildFor(browserItem.name);
await page.location("https://drash.land");
await page.cookie({
name: "X-CSRF-TOKEN",
value: "hi:)",
url: "https://drash.land",
});
await page.location("https://drash.land/drash/v1.x/#/"); // Going here to ensure the cookie stays
const cookieVal = await page.evaluate(() => {
return document.cookie;
});
await browser.close();
assertEquals(cookieVal, "X-CSRF-TOKEN=hi:)");
},
);
});
}
27 changes: 14 additions & 13 deletions tests/integration/get_and_set_input_value_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,18 @@ import { buildFor } from "../../mod.ts";
import { browserList } from "../browser_list.ts";

for (const browserItem of browserList) {
Deno.test(
browserItem.name +
": Get and set input value - Tutorial for this feature in the docs should work",
async () => {
const { browser, page } = await buildFor(browserItem.name);
await page.location("https://chromestatus.com");
const elem = await page.querySelector('input[placeholder="Filter"]');
await elem.value("hello world");
const val = await elem.value();
assertEquals(val, "hello world");
await browser.close();
},
);
Deno.test(browserItem.name, async (t) => {
await t.step(
"Get and set input value - Tutorial for this feature in the docs should work",
async () => {
const { browser, page } = await buildFor(browserItem.name);
await page.location("https://chromestatus.com");
const elem = await page.querySelector('input[placeholder="Filter"]');
await elem.value("hello world");
const val = await elem.value();
assertEquals(val, "hello world");
await browser.close();
},
);
});
}
42 changes: 22 additions & 20 deletions tests/integration/getting_started_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,28 @@ import { browserList } from "../browser_list.ts";
import { assertEquals } from "../../deps.ts";

for (const browserItem of browserList) {
Deno.test(
browserItem.name + ": Tutorial for Getting Started in the docs should work",
async () => {
// Setup
const { browser, page } = await buildFor(browserItem.name); // also supports firefox
await page.location("https://drash.land"); // Go to this page
Deno.test(browserItem.name, async (t) => {
await t.step(
"Tutorial for Getting Started in the docs should work",
async () => {
// Setup
const { browser, page } = await buildFor(browserItem.name); // also supports firefox
await page.location("https://drash.land"); // Go to this page

// Do any actions and assertions, in any order
assertEquals(await page.location(), "https://drash.land/");
const elem = await page.querySelector(
'a[href="https://discord.gg/RFsCSaHRWK"]',
);
await elem.click({
waitFor: "navigation",
}); // This element will take the user to Sinco's documentation
const location = await page.location();
// Do any actions and assertions, in any order
assertEquals(await page.location(), "https://drash.land/");
const elem = await page.querySelector(
'a[href="https://discord.gg/RFsCSaHRWK"]',
);
await elem.click({
waitFor: "navigation",
}); // This element will take the user to Sinco's documentation
const location = await page.location();

// Once finished, close to clean up any processes
await browser.close();
assertEquals(location, "https://discord.com/invite/RFsCSaHRWK");
},
);
// Once finished, close to clean up any processes
await browser.close();
assertEquals(location, "https://discord.com/invite/RFsCSaHRWK");
},
);
});
}
85 changes: 43 additions & 42 deletions tests/integration/manipulate_page_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,54 +4,55 @@ import { buildFor } from "../../mod.ts";
import { browserList } from "../browser_list.ts";

for (const browserItem of browserList) {
Deno.test(browserItem.name + ": Manipulate Webpage", async () => {
const { browser, page } = await buildFor(browserItem.name);
await page.location("https://drash.land");

const updatedBody = await page.evaluate(() => {
// deno-lint-ignore no-undef
const prevBody = document.body.children.length;
// deno-lint-ignore no-undef
const newEl = document.createElement("p");
// deno-lint-ignore no-undef
document.body.appendChild(newEl);
// deno-lint-ignore no-undef
return prevBody === document.body.children.length - 1;
});
assertEquals(updatedBody, true);

await browser.close();
});

Deno.test(
browserItem.name +
": Evaluating a script - Tutorial for this feature in the documentation works",
async () => {
Deno.test(browserItem.name, async (t) => {
await t.step("Manipulate Webpage", async () => {
const { browser, page } = await buildFor(browserItem.name);
await page.location("https://drash.land");
const pageTitle = await page.evaluate(() => {
// deno-lint-ignore no-undef
return document.title;
});
const sum = await page.evaluate(`1 + 10`);
const oldBodyLength = await page.evaluate(() => {

const updatedBody = await page.evaluate(() => {
// deno-lint-ignore no-undef
return document.body.children.length;
});
const newBodyLength = await page.evaluate(() => {
const prevBody = document.body.children.length;
// deno-lint-ignore no-undef
const p = document.createElement("p");
p.textContent = "Hello world!";
const newEl = document.createElement("p");
// deno-lint-ignore no-undef
document.body.appendChild(p);
document.body.appendChild(newEl);
// deno-lint-ignore no-undef
return document.body.children.length;
return prevBody === document.body.children.length - 1;
});
assertEquals(updatedBody, true);

await browser.close();
assertEquals(pageTitle, "Drash Land");
assertEquals(sum, 11);
assertEquals(oldBodyLength, 3);
assertEquals(newBodyLength, 4);
},
);
});

await t.step(
"Evaluating a script - Tutorial for this feature in the documentation works",
async () => {
const { browser, page } = await buildFor(browserItem.name);
await page.location("https://drash.land");
const pageTitle = await page.evaluate(() => {
// deno-lint-ignore no-undef
return document.title;
});
const sum = await page.evaluate(`1 + 10`);
const oldBodyLength = await page.evaluate(() => {
// deno-lint-ignore no-undef
return document.body.children.length;
});
const newBodyLength = await page.evaluate(() => {
// deno-lint-ignore no-undef
const p = document.createElement("p");
p.textContent = "Hello world!";
// deno-lint-ignore no-undef
document.body.appendChild(p);
// deno-lint-ignore no-undef
return document.body.children.length;
});
await browser.close();
assertEquals(pageTitle, "Drash Land");
assertEquals(sum, 11);
assertEquals(oldBodyLength, 3);
assertEquals(newBodyLength, 4);
},
);
});
}
47 changes: 24 additions & 23 deletions tests/integration/screenshots_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,28 @@ import { buildFor } from "../../mod.ts";
import { browserList } from "../browser_list.ts";

for (const browserItem of browserList) {
Deno.test(
browserItem.name +
" - Tutorial for taking screenshots in the docs should work",
async () => {
const { browser, page } = await buildFor(browserItem.name);
await page.location("https://drash.land");
const screenshotsFolder = "./screenshots";
Deno.mkdirSync(screenshotsFolder); // Ensure you create the directory your screenshots will be put within
await page.takeScreenshot(screenshotsFolder); // Will take a screenshot of the whole page, and write it to `./screenshots/dd_mm_yyyy_hh_mm_ss.jpeg`
await page.takeScreenshot(screenshotsFolder, {
fileName: "drash_land.png",
format: "png",
}); // Specify filename and format. Will be saved as `./screenshots/drash_land.png`
const anchor = await page.querySelector(
'a[href="https://github.com/drashland"]',
);
await anchor.takeScreenshot(screenshotsFolder, {
fileName: "modules.jpeg",
}); // Will screenshot only the GitHub icon section, and write it to `./screenshots/dd_mm_yyyy_hh_mm_ss.jpeg`
await browser.close();
Deno.removeSync("./screenshots", { recursive: true });
},
);
Deno.test(browserItem.name, async (t) => {
await t.step(
"Tutorial for taking screenshots in the docs should work",
async () => {
const { browser, page } = await buildFor(browserItem.name);
await page.location("https://drash.land");
const screenshotsFolder = "./screenshots";
Deno.mkdirSync(screenshotsFolder); // Ensure you create the directory your screenshots will be put within
await page.takeScreenshot(screenshotsFolder); // Will take a screenshot of the whole page, and write it to `./screenshots/dd_mm_yyyy_hh_mm_ss.jpeg`
await page.takeScreenshot(screenshotsFolder, {
fileName: "drash_land.png",
format: "png",
}); // Specify filename and format. Will be saved as `./screenshots/drash_land.png`
const anchor = await page.querySelector(
'a[href="https://github.com/drashland"]',
);
await anchor.takeScreenshot(screenshotsFolder, {
fileName: "modules.jpeg",
}); // Will screenshot only the GitHub icon section, and write it to `./screenshots/dd_mm_yyyy_hh_mm_ss.jpeg`
await browser.close();
Deno.removeSync("./screenshots", { recursive: true });
},
);
});
}
23 changes: 12 additions & 11 deletions tests/integration/visit_pages_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,16 @@ import { browserList } from "../browser_list.ts";
import { assertEquals } from "../../deps.ts";

for (const browserItem of browserList) {
Deno.test(
browserItem.name +
": Visit pages - Tutorial for this feature in the docs should work",
async () => {
const { browser, page } = await buildFor(browserItem.name);
await page.location("https://drash.land");
const location = await page.location();
await browser.close();
assertEquals(location, "https://drash.land/");
},
);
Deno.test(browserItem.name, async (t) => {
await t.step(
"Visit pages - Tutorial for this feature in the docs should work",
async () => {
const { browser, page } = await buildFor(browserItem.name);
await page.location("https://drash.land");
const location = await page.location();
await browser.close();
assertEquals(location, "https://drash.land/");
},
);
});
}
Loading

0 comments on commit 3361320

Please sign in to comment.