Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add framework for UI testing via bs4 #62

Closed
wants to merge 8 commits into from

Conversation

JasonGrace2282
Copy link
Member

@JasonGrace2282 JasonGrace2282 commented Jul 24, 2024

This is mostly here so I can explore how I like this solution, and others can see my progress.

The main difference is this now uses BeautifulSoup4, so we can leverage the flexibility of that for more advanced queries. The simple but tedious cases are encapsulated in an Html class, which should be sufficient for most tests.

Testing plan

pytest

Progress

  • Implement rough framework
  • Add UI tests for assignments app to see if the framework is sufficiently useful.

@JasonGrace2282 JasonGrace2282 added the testing Related to adding tests, or the infrastructure for tests label Jul 24, 2024
@JasonGrace2282 JasonGrace2282 self-assigned this Jul 24, 2024
@JasonGrace2282 JasonGrace2282 marked this pull request as ready for review July 27, 2024 18:38
@JasonGrace2282 JasonGrace2282 requested a review from a team as a code owner July 27, 2024 18:38
@JasonGrace2282
Copy link
Member Author

JasonGrace2282 commented Jul 27, 2024

I feel pretty happy with this approach - what do you think @krishnans2006 ?

I did some benchmarking, and I found on my machine (for actual Tin pages):

  • Parsing HTML takes on average 0.01s
  • Searching through the HTML for a button takes on average 0.002s

And with python -O

  • Parsing HTML takes on average 0.006s
  • Searching through the HTML for a button takes on average 0.002s

So I'm not too concerned about performance. I've written some light tests to illustrate kind of what I was going for with the UI testing approach, any kind of feedback would be nice :)

krishnans2006
krishnans2006 previously approved these changes Aug 3, 2024
@JasonGrace2282
Copy link
Member Author

JasonGrace2282 commented Aug 4, 2024

As discussed internally

  • Avoid checking for button and input type=submit unless the tin-btn css class is not found.
  • Make button text case insensitive
  • Rename visible to visibility or something

doctest_optionflags = "NORMALIZE_WHITESPACE NUMBER"
filterwarnings = [
"error",
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Due to pytest's bad naming, this is a bit confusing, but the error means to transform all warnings into exceptions. I'm not sure if this is wanted (or needed) but it should help during migrations between e.g. Django 4.2 - Django 5.2

@JasonGrace2282
Copy link
Member Author

Looking back at this PR, it might be worth it to use Selenium instead of just parsing html...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
testing Related to adding tests, or the infrastructure for tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants