diff --git a/.ameba.yml b/.ameba.yml new file mode 100644 index 0000000..48d03ce --- /dev/null +++ b/.ameba.yml @@ -0,0 +1,23 @@ +# This configuration file was generated by `ameba --gen-config` +# on 2024-02-24 10:06:31 UTC using Ameba version 1.6.1. +# The point is for the user to remove these configuration records +# one by one as the reported problems are removed from the code base. + +# Problems found: 1 +# Run `ameba --only Naming/AccessorMethodName` for details +Naming/AccessorMethodName: + Description: Makes sure that accessor methods are named properly + Excluded: + - src/lucky_flow/webless/element.cr + Enabled: true + Severity: Convention + +# Problems found: 5 +# Run `ameba --only Lint/UselessAssign` for details +Lint/UselessAssign: + Description: Disallows useless variable assignments + ExcludeTypeDeclarations: false + Excluded: + - src/lucky_flow.cr + Enabled: true + Severity: Warning diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5a030ab..d6d5471 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -2,7 +2,7 @@ name: Lucky Flow CI on: push: - branches: [ main ] + branches: [main] pull_request: branches: "*" @@ -58,7 +58,7 @@ jobs: - uses: actions/checkout@v3 - uses: browser-actions/setup-chrome@v1 with: - chrome-version: stable + chrome-version: beta if: matrix.os == 'windows-latest' - uses: crystal-lang/install-crystal@v1 with: diff --git a/Dockerfile b/Dockerfile index 2ad1665..5c0c15f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,9 +1,13 @@ -FROM crystallang/crystal:1.4.1 +FROM crystallang/crystal:1.5.1 WORKDIR /data EXPOSE 3002 RUN apt-get update \ - && apt-get install -y libnss3 libgconf-2-4 chromium-browser \ + && apt-get install -y \ + libnss3 \ + libgconf-2-4 \ + chromium-browser \ + firefox-geckodriver \ && apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* COPY . /data diff --git a/script/setup b/script/setup index 07cca0a..bec0049 100755 --- a/script/setup +++ b/script/setup @@ -4,12 +4,15 @@ set -e set -o pipefail -if ! command -v docker-compose > /dev/null; then - printf 'Docker and docker-compose are not installed.\n' +if command -v docker-compose > /dev/null; then + docker-compose build + docker-compose run app shards install +elif command -v docker compose > /dev/null; then + docker compose build + docker compose run app shards install +else + printf 'Docker and/or docker-compose are not installed.\n' printf 'See https://docs.docker.com/compose/install/ for install instructions.\n' exit 1 fi -docker-compose build - -docker-compose run app shards install diff --git a/script/test b/script/test index 9475b61..f6ddfce 100755 --- a/script/test +++ b/script/test @@ -4,7 +4,11 @@ set -e set -o pipefail -COMPOSE="docker-compose run app" +if command -v docker-compose > /dev/null; then + COMPOSE="docker-compose run app" +elif command -v docker compose > /dev/null; then + COMPOSE="docker compose run app" +fi printf "\nrunning specs with 'crystal spec'\n\n" $COMPOSE crystal spec diff --git a/shard.yml b/shard.yml index 214a090..7e7d247 100644 --- a/shard.yml +++ b/shard.yml @@ -4,7 +4,7 @@ version: 0.9.2 authors: - Paul Smith -crystal: "~> 1.4" +crystal: "~> 1.5" license: MIT diff --git a/spec/lucky_flow_spec.cr b/spec/lucky_flow_spec.cr index 4e92afc..9d6866e 100644 --- a/spec/lucky_flow_spec.cr +++ b/spec/lucky_flow_spec.cr @@ -237,60 +237,120 @@ describe LuckyFlow do flow.should have_element("h1", text: "Target") end - it "can open screenshots", tags: "headless_chrome" do - flow = LuckyFlow.new - fake_process = FakeProcess - time = Time.utc + context "with headless chrome" do + it "can open screenshots", tags: "headless_chrome" do + flow = LuckyFlow.new + fake_process = FakeProcess + time = Time.utc - flow.open_screenshot(fake_process, time) + flow.open_screenshot(fake_process, time) - fake_process.shell.should be_true - fake_process.command.should eq "open ./tmp/screenshots/#{time.to_unix}.png" - end + fake_process.shell.should be_true + fake_process.command.should eq "open ./tmp/screenshots/#{time.to_unix}.png" + end - it "can open fullsize screenshots", tags: "headless_chrome" do - flow = LuckyFlow.new - fake_process = FakeProcess - time = Time.utc + it "can open fullsize screenshots", tags: "headless_chrome" do + flow = LuckyFlow.new + fake_process = FakeProcess + time = Time.utc - flow.open_screenshot(fake_process, time, fullsize: true) + flow.open_screenshot(fake_process, time, fullsize: true) - fake_process.shell.should be_true - fake_process.command.should eq "open ./tmp/screenshots/#{time.to_unix}.png" - end + fake_process.shell.should be_true + fake_process.command.should eq "open ./tmp/screenshots/#{time.to_unix}.png" + end - it "can reset the session", tags: "headless_chrome" do - flow = visit_page_with <<-HTML -

Title

- HTML - flow.driver.add_cookie("hello", "world") - flow.driver.get_cookie("hello").should eq "world" + it "can reset the session", tags: "headless_chrome" do + flow = visit_page_with <<-HTML +

Title

+ HTML + flow.driver.add_cookie("hello", "world") + flow.driver.get_cookie("hello").should eq "world" - LuckyFlow.reset + LuckyFlow.reset - expect_raises Selenium::Error do - flow.driver.get_cookie("hello") + expect_raises Selenium::Error do + flow.driver.get_cookie("hello") + end + end + + it "can accept and dismiss alerts", tags: "headless_chrome" do + flow = visit_page_with <<-HTML + + + HTML + + flow.click("@button") + flow.accept_alert + flow.should have_element("@button", text: "Click Me - 1") + flow.click("@button") + flow.dismiss_alert + flow.should have_element("@button", text: "Click Me - 2") end end - it "can accept and dismiss alerts", tags: "headless_chrome" do - flow = visit_page_with <<-HTML - - - HTML + context "with headless firefox" do + it "can open screenshots", tags: "headless_firefox" do + flow = LuckyFlow.new + fake_process = FakeProcess + time = Time.utc - flow.click("@button") - flow.accept_alert - flow.should have_element("@button", text: "Click Me - 1") - flow.click("@button") - flow.dismiss_alert - flow.should have_element("@button", text: "Click Me - 2") + flow.open_screenshot(fake_process, time) + + fake_process.shell.should be_true + fake_process.command.should eq "open ./tmp/screenshots/#{time.to_unix}.png" + end + + it "can open fullsize screenshots", tags: "headless_firefox" do + flow = LuckyFlow.new + fake_process = FakeProcess + time = Time.utc + + flow.open_screenshot(fake_process, time, fullsize: true) + + fake_process.shell.should be_true + fake_process.command.should eq "open ./tmp/screenshots/#{time.to_unix}.png" + end + + it "can reset the session", tags: "headless_firefox" do + flow = visit_page_with <<-HTML +

Title

+ HTML + flow.driver.add_cookie("hello", "world") + flow.driver.get_cookie("hello").should eq "world" + + LuckyFlow.reset + + expect_raises Selenium::Error do + flow.driver.get_cookie("hello") + end + end + + it "can accept and dismiss alerts", tags: "headless_firefox" do + flow = visit_page_with <<-HTML + + + HTML + + flow.click("@button") + flow.accept_alert + flow.should have_element("@button", text: "Click Me - 1") + flow.click("@button") + flow.dismiss_alert + flow.should have_element("@button", text: "Click Me - 2") + end end it "can choose option in select input" do @@ -340,7 +400,7 @@ describe LuckyFlow do end end - it "can hover over an element", tags: "headless_chrome" do + it "can hover over an element", tags: "headless_firefox" do flow = visit_page_with <<-HTML