Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ebebbington committed Apr 28, 2024
1 parent 0d870c9 commit 27731fd
Show file tree
Hide file tree
Showing 15 changed files with 121 additions and 206 deletions.
14 changes: 14 additions & 0 deletions src/element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,20 @@ export class Element {
const quad = quads[0];
let x = 0;
let y = 0;

/**
* It could be that the element isn't clickable. Once
* instance i've found this is when i've tried to click
* an element `<a id=... href=... />` eg self closing.
* Could be more reasons though
*/
if (!quad) {
await this.#page.client.close(
`Unable to click the element "${this.#selector}". It could be that it is invalid HTML`,
);
return;
}

for (const point of quad) {
x += point.x;
y += point.y;
Expand Down
13 changes: 13 additions & 0 deletions src/page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,19 @@ export class Page {
url: newLocation,
},
);

// Usually if an invalid URL is given, the WS never gets a notification
// but we get a message with the id associated with the msg we sent
// TODO :: Ideally the protocol class would throw and we could catch it so we know
// for sure its an error
if ("errorText" in res) {
if (notificationPromise && "resolve" in notificationPromise) {
notificationPromise.resolve();
}
await this.client.close(res.errorText);
return "";
}

await notificationPromise;
if (res.errorText) {
await this.client.close(
Expand Down
6 changes: 3 additions & 3 deletions src/protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ interface NotificationResponse { // Not entirely sure when, but when we send the
}

type Create<T> = T extends true ? {
protocol: Protocol;
frameId: string;
}
protocol: Protocol;
frameId: string;
}
: T extends false ? Protocol
: never;

Expand Down
2 changes: 2 additions & 0 deletions src/utility.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ export function getFirefoxPath(): string {
return "/usr/bin/firefox";
case "windows":
return "C:\\Program Files\\Mozilla Firefox\\firefox.exe";
default:
throw new Error("Unhandled OS. Unsupported for " + Deno.build.os);
}
}

Expand Down
65 changes: 0 additions & 65 deletions tests/integration/clicking_elements_test.ts

This file was deleted.

2 changes: 0 additions & 2 deletions tests/integration/docker_test/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
version: '3'

services:
drivers:
container_name: drivers
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/docker_test/drivers.dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
FROM debian:stable-slim

ENV CHROME_VERSION "101.0.4951.54"
ENV CHROME_VERSION "124.0.6367.91"

# Install chrome driver
RUN apt update -y \
Expand Down
22 changes: 0 additions & 22 deletions tests/integration/get_and_set_input_value_test.ts

This file was deleted.

32 changes: 0 additions & 32 deletions tests/integration/getting_started_test.ts

This file was deleted.

2 changes: 1 addition & 1 deletion tests/integration/manipulate_page_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ for (const browserItem of browserList) {
await page.location("https://drash.land");
const pageTitle = await page.evaluate(() => {
// deno-lint-ignore no-undef
return document.title;
return document.querySelector("h1")?.textContent;
});
const sum = await page.evaluate(`1 + 10`);
const oldBodyLength = await page.evaluate(() => {
Expand Down
32 changes: 0 additions & 32 deletions tests/integration/screenshots_test.ts

This file was deleted.

20 changes: 0 additions & 20 deletions tests/integration/visit_pages_test.ts

This file was deleted.

17 changes: 10 additions & 7 deletions tests/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@ class JSResource extends Drash.Resource {
response.headers.set("content-type", "application/javascript");
}
}
class PopupsResource extends Drash.Resource {
public paths = ["/popups"];
class AnchorLinksResource extends Drash.Resource {
public paths = ["/anchor-links"];

public GET(_r: Drash.Request, res: Drash.Response) {
return res.html('<a href="https://drash.land" target="_blank" />');
return res.html(
'<a id="blank" href="https://drash.land" target="_blank">Website</a> <a id="not-blank" href="https://discord.gg/RFsCSaHRWK">Discord</a> <a id="invalid-link" href="#" />',
);
}
}

Expand All @@ -39,12 +41,13 @@ class DialogsResource extends Drash.Resource {
}
}

class FileInputResource extends Drash.Resource {
public paths = ["/file-input"];
class InputResource extends Drash.Resource {
public paths = ["/input"];

public GET(_r: Drash.Request, res: Drash.Response) {
return res.html(`
<p></p>
<div></div>
<input id="text" type="text" />
<input type="file" multiple id="multiple-file" />
<input type="file" id="single-file" />
Expand Down Expand Up @@ -82,9 +85,9 @@ export const server = new Drash.Server({
resources: [
HomeResource,
JSResource,
PopupsResource,
AnchorLinksResource,
WaitForRequestsResource,
FileInputResource,
InputResource,
DialogsResource,
],
protocol: "http",
Expand Down
Loading

0 comments on commit 27731fd

Please sign in to comment.