Comments (3)
Yes, this would be cool.
from ladder.
This seems like a very cool idea.
I played around with your example a bit, and I think we may be able to leverage Github actions to run a shell script whenever a ruleset yaml is uploaded or changed to generate and run a test. From your example, I changed await expect(page.getByText(paywallText)).toBeVisible();
to await expect(page.getByText(paywallText)).not.toBeVisible();
for the test with ladder so both tests pass and could be used for CI.
I used the following bash script to generate a Playwright test.
./generate_test.sh -i rulesets/ca/_multi-metroland-media-group.yaml > tests/_multi-metroland-media-group.spec.ts
generate_test.sh
#!/bin/bash
# Command-line argument parsing
while getopts "i:" opt; do
case $opt in
i)
input_file=$OPTARG
;;
\?)
echo "Invalid option: -$OPTARG" >&2
exit 1
;;
:)
echo "Option -$OPTARG requires an argument." >&2
exit 1
;;
esac
done
# Check if the input file is provided
if [ -z "$input_file" ]; then
echo "Usage: $0 -i <input_yaml_file>"
exit 1
fi
# Extract information from the "tests" section
url=$(awk '/- url:/ {sub(/- url: /, ""); sub(/^[[:space:]]*/, ""); print}' "$input_file")
domain=$(echo "$url" | awk -F/ '{print $3}')
test=$(awk '/test:/ {sub(/test: /, ""); sub(/^[[:space:]]*/, ""); print}' "$input_file")
# Generate Playwright test script
echo "import { expect, test } from '@playwright/test';"
echo
echo "test('$domain has paywall by default', async ({ page }) => {"
echo " await page.goto('$url');"
echo " await expect($test).toBeVisible();"
echo "});"
echo
echo "test('$domain + Ladder does not have paywall', async ({ page }) => {"
echo " await page.goto('http://localhost:8080/$url');"
echo " await page.waitForLoadState();"
echo " await expect($test).not.toBeVisible();"
echo "});"
In the ruleset yaml, I put a Playwright locator in the test portion:
tests:
- url: https://www.wellandtribune.ca/news/niagara-region/niagara-transit-commission-rejects-council-request-to-reduce-its-budget-increase/article_e9fb424c-8df5-58ae-a6c3-3648e2a9df66.html
test: page.getByText("This article is exclusive to subscribers.")
At the moment, the bash script is pretty limited to just checking if a specified element is or is not visible. If we continue this way, we may want the script to be a bit more general so it can capture other scenarios. This may require anyone contributing a rule to be a bit more explicit in their ruleset tests section, so rather than contribute a Playwright locator they may need to provide the expectation with both a locator and an assertion:
test: expect(page.getByText("This article is exclusive to subscribers.")).toBeVisible()
Some additional parsing in the bash script could insert a .not
before the assertion for the ladder test.
from ladder.
Nice work!
I've been thinking about how to generate rules for any site, in an automated fashion. One of the main roadblocks is figuring out whether or not a site is paywalled, and to generate a test for it. I wonder if it's as simple as extracting visible text from a page, and asking an LLM whether or not it is paywall text is sufficient.
from ladder.
Related Issues (20)
- Proposal: Use Tailwind CLI instead of play CDN HOT 5
- May I inquire about the method to enable a program to establish a network connection via a proxy? HOT 1
- Idea: API should return structured article json HOT 27
- Request Header Fields Too Large HOT 7
- Improvement: add benchmarking and testing suite HOT 2
- Ladder malforms https links HOT 7
- Unraid docker app HOT 1
- The 'package' line in go.mod doesn't have the URL HOT 1
- Looking for the curl --compressed equivalent in Ladder HOT 2
- Should Ladder's UI behave differently for mobile?
- Medium.com blocked by cloudflare HOT 3
- To deploy on my own VPS HOT 2
- Catch-All rule to add "Access-Control-Allow-Origin: *" to all responses?
- http: no Host in request URL
- Ladder should restrict proxying local/reserved IP addresses HOT 1
- Feature request: Possibility to set up number of threads spawned HOT 1
- Bug: ENV "LOG_URLS" has stopped working
- Public instances ? HOT 7
- Error loading website with basic auth
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ladder.