Skip to content

Commit

Permalink
Merge dev to main (major changes) (#9)
Browse files Browse the repository at this point in the history
* implemented quick selector tool

* implement test prompt file (#2)

* Create npm-publish.yml

* Update npm-publish.yml

* Update npm-publish.yml

* fix workflow: use pnpm

* fix workflow: add set version to release tag

* workflow: add checkout fetch-depth: 0

* 1.0.2

* 1.0.3

* patch 1.0.2

* fix src import

* 1.0.3

* wip generate test from test prompt file

* working testsuite generator

* move testsuite generator to new directory

* refactor cli

* update project tests

* Tidy test file mode (#3)

* tidy cli code

* make gen command output steps json

* update README and package.json

* implements press key action in webcontroller

* remove http.controller.ts

* update default prompts

* update test and remove unused

* implements press key action in webcontroller (#6)

* CLI decoupling to new function (#5)

* implements press key action in webcontroller

* remove http.controller.ts

* update default prompts

* update test and remove unused

* extract cli run to new function

* add selenium test generation support (#7)

* wip selenium test generator

* MVP working selenium test generate

* add interface for translator

* move templates to new dir

* add more translation for selenium

* fix selenium bugs

Template unknown translator: selenium
Testsuite generator unknown translator selenium

* removed prompt mode (#8)

* update project tests

* update README.md
  • Loading branch information
wuttinanhi authored Nov 23, 2024
1 parent a4c911f commit ab7a512
Show file tree
Hide file tree
Showing 55 changed files with 1,369 additions and 642 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -136,3 +136,4 @@ screenshot.png
app.test.ts
gen.test.ts
*.test.ts
examples/java_selenium/src/test/java/BasicTest.java
158 changes: 89 additions & 69 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -1,70 +1,90 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
// From https://medium.com/@mtiller/debugging-with-typescript-jest-ts-jest-and-visual-studio-code-ef9ca8644132
// {
// "name": "Debug Jest Tests",
// "type": "node",
// "request": "launch",
// "program": "${file}",
// "runtimeArgs": [
// "--inspect-brk",
// "${workspaceRoot}/node_modules/.bin/jest",
// "--runInBand"
// ],
// "console": "integratedTerminal",
// "internalConsoleOptions": "neverOpen",
// "skipFiles": [
// // Node.js internal core modules
// "<node_internals>/**",
// // Ignore all dependencies (optional)
// "${workspaceFolder}/node_modules/**",
// ],
// },
{
"name": "tsx",
"type": "node",
"request": "launch",
// Debug current file in VSCode
"program": "${file}",
/*
* Path to tsx binary
* Assuming locally installed
*/
"runtimeExecutable": "tsx",
/*
* Open terminal when debugging starts (Optional)
* Useful to see console.logs
*/
"console": "integratedTerminal",
"internalConsoleOptions": "neverOpen",
// Files to exclude from debugger (e.g. call stack)
"skipFiles": [
// Node.js internal core modules
"<node_internals>/**",
// Ignore all dependencies (optional)
"${workspaceFolder}/node_modules/**",
],
},
{
"type": "node",
"request": "launch",
"name": "Vitest Debug Current Test File",
"autoAttachChildProcesses": true,
"skipFiles": [
"<node_internals>/**",
"**/node_modules/**"
],
"program": "${workspaceRoot}/node_modules/vitest/vitest.mjs",
"args": [
"run",
"${relativeFile}"
],
"smartStep": true,
"console": "integratedTerminal"
}
]
}
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
// From https://medium.com/@mtiller/debugging-with-typescript-jest-ts-jest-and-visual-studio-code-ef9ca8644132
// {
// "name": "Debug Jest Tests",
// "type": "node",
// "request": "launch",
// "program": "${file}",
// "runtimeArgs": [
// "--inspect-brk",
// "${workspaceRoot}/node_modules/.bin/jest",
// "--runInBand"
// ],
// "console": "integratedTerminal",
// "internalConsoleOptions": "neverOpen",
// "skipFiles": [
// // Node.js internal core modules
// "<node_internals>/**",
// // Ignore all dependencies (optional)
// "${workspaceFolder}/node_modules/**",
// ],
// },
{
"name": "tsx",
"type": "node",
"request": "launch",
// Debug current file in VSCode
"program": "${file}",
/*
* Path to tsx binary
* Assuming locally installed
*/
"runtimeExecutable": "tsx",
/*
* Open terminal when debugging starts (Optional)
* Useful to see console.logs
*/
"console": "integratedTerminal",
"internalConsoleOptions": "neverOpen",
// Files to exclude from debugger (e.g. call stack)
"skipFiles": [
// Node.js internal core modules
"<node_internals>/**",
// Ignore all dependencies (optional)
"${workspaceFolder}/node_modules/**"
]
},
{
"name": "Debug gen command",
"type": "node",
"request": "launch",
// Debug current file in VSCode
"program": "index.ts",
/*
* Path to tsx binary
* Assuming locally installed
*/
"runtimeExecutable": "tsx",
/*
* Open terminal when debugging starts (Optional)
* Useful to see console.logs
*/
"console": "integratedTerminal",
"internalConsoleOptions": "neverOpen",
// Files to exclude from debugger (e.g. call stack)
"skipFiles": [
// Node.js internal core modules
"<node_internals>/**",
// Ignore all dependencies (optional)
"${workspaceFolder}/node_modules/**"
],
"args": ["gen", "--headless", "false", "--verbose", "-f", "examples/testprompts/todo.xml"]
},
{
"type": "node",
"request": "launch",
"name": "Vitest Debug Current Test File",
"autoAttachChildProcesses": true,
"skipFiles": ["<node_internals>/**", "**/node_modules/**"],
"program": "${workspaceRoot}/node_modules/vitest/vitest.mjs",
"args": ["run", "${relativeFile}"],
"smartStep": true,
"console": "integratedTerminal"
}
]
}
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
"editor.inlineSuggest.suppressSuggestions": false,
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.formatOnSave": true
}
},
"typescript.tsdk": "node_modules/typescript/lib"
}
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,12 @@ Generate testsuite from test prompt file ([todo.xml](examples/testprompts/todo.x
aitestgen gen -f examples/testprompts/todo.xml
```

the generated output will be saved at `todo.testsuite.test.ts`
the generated output will be saved at `todo.test.ts`

## Choosing a Model

Currently, the best-performing model for test generation is **gpt-4o-mini**.
We are still searching for the ideal Ollama model for a self-hosted solution.

## Contributing

Expand Down
2 changes: 2 additions & 0 deletions examples/java_selenium/.gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Auto detect text files and perform LF normalization
* text=auto
26 changes: 26 additions & 0 deletions examples/java_selenium/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Compiled class file
*.class

# Log file
*.log

# BlueJ files
*.ctxt

# Mobile Tools for Java (J2ME)
.mtj.tmp/

# Package Files #
*.jar
*.war
*.nar
*.ear
*.zip
*.tar.gz
*.rar

# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*
replay_pid*

target
21 changes: 21 additions & 0 deletions examples/java_selenium/.vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "java",
"name": "Current File",
"request": "launch",
"mainClass": "${file}"
},
{
"type": "java",
"name": "Main",
"request": "launch",
"mainClass": "com.example.Main",
"projectName": "demo"
}
]
}
10 changes: 10 additions & 0 deletions examples/java_selenium/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"java.configuration.updateBuildConfiguration": "automatic",
"[xml]": {
"editor.defaultFormatter": "redhat.vscode-xml",
"editor.formatOnSave": true,
"editor.autoClosingBrackets": "never",
"files.trimFinalNewlines": true
},
"java.compile.nullAnalysis.mode": "automatic"
}
21 changes: 21 additions & 0 deletions examples/java_selenium/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2024 wuttinanhi

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
6 changes: 6 additions & 0 deletions examples/java_selenium/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# aitestgen java test

## Run test
```bash
mvn test
```
32 changes: 32 additions & 0 deletions examples/java_selenium/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.example</groupId>
<artifactId>demo</artifactId>
<version>1.0-SNAPSHOT</version>

<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<selenium.version>4.26.0</selenium.version>
</properties>

<dependencies>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>${selenium.version}</version>
</dependency>

<!-- https://mvnrepository.com/artifact/org.junit.jupiter/junit-jupiter-engine -->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.11.3</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
7 changes: 7 additions & 0 deletions examples/java_selenium/src/main/java/com/example/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.example;

public class Main {
public static void main(String[] args) {
System.out.println("Hello world!");
}
}
48 changes: 48 additions & 0 deletions examples/java_selenium/src/test/java/BasicTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import static org.junit.jupiter.api.Assertions.assertEquals;

import java.time.Duration;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.support.ui.WebDriverWait;

public class BasicTest {

WebDriver driver;

@BeforeEach
public void setup() {
driver = new ChromeDriver();
}

@AfterEach
public void teardown() {
driver.quit();
}

@Test
public void SimpleTest() {
driver.get("https://www.selenium.dev/selenium/web/web-form.html");

WebElement textInput = driver.findElement(By.cssSelector("#my-text-id"));

WebElement submitButton = driver.findElement(By.cssSelector(".btn"));

textInput.sendKeys("hello");

submitButton.click();

new WebDriverWait(driver, Duration.ofSeconds(10)).until(webDriver -> ((JavascriptExecutor) webDriver).executeScript("return document.readyState").equals("complete"));

WebElement successMessage = driver.findElement(By.cssSelector("#message"));
String textsuccessMessage = successMessage.getText();
assertEquals("Received!", textsuccessMessage);

driver.quit();
}
}
19 changes: 19 additions & 0 deletions examples/testprompts/ollama.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<testsuite>
<name>Ollama Test</name>
<output>todo.test.ts</output>
<language>typescript</language>
<translator>puppeteer</translator>
<provider>ollama</provider>
<ollamahost>http://localhost:11434</ollamahost>
<model>qwen2.5-coder:7b-instruct-q8_0</model>
<testcases>
<testcase>
<name>Should add a todo</name>
<prompt>
1. go to https://microsoftedge.github.io/Demos/demo-to-do/
2. add a todo "Cook Dinner" to the list
3. expected added todo "Cook Dinner" in the list
</prompt>
</testcase>
</testcases>
</testsuite>
Loading

0 comments on commit ab7a512

Please sign in to comment.