Alejadro Sanchez-Giraldo commited on
Commit
7e6eae0
·
1 Parent(s): 4190c8f

improve test and docs for running

Browse files
Files changed (2) hide show
  1. README.md +6 -0
  2. test/test_chatbot.py +33 -17
README.md CHANGED
@@ -60,3 +60,9 @@ source myenv/bin/activate
60
  pip3 install -r requirements.txt
61
 
62
  LAUNCHDARKLY_SDK_KEY=$LAUNCHDARKLY_SDK_KEY streamlit run app.py
 
 
 
 
 
 
 
60
  pip3 install -r requirements.txt
61
 
62
  LAUNCHDARKLY_SDK_KEY=$LAUNCHDARKLY_SDK_KEY streamlit run app.py
63
+
64
+ ## Run test with pytest and playwright
65
+
66
+ ```bash
67
+ pytest --html=report.html --browser webkit --tracing on
68
+ ```
test/test_chatbot.py CHANGED
@@ -1,5 +1,5 @@
1
  import re
2
- from playwright.sync_api import Page, expect, Browser
3
 
4
  def test_has_title(page: Page):
5
  page.goto("http://localhost:8501")
@@ -9,19 +9,35 @@ def test_has_title(page: Page):
9
 
10
  def test_get_started_link(browser: Browser):
11
 
12
- for _ in range(30):
13
- # create a new incognito browser context
14
- context = browser.new_context()
15
- # create a new page inside context.
16
- page = context.new_page()
17
- # clear cache
18
- page.context.clear_cookies()
19
- page.goto("http://localhost:8501")
20
-
21
- # expect Sentiment Analysis Demo with AI Model Flags
22
- locator = page.locator('.main')
23
- expect(locator).to_contain_text("Sentiment Analysis Demo with AI Model Flags")
24
- # screenshot
25
- page.screenshot(path=f"test_get_started_link{_}.png")
26
- # dispose context once it is no longer needed.
27
- context.close()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import re
2
+ from playwright.sync_api import expect, Page, Browser
3
 
4
  def test_has_title(page: Page):
5
  page.goto("http://localhost:8501")
 
9
 
10
  def test_get_started_link(browser: Browser):
11
 
12
+ for _ in range(1):
13
+ # create a new incognito browser context
14
+ context = browser.new_context()
15
+ # create a new page inside context.
16
+ page = context.new_page()
17
+ page.goto("http://localhost:8501")
18
+
19
+ # expect Sentiment Analysis Demo with AI Model Flags
20
+ locator = page.locator('.main')
21
+ expect(locator).to_contain_text("Sentiment Analysis Demo with AI Model Flags")
22
+ # screenshot
23
+ page.screenshot(path=f"test_get_started_link{_}.png")
24
+ # dispose context once it is no longer needed.
25
+ context.close()
26
+
27
+ def test_sentiment_tesst(page: Page):
28
+ page.goto("http://localhost:8501")
29
+
30
+ #Set Array of names to test
31
+ names = ["Happy", "Sad", "Angry", "Excited", "Fearful", "Confused", "Surprised", "Disgusted", "Calm", "Bored"]
32
+
33
+ for name in names:
34
+ page.get_by_label("Enter text for sentiment analysis:").fill("This is a test sentiment phrase.")
35
+ page.get_by_label("Enter your name").fill(name)
36
+ page.click('button:has-text("Analyze")')
37
+ # Screeshot
38
+ locator = page.locator('.main')
39
+ expect(locator).to_contain_text("Using model:")
40
+ expect(locator).to_contain_text("Sentiment:")
41
+ page.screenshot(path=f"test_sentiment_tesst_{name}.png")
42
+ # refresh page
43
+ page.reload()