test.cjs 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. const os = require("os");
  2. const path = require("path");
  3. const { expect } = require("chai");
  4. const { spawn, spawnSync } = require("child_process");
  5. const { Builder, By, Capabilities, until } = require("selenium-webdriver");
  6. const { elementIsVisible, elementLocated } = require("selenium-webdriver/lib/until.js");
  7. // create the path to the expected application binary
  8. const application = path.resolve(
  9. __dirname,
  10. "..",
  11. "..",
  12. "..",
  13. "src-tauri",
  14. "target",
  15. "release",
  16. "appflowy_tauri"
  17. );
  18. // keep track of the webdriver instance we create
  19. let driver;
  20. // keep track of the tauri-driver process we start
  21. let tauriDriver;
  22. before(async function() {
  23. // set timeout to 2 minutes to allow the program to build if it needs to
  24. this.timeout(120000);
  25. // ensure the program has been built
  26. spawnSync("cargo", ["build", "--release"]);
  27. // start tauri-driver
  28. tauriDriver = spawn(
  29. path.resolve(os.homedir(), ".cargo", "bin", "tauri-driver"),
  30. [],
  31. { stdio: [null, process.stdout, process.stderr] }
  32. );
  33. const capabilities = new Capabilities();
  34. capabilities.set("tauri:options", { application });
  35. capabilities.setBrowserName("wry");
  36. // start the webdriver client
  37. driver = await new Builder()
  38. .withCapabilities(capabilities)
  39. .usingServer("http://localhost:4444/")
  40. .build();
  41. });
  42. after(async function() {
  43. // stop the webdriver session
  44. await driver.quit();
  45. // kill the tauri-driver process
  46. tauriDriver.kill();
  47. });
  48. describe("AppFlowy Unit Test", () => {
  49. it("should find get started button", async () => {
  50. // should sign out if already sign in
  51. const getStartedButton = await driver.wait(until.elementLocated(By.xpath("//*[@id=\"root\"]/form/div/div[3]")));
  52. getStartedButton.click();
  53. });
  54. it("should get sign out button", async (done) => {
  55. // const optionButton = await driver.wait(until.elementLocated(By.css('*[test-id=option-button]')));
  56. // const optionButton = await driver.wait(until.elementLocated(By.id('option-button')));
  57. // const optionButton = await driver.wait(until.elementLocated(By.css('[aria-label=option]')));
  58. // Currently, only the find className is work
  59. const optionButton = await driver.wait(until.elementLocated(By.className("relative h-8 w-8")));
  60. optionButton.click();
  61. await new Promise((resolve) => setTimeout(resolve, 4000));
  62. });
  63. });