aboutsummaryrefslogtreecommitdiff
path: root/e2e/lib/OptionPage.ts
blob: e1ea759c943a6a2f59a13cd1ea43901c458aa5e2 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import { Lanthan } from "lanthan";
import { WebDriver, By } from "selenium-webdriver";
import JSONOptionPage from "./JSONOptionPage";
import FormOptionPage from "./FormOptionPage";

export default class OptionPage {
  private webdriver: WebDriver;

  constructor(private lanthan: Lanthan) {
    this.webdriver = lanthan.getWebDriver();
  }

  static async open(lanthan: Lanthan) {
    const url = await lanthan
      .getWebExtBrowser()
      .runtime.getURL("build/settings.html");
    await lanthan.getWebDriver().navigate().to(url);
    return new OptionPage(lanthan);
  }

  async switchToForm(): Promise<FormOptionPage> {
    const useFormInput = await this.webdriver.findElement(
      By.css("#setting-source-form")
    );
    await useFormInput.click();
    await this.webdriver.switchTo().alert().accept();
    return new FormOptionPage(this.lanthan);
  }

  async asFormOptionPage(): Promise<FormOptionPage> {
    // TODO validate current page
    return new FormOptionPage(this.lanthan);
  }

  async asJSONOptionPage(): Promise<JSONOptionPage> {
    // TODO validate current page
    return new JSONOptionPage(this.lanthan);
  }

  scrollTo(x: number, y: number): Promise<void> {
    return this.webdriver.executeScript(`window.scrollTo(${x}, ${y})`);
  }
}