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

added initial explorer test for poc validation #16

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/nightly.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ env:
CLUSTER_ADMIN_PASSWORD_HASH: ${{ secrets.CLUSTERS_CONFIG_PASSWORD }}
WEAVEWORKS_BOT_TOKEN: ${{ secrets.WEAVEWORKS_BOT_TOKEN }}
ENTERPRISE_CHART_VERSION: ${{ inputs.chart_version }}
DEFAULT_ENTERPRISE_CHART_VERSION: "0.31.0-9-gdae6755"
DEFAULT_ENTERPRISE_CHART_VERSION: "0.38.0-4-gaa8c216" # release 0.38.1
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

we eventually should have the latest release


jobs:
build_and_run_tests:
Expand Down
27 changes: 14 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,24 +1,25 @@
# Playwright Tests

### How to run tests locally:
## How to run tests locally

This is a guide to quickly setup the environment to run and debug tests locally on a kind cluster.
This is a guide to quickly setup the environment to run and debug tests locally on a Kind cluster.

There are some prerequisites before running tests locally. It includes installing required tools and environment configurations.

## Tools & Utilities
## Tools & Utilities

It is recommended to install latest and stable version of these tools. All tools must be on path.
| Tool | Purpose | Installation |
|--|--|--|
| Docker | Containers runtime environment | `https://docs.docker.com/get-docker` |
| Kind | Running local Kubernetes cluster | `https://kind.sigs.k8s.io/docs/user/quick-start#installation` |
|Kubectl|Kubernetes command-line tool| `https://kubernetes.io/docs/tasks/tools/install-kubectl-linux` |
| Playwright | a framework for Web Testing and Automation | `https://playwright.dev/docs/intro#installing-playwright`|
| flux | Command-line interface to bootstrap and interact with Flux | `https://fluxcd.io/docs/installation/#install-the-flux-cli`|
| Playwright chromium browser | a browser binary which playwright needs to operate and run tests | After installing Playwright run `playwright install chromium`<br> you can also check this page for more info. <br> `ghttps://playwright.dev/docs/browsers`
| Pytest | a testing framework that allows users to write test codes using Python programming language. | `https://docs.pytest.org/en/7.1.x/getting-started.html` |
| pytest-reporter-html1 | A basic HTML report for pytest using Jinja2 template engine. | `https://pypi.org/project/pytest-reporter-html1/` |

| Tool | Purpose | Installation |
|-----------------------------|----------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------|
| Docker | Containers runtime environment | `https://docs.docker.com/get-docker` |
| Kind | Running local Kubernetes cluster | `https://kind.sigs.k8s.io/docs/user/quick-start#installation` |
| Kubectl | Kubernetes command-line tool | `https://kubernetes.io/docs/tasks/tools/install-kubectl-linux` |
| Playwright | a framework for Web Testing and Automation | `https://playwright.dev/docs/intro#installing-playwright` |
| flux | Command-line interface to bootstrap and interact with Flux | `https://fluxcd.io/docs/installation/#install-the-flux-cli` |
| Playwright chromium browser | a browser binary which playwright needs to operate and run tests | After installing Playwright run `playwright install chromium`<br> you can also check this page for more info. <br> `ghttps://playwright.dev/docs/browsers` |
| Pytest | a testing framework that allows users to write test codes using Python programming language. | `https://docs.pytest.org/en/7.1.x/getting-started.html` |
| pytest-reporter-html1 | A basic HTML report for pytest using Jinja2 template engine. | `https://pypi.org/project/pytest-reporter-html1/` |

## Environment Setup
1. Clone the repo<br/>
Expand Down
12 changes: 12 additions & 0 deletions pages/explorer_page.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
class Explorer:
def __init__(self, page, url):
self.page = page
self.url = url
Copy link
Contributor

Choose a reason for hiding this comment

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

After fixing this line , the URL will not be needed.


def open(self):
Copy link
Contributor

Choose a reason for hiding this comment

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

function name here is so generic , you need to specify which page you need to open just to make it easy for any one else understand what the function does and search about it easily despicably if you have large testing framework, you can refer to policies page to see how we name the function in page object model pattern.

self.page.get_by_role("link", name="Explorer").click()

def search(self, term):
Copy link
Contributor

Choose a reason for hiding this comment

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

function name here is so generic , you need to specify which control exactly you need to get just to make it easy for any one else understand what the function does and search about it easily despicably if you have large testing framework, you can refer to policies page to see how we name the function in page object model pattern.

self.page.goto(f"{self.url}/explorer/query?descending=false&terms={term}")
Copy link
Contributor

Choose a reason for hiding this comment

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

In automation testing you need to interact more with controls in the page instead of drop the URL easily in the address bar to make sure that this controls and fields respond correctly.
So in this case you need to catch the Filter& search icon in the page and select the value you need to Search by same as we do manually like in the below record

Explorer_Search.mp4



20 changes: 20 additions & 0 deletions test_weave_gitops_enterprise/explorer/test_search.py
Copy link
Contributor

Choose a reason for hiding this comment

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

we don't need to create a Folder for each section we add tests for, we just Append our tests files to the test_weave_gitops_enterprise and name the file a name refers to what exactly it tests so in this case the file name will be test_explorer_search.py

Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import os

from playwright.sync_api import Playwright, sync_playwright, expect
from pages.explorer_page import Explorer
import pytest

@pytest.mark.usefixtures("login")
class TestExplorer:

@pytest.fixture(autouse=True)
def _obj(self, login):
self.URL = os.getenv("URL")
self.page = login
self.explorer_page = Explorer(self.page, self.URL)

def test_search(self):
Copy link
Contributor

Choose a reason for hiding this comment

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

Test function name here is so generic also , you need to specify what exactly you need to test, you can refer to this file to see how we name the testing functions in page object model pattern.

self.explorer_page.open()
expect(self.page).to_have_url(f"{self.URL}/explorer/query")
self.explorer_page.search("flux-system")
expect(self.page.locator("tbody")).to_contain_text("flux-system")
Loading