Skip to content

Commit

Permalink
modify cli options
Browse files Browse the repository at this point in the history
  • Loading branch information
youssefsiam38 committed Aug 29, 2021
1 parent c643d46 commit d09c47f
Show file tree
Hide file tree
Showing 9 changed files with 39 additions and 190 deletions.
14 changes: 7 additions & 7 deletions README.MD
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<img align="right" width="209px" src="./logo/twistLogo.png">

Twist is a simple UI testing CLI tool written in Go (Golang). Its main purpose is to help developers write simple and easy read & write YAML-based instructions and assertions to drive the browser in no-time. (I built this tool to test my personal projects. Use it in your own cautious)
Twist is a simple UI testing CLI tool written in Go. Its main purpose is to help developers write simple and easy read & write YAML-based instructions and assertions to drive the browser in no-time. (I built this tool to test my personal projects. Use it in your own cautious)

This tool is not like selenium or its alternatives, it's less advanced (has only two assertions!). It is built over [chromedp](https://github.com/chromedp/chromedp) which built over DevTools Protocol (can not test firefox).

Expand Down Expand Up @@ -136,7 +136,7 @@ instructions:
```yaml
instructions:
- doubleClick:
selector: "#home"
selector: "#home"
```
or
```yaml
Expand All @@ -149,7 +149,7 @@ instructions:
```yaml
instructions:
- rightClick:
selector: "#home"
selector: "#home"
```
or
```yaml
Expand Down Expand Up @@ -185,7 +185,7 @@ instructions:
```yaml
instructions:
- submit:
selector: "#home"
selector: "#home"
```
or
```yaml
Expand Down Expand Up @@ -236,7 +236,7 @@ instructions:
```yaml
instructions:
- assertPathis:
name: "Blog home page assertion"
name: "Blog home page assertion"
expect: "https://youssefsiam.me"
```
or
Expand All @@ -251,7 +251,7 @@ this way the assertion name will be assertPathIs
```yaml
instructions:
- assertText:
name: "The text is `about` assertion"
name: "The text is `about` assertion"
expect: "about"
selector: "button#about"
selector: "button#about"
```
27 changes: 14 additions & 13 deletions cmd/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,39 +9,40 @@ import (
"github.com/youssefsiam38/twist/src/utils"
)

var initDir string

func init() {
initCmd.Flags().StringVarP(&initDir, "dir", "d", "twist", "The directory name you want to create")
}

var initCmd = &cobra.Command{
Use: "init",
Short: "Creates the twist folder with the defaults",
Long: `Creates the twist folder with the default values for you`,
Run: func(cmd *cobra.Command, args []string) {
if utils.FolderExist("twist") {
fmt.Println("twist folder is already exist")
if utils.FolderExist(initDir) {
fmt.Printf("%s folder is already exist", initDir)
} else {
err := os.Mkdir("twist", 0755)
err := os.Mkdir(initDir, 0755)
if err != nil {
fmt.Println(err)
}
err = os.Mkdir("twist/stories", 0755)
err = os.Mkdir(fmt.Sprintf("%s/stories",initDir), 0755)
if err != nil {
fmt.Println(err)
}

configBuf := []byte("execute: in order # or in parallel, if in parallel no need to specify the order\ntimeout: 70m\noutput: stdout # or filename\norder: \n- blog")
configBuf := []byte("execute: in order # or in parallel (not supported), if in parallel no need to specify the order\ntimeout: 70m\noutput: stdout # or filename (not supported)\norder: \n- blog")


err = ioutil.WriteFile("twist/config.yml", configBuf, 0755)
err = ioutil.WriteFile(fmt.Sprintf("%s/config.yml", initDir), configBuf, 0755)
if err != nil {
fmt.Println(err)
}

storyBuf := []byte(`execute: in order # or in parallel, if in parallel no need to specify the order
timeout: 70m
output: stdout # or filename
order:
- blog
`)
storyBuf := []byte("start: https://youssefsiam.me\nheadless: false\ntimeout: 1m\ninstructions:\n- waitFor: \n selector: \".blog-post-card-wrapper\"\n- assertPathIs: https://youssefsiam.me")

err = ioutil.WriteFile("twist/stories/blog.story.yml", storyBuf, 0755)
err = ioutil.WriteFile(fmt.Sprintf("%s/stories/blog.story.yml",initDir), storyBuf, 0755)
if err != nil {
fmt.Println(err)
}
Expand Down
10 changes: 6 additions & 4 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,21 @@ import (
"github.com/youssefsiam38/twist/src/handle"
)

var dir string

func init() {
rootCmd.AddCommand(versionCmd)
rootCmd.AddCommand(initCmd)
rootCmd.AddCommand(authorCmd)
// rootCmd.Flags().StringVarP(&Verbose, "version", "v", "", "Twist version")
rootCmd.Flags().StringVarP(&dir, "dir", "d", "twist", "The Twist directory name")
}

var rootCmd = &cobra.Command{
Use: "run the test flow",
Use: "twist",
Short: "Twist is a Simple UI testing tool",
Long: `A fast easy to read and write automation testing tool.Complete documentation is available at https://github.com/youssefsiam38/twist`,
Long: `A fast easy to read and write UI automation testing tool.Complete documentation is available at https://github.com/youssefsiam38/twist`,
Run: func(cmd *cobra.Command, args []string) {
if err := handle.Handle(); err != nil {
if err := handle.Handle(dir); err != nil {
fmt.Fprintf(os.Stderr, "Error: %v", err)
}
},
Expand Down
11 changes: 0 additions & 11 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,8 @@ go 1.16
require (
github.com/chromedp/cdproto v0.0.0-20210823203301-2c0adcc9edc4
github.com/chromedp/chromedp v0.7.4
github.com/gobuffalo/envy v1.9.0 // indirect
github.com/gobuffalo/logger v1.0.4 // indirect
github.com/gobuffalo/packr v1.30.1 // indirect
github.com/gobuffalo/packr/v2 v2.8.1 // indirect
github.com/karrick/godirwalk v1.16.1 // indirect
github.com/konsorten/go-windows-terminal-sequences v1.0.3 // indirect
github.com/logrusorgru/aurora/v3 v3.0.0
github.com/rogpeppe/go-internal v1.8.0 // indirect
github.com/sirupsen/logrus v1.8.1 // indirect
github.com/spf13/cobra v1.2.1
golang.org/x/crypto v0.0.0-20210817164053-32db794688a5 // indirect
golang.org/x/sys v0.0.0-20210823070655-63515b42dcdf // indirect
golang.org/x/term v0.0.0-20210615171337-6886f2dfbf5b // indirect
golang.org/x/tools v0.1.5 // indirect
gopkg.in/yaml.v2 v2.4.0
)
Loading

0 comments on commit d09c47f

Please sign in to comment.