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

UI Automation Tests for LLM Studio #561

Merged
merged 26 commits into from Feb 12, 2024
Merged

UI Automation Tests for LLM Studio #561

merged 26 commits into from Feb 12, 2024

Conversation

itsmunishbhardwaj
Copy link
Collaborator

@itsmunishbhardwaj itsmunishbhardwaj commented Jan 12, 2024

How to run the tests

  • To run tests locally
     export LOCAL_LOGIN=True
     export PYTEST_BASE_URL=localhost:10101
     make llmstudio
     make test-ui
  • To run tests on platform with okta login like: https://internal-genai.dedicated.h2o.ai/
     export OKTA_USER=
     export OKTA_PASSWORD=
     export PYTEST_BASE_URL=
     make test-ui
  • To run tests on platform with keycloak login like: https://cloud-qa.h2o.ai/
     export KEYCLOAK_USER=
     export KEYCLOAK_PASSWORD=
     export PYTEST_BASE_URL=
     make test-ui

Test results are stored at reports/junit_ui.xml

Makefile Outdated
@@ -142,4 +172,4 @@ build-doc-locally: # Bundles your website into static files for production
cd documentation && npm run build

serve-doc-locally: # Serves the built website locally
cd documentation && npm run serve
cd documentation && npm run serve
Copy link

Choose a reason for hiding this comment

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

missing new line

Pipfile Outdated
pytest-bdd = "==6.1.1"
playwright = "==1.40.0"
hac-playwright = { file = "http://h2o-public-test-data.s3.amazonaws.com/e2e-testing/hac_playwright-1.40.0-py3-none-any.whl" }
pytest-base-url = "==2.0.0"
Copy link

Choose a reason for hiding this comment

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

missing new line

And I run the experiment
Then I should see the test-experiment should finish successfully
When I delete experiment test-experiment
Then I should not see the experiment test-experiment
Copy link

Choose a reason for hiding this comment

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

missing new line

# If the heading is present, click the "I agree" button
page.get_by_role("button", name="I agree").click()
else:
return 1
Copy link

Choose a reason for hiding this comment

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

  1. this method has None return type
  2. the return value is not used anywhere in the code
    thus entire section could be removed:
else:
        return 1

Makefile Outdated Show resolved Hide resolved
Copy link
Contributor

@maxjeblick maxjeblick left a comment

Choose a reason for hiding this comment

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

I still have issues running the tests locally (make test-ui-local), in particular it fails on page.goto(base_url) with base_url being an empty string.

tests/ui/test.py Outdated Show resolved Hide resolved
from hac_playwright.pages.base import BasePage
from playwright.sync_api import expect

CLOUD_FILESYSTEM_PATH = "/home/llmstudio/mount/data/user/"
Copy link
Contributor

Choose a reason for hiding this comment

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

As discussed, this won't work for local tests.
Probably an env variable in the makefile together with an if-else condition will do the job (unless there's a more direct way of detecting running on the cloud):

test-ui-local: 
	$LOCAL_TEST=true \
        (PW_DEBUG) $(PIPENV) run pytest \ ...

Within the python code:
if "LOCAL_TEST" in os.environ

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I can create an env variable to store the local directory to run the tests locally. WDYT? eg:
export FILESYSTEM_PATH=<path to local filesystem>
you can manually export this env var to add path which shall trump $CLOUD_FILESYSTEM_PATH

Copy link
Contributor

Choose a reason for hiding this comment

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

There may be other places where one may need to distinguish between local vs. cloud (e.g. disable login for local), having a flag may be more flexible.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

makes sense yess

Copy link

Choose a reason for hiding this comment

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

In general, Page Objects should not contain any test logic and test data, like specific paths, names etc.
It's just an abstraction layer to express your tests steps.
So all paths, names belong to test cases/fixtures only.

Then I should see the test-experiment should finish successfully
When I delete experiment test-experiment
Then I should not see the experiment test-experiment

Copy link

Choose a reason for hiding this comment

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

Line 25 contains spaces " ", but it should be just new line character at the end of 24

from hac_playwright.pages.base import BasePage
from playwright.sync_api import expect

CLOUD_FILESYSTEM_PATH = "/home/llmstudio/mount/data/user/"
Copy link

Choose a reason for hiding this comment

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

In general, Page Objects should not contain any test logic and test data, like specific paths, names etc.
It's just an abstraction layer to express your tests steps.
So all paths, names belong to test cases/fixtures only.

tests/ui/llm_studio_page.py Outdated Show resolved Hide resolved

def view_experiment_page(self):
locator = self.page.get_by_role("button", name="View experiments")
locator.click()
Copy link

Choose a reason for hiding this comment

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

  1. self.page.get_by_role("button", name="View experiments").click()
  2. shouldn't we wait for the experiments page to be displayed?

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 dont have to

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Is it failing for you?

self.page.wait_for_timeout(3000)

def experiment_name(self, name: str):
locator = self.get_by_test_id(self.EXPERIMENT_NAME_SELECTOR)
Copy link

Choose a reason for hiding this comment

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

self.get_by_test_id(self.EXPERIMENT_NAME_SELECTOR).fill(name)

locator.fill(name)

def llm_backbone(self, value: str):
locator = self.page.get_by_role("combobox", name="LLM Backbone")
Copy link

Choose a reason for hiding this comment

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

self.page.get_by_role("combobox", name="LLM Backbone").fill(value)


@when("I login to LLM Studio", target_fixture="llm_studio")
def login_to_llm_studio(logger: logging.Logger, page: Page, base_url: str):
okta_user = os.environ.get("OKTA_USER")
Copy link

Choose a reason for hiding this comment

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

what if we deploy LLM Studio to GCP env with keycloak instead of Okta?

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 need account for that yes. Do you know how to achieve this?

Copy link

Choose a reason for hiding this comment

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

jenkins has secrets for cloud-qa and managed cloud

Pipfile Outdated
@@ -68,3 +68,7 @@ types-pyyaml = ">=6.0"
types-requests = ">=2.31"
types-toml = ">=0.10"
wheel = "==0.41.0"
pytest-bdd = "==6.1.1"
playwright = "==1.40.0"
hac-playwright = { file = "http://h2o-public-test-data.s3.amazonaws.com/e2e-testing/hac_playwright-1.40.0-py3-none-any.whl" }
Copy link
Contributor

Choose a reason for hiding this comment

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

This is currently blocking using 1.40

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

okay, installation the previous available version 1.38.0 instead

Makefile Outdated
Comment on lines 23 to 24
$(PIP) install pip --upgrade
$(PIP) install "pipenv>=2023.11.15"
Copy link
Collaborator

Choose a reason for hiding this comment

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

let's stick to what is on main branch, if not causing troubles.
Fixed pip,pipenv version and newer than your min. pipenv


.PHONY: setup-no-flash
setup-no-flash: pipenv
$(PIPENV) install --verbose --python $(PYTHON_VERSION)

setup-ui: pipenv
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why does it need another make command, why is -dev not enough? It should get some coverage in the README.md or any other appropriate docs how the tests are to be used.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Probably designed to be run on a remote machine connecting to another instance? Again, should get coverage in docs why it has been designed this way and how it is to be used.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

precisely, its designed to be able to run from a remote machine. I'll add documentation coverage

Pipfile Outdated
@@ -68,3 +68,7 @@ types-pyyaml = ">=6.0"
types-requests = ">=2.31"
types-toml = ">=0.10"
wheel = "==0.41.0"
pytest-bdd = "==6.1.1"
playwright = "==1.40.0"
Copy link
Collaborator

Choose a reason for hiding this comment

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

afaik, playwright is not needed when you already specify hac-playwright. Please confirm.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

youre right, works without playwright

Makefile Show resolved Hide resolved
Copy link
Contributor

@maxjeblick maxjeblick left a comment

Choose a reason for hiding this comment

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

Thanks a lot for adding the missing Ui tests!
PR looks go to me, we can address subsequent refinements in upcoming PRs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants