MichaelKentBurns / MKB-cohort-1-Demo

Where the MichaelKentBurns.com students in cohort-1 can demonstrate what they have learned
GNU General Public License v3.0
5 stars 0 forks source link

Explore automated testing and demonstrate something. #4

Closed MichaelKentBurns closed 1 week ago

MichaelKentBurns commented 2 months ago

We need to test our code, and we first start with just simple user interaction using the browser. We follow a simple script and do the actions and then note the visual results.

But, doing that over and over is very tedious. We want a way to capture that interaction with the web page and have a script that will do it for us. We should be able to replay that over and over while changing code to make sure we don't break it.

I'll find a way to do that and demonstrate it next week.

MichaelKentBurns commented 2 months ago

There is a testing framework that is a Chrome extension, its name is Selenium. https://en.wikipedia.org/wiki/Selenium_(software)

MichaelKentBurns commented 1 month ago

Setup:

  1. Install the Selenium extension to your Chrome browser: Selenium IDE.
  2. Pin that to your extensions in the title bar of Chrome.

We should keep a library of tests in the projects test directory. I have created one and pushed it to the project: test/SeleniumTestOfSurveyApp.side.

MichaelKentBurns commented 1 month ago

I changed my mind for now and decided to put the selenium files into test/automate directory for now: test/automate/test-demo.MKB.com-Survey-Demo.side

I captured a number of screen images in test/images I included a .webloc file pointing to the main page: https://www.selenium.dev/selenium-ide/ I saved a .pdf file of the command line interface doc Command-line-Runner-Selenium-IDE.pdf That is an easy install and allows you to run one or all the tests from a shell.

MichaelKentBurns commented 1 month ago

Here is the text of my installation and execution of the command line tests:

michael@Logos automate % npm install -g selenium-side-runner npm warn deprecated inflight@1.0.6: This module is not supported, and leaks memory. Do not use it. Check out lru-cache if you want a good and tested way to coalesce async requests by a key value, which is much more comprehensive and powerful. npm warn deprecated glob@7.2.3: Glob versions prior to v9 are no longer supported npm warn deprecated glob@7.2.3: Glob versions prior to v9 are no longer supported npm warn deprecated glob@7.2.3: Glob versions prior to v9 are no longer supported npm warn deprecated glob@7.2.3: Glob versions prior to v9 are no longer supported

added 380 packages in 16s

44 packages are looking for funding run npm fund for details npm notice npm notice New minor version of npm available! 10.7.0 -> 10.8.1 npm notice Changelog: https://github.com/npm/cli/releases/tag/v10.8.1 npm notice To update run: npm install -g npm@10.8.1 npm notice michael@Logos automate % npm install -g chromedriver

added 63 packages in 8s

2 packages are looking for funding run npm fund for details npm notice npm notice New minor version of npm available! 10.7.0 -> 10.8.1 npm notice Changelog: https://github.com/npm/cli/releases/tag/v10.8.1 npm notice To update run: npm install -g npm@10.8.1 npm notice michael@Logos automate % ls Command-line Runner · Selenium IDE.pdf images test-demo.MKB.com-Survey-Demo.side michael@Logos automate % ls -latr total 960 drwxr-xr-x 8 michael staff 256 Jun 1 17:34 .. -rw-r--r--@ 1 michael staff 23143 Jun 20 11:48 test-demo.MKB.com-Survey-Demo.side drwxr-xr-x 7 michael staff 224 Jun 20 14:43 images -rw-r--r--@ 1 michael staff 6148 Jun 20 14:47 .DS_Store drwxr-xr-x 6 michael staff 192 Jun 20 14:47 . -rw-r--r--@ 1 michael staff 455308 Jun 20 14:47 Command-line Runner · Selenium IDE.pdf michael@Logos automate % mv 'Command-line Runner · Selenium IDE.pdf' Command-line-Runner-Selenium-IDE.pdf michael@Logos automate % selenium-side-runner zsh: command not found: selenium-side-runner michael@Logos automate % csh -l [Logos:MKB-cohort-1-Demo/test/automate] michael% selenium-side-runner Usage: selenium-side-runner [options] your-project-glob-here-.side [variadic-project-globs-.side]

Options: -V, --version output the version number --base-url [url] Override the base URL that was set in the IDE -c, --capabilities [list] Webdriver capabilities -j, --jest-options [list] Options to configure Jest, wrap in extra quotes to allow shell to process (default: "\"\"") -s, --server [url] Webdriver remote server -r, --retries [number] Retry tests N times on failures, thin wrapper on jest.retryTimes (default: 0) -f, --filter [string] Run suites matching name, takes a regex without slashes, eg (^(hello|goodbye).$) -w, --max-workers [number] Maximum amount of workers that will run your tests, defaults to number of cores -t, --timeout [number] The maximimum amount of time, in milliseconds, to spend attempting to locate an element. (default: 15000) (default: 15000) -T, --jest-timeout [number] The maximimum amount of time, in milliseconds, to wait for a test to finish. (default: 60000) (default: 60000) -x, --proxy-type [type] Type of proxy to use (one of: direct, manual, pac, socks, system) -y, --proxy-options [list] Proxy options to pass, for use with manual, pac and socks proxies -n, --config-file [filepath] Use specified YAML file for configuration. (default: .side.yml) -o, --output-directory [directory] Write test results as json to file in specified directory. Name will be based on timestamp. -z, --screenshot-failure-directory [directory] Write screenshots of failed tests to file in specified directory. Name will be based on test + timestamp. -f, --force Forcibly run the project, regardless of project's version -d, --debug Print debug logs -D, --debug-startup Print debug startup logs -X, --debug-connection-mode Debug driver connection mode -h, --help display help for command [Logos:MKB-cohort-1-Demo/test/automate] michael% ls -l total 944 -rw-r--r--@ 1 michael staff 455308 Jun 20 14:47 Command-line-Runner-Selenium-IDE.pdf drwxr-xr-x 7 michael staff 224 Jun 20 14:43 images -rw-r--r--@ 1 michael staff 23143 Jun 20 11:48 test-demo.MKB.com-Survey-Demo.side [Logos:MKB-cohort-1-Demo/test/automate] michael% selenium-side-runner .side info: Running test Start at the demo.MKB.com dashboard and complete the front end survey with some wandering. info: Finished test Start at the demo.MKB.com dashboard and complete the front end survey with some wandering. Failure FAIL ../../../../../../../../../Users/Michael/npm/lib/node_modules/selenium-side-runner/dist/main.test.js (24.966 s) Running project test-demo.MKB.com-Survey-Demo Running suite Default Suite ✕ Running test Start at the demo.MKB.com dashboard and complete the front end survey with some wandering. (24628 ms)

● Running project test-demo.MKB.com-Survey-Demo › Running suite Default Suite › Running test Start at the demo.MKB.com dashboard and complete the front end survey with some wandering.

Operation timed out during type:id=last-name:Burns

  at Timeout._onTimeout (node_modules/@seleniumhq/side-runtime/src/playback-tree/command-node.ts:187:13)

Test Suites: 1 failed, 1 total Tests: 1 failed, 1 total Snapshots: 0 total Time: 24.996 s Ran all test suites within paths "/Users/Michael/npm/lib/node_modules/selenium-side-runner/dist/main.test.js". console.warn Unexpected error occured during command: type-id=last-name-Burns

  at CommandNode.handleTransientError (node_modules/@seleniumhq/side-runtime/src/playback-tree/command-node.ts:234:15)
  at node_modules/@seleniumhq/side-runtime/src/playback-tree/command-node.ts:197:18

console.error ECONNREFUSED connect ECONNREFUSED 127.0.0.1:55269

  at CommandNode.handleTransientError (node_modules/@seleniumhq/side-runtime/src/playback-tree/command-node.ts:240:17)
  at node_modules/@seleniumhq/side-runtime/src/playback-tree/command-node.ts:197:18

console.error Command failure: type-id=last-name-Burns

  at CommandNode.handleTransientError (node_modules/@seleniumhq/side-runtime/src/playback-tree/command-node.ts:245:15)
  at node_modules/@seleniumhq/side-runtime/src/playback-tree/command-node.ts:197:18

Jest did not exit one second after the test run has completed.

'This usually means that there are asynchronous operations that weren't stopped in your tests. Consider running Jest with --detectOpenHandles to troubleshoot this issue. [Logos:MKB-cohort-1-Demo/test/automate] michael% pwd /Volumes/PRO-G40/Michael/Development/MKB/Cohort-1/MKB-cohort-1-Demo/test/automate

MichaelKentBurns commented 1 month ago

I will demonstrate this next meeting. Monday June 24th if that works out.

MichaelKentBurns commented 1 week ago

This story has been a good way to introduce some new automated testing tools available to us. I will at some point add this to a new page in the training site. But, for this project, I'm closing this issue, but it will remain here (in a closed state) for documentation purposes.