# Actions

Concordia Language contains a set of **meta-actions** that can be used by different testing frameworks for generating test scripts. Concordia Compiler uses Intent Recognition (yes, like chatbots do) to understand sentences and extract the desired action to perform. Later these actions are sent to testing frameworks for conversion into commands.

{% hint style="info" %}
Concordia actions are recognized in **Variants**, **Test Cases**, and **Test Events**.
{% endhint %}

The following list presents the available actions and gives some examples on how to use them in sentences. We expect that you **do not have to memorize them** but, instead, **see the things you can do**. Try to write the sentences the way you speak, using *first person singular* (`I`) . When there is a UI Element in the sentence, embrace it with `{` and `}`, like `{this}`. The compiler will tell you whether it cannot understand some sentence you wrote. If you think it should have understood something, [please tell us](https://github.com/thiagodp/concordialang/issues/new). We'll try to augment the compiler's vocabulary to understand it the next time.

### `accept`

> Accepts a browser message or app message.

```gherkin
 # Simple alert
 When I accept the alert

 # Alert with a message
 When I accept the alert "Do you want to continue?"

 # Confirmation dialog
 When I accept the confirmation

 # Confirmation dialog with a message
 When I accept the confirmation "Do you want to continue?"

 # Popup dialog
 When I accept the popup

 # Popup dialog with a message
 When I accept the popup "Are you sure?"

 # Prompt dialog
 When I accept the prompt

 # Prompt dialog with a message
 When I accept the prompt "What's your name?"
```

### `amOn`

> Indicates a webpage or screen in which it is expected to be at.

```gherkin
 # URL
 Given that I am on "http://concordialang.org"

 # Contant
 Given that I am on [Some Page]
```

### `append`

> Adds a value to an element.

```gherkin
 # Append a value to a UI Element
 When I append "Foo" to {Foo}
 When I append 100 to {Bar}
 When I append [My Contant] to {Zoo}

 # Append a value to a UI literal
 When I append "Bar" to <#foo>
 When I append 200 to <#foo>
 When I append [My Contant] to <#zoo>
```

### `attachFile`

> Attaches a file. It selects a file and confirms its choice (e.g., clicks Open).

```gherkin
 When I attach the file "/path/to/file" to {Foo}
 When I attach the file [My File] to {Foo}

 When I attach the file "/path/to/file" to <#bar>
 When I attach the file [My File] to <#bar>
```

### `cancel`

> Cancels a browser message or app message.

```gherkin
 When I cancel the alert

 When I cancel the confirmation

 When I cancel the popup

 When I cancel the prompt
```

### `check`

> Checks a checkbox.

```gherkin
 When I check {Foo}

 When I check <#bar>
```

### `clear`

> Empties an input field or browser cookie

```gherkin
 When I clear {Foo}

 When I clear <#bar>

 When I clear the cookie "app"

 When I clear the cookie [App Cookie]
```

### `click`

> Clicks on something in the screen.

```gherkin
 When I click on {Foo}

 When I click on <#bar>

 When I click on "Some Text"

 When I click on [Value From Contant]
```

### `close`

> Closes a tab, a set of tabs, or an app (mobile only).

```gherkin
 When I close the current tab

 When I close the other tabs

 # Mobile only
 When I close the app
```

### `connect`

> Connects to a database.

The next sentence is for [Test Events](https://app.gitbook.com/s/-LyZeGFeFI9v0gasbqLP/language/language.md#test-events) only:

```gherkin
 When I connect to the database [TestDB]
```

### `disconnect`

> Disconnects from a database.

The next sentence is for [Test Events](https://app.gitbook.com/s/-LyZeGFeFI9v0gasbqLP/language/language.md#test-events) only:

```gherkin
 When I disconnect from the database [TestDB]
```

### `doubleClick`

> Performs a double click on something.

```gherkin
When I double click {Foo}

 When I double click <#bar>

 When I double click "Some Text"

 When I double click [My Contant]
```

### `drag`

> Drags and drops something to a widget.

```gherkin
 When I drag {Foo} to {Bar}

 When I drag <#foo> to <#bar>
```

### `fill`

> Indicates that a field is being filled. If desired, a value can be given. Otherwise, a value will be generated for the corresponding Test Case.

#### fill + target

```gherkin
 When I fill   {Foo}
 When I inform {Foo}
 When I enter  {Foo}
 When I type   {Foo}


 When I fill {Foo} with "foo"
 When I fill {Foo} with [My Contant]
 When I fill <#bar> with "bar"
 When I fill <#bar> with 3.1415


 When I type "bar" in {Foo}
 When I type "foo" in <#bar>
 When I type 3.1416 in {Zoo}
 When I type [My Contant] in <#zoo>
```

### `hide`

> Hides something.

```gherkin
 # Hides the device's keyboard - Mobile only
 When I hide the keyboard
```

### `install`

> Installs an app.

```gherkin
 When I install the app "com.example.android.myapp"
```

### `maximize`

> Maximizes a window or the browser.

```gherkin
 When I maximize the window
```

### `move`

> Moves the mouse cursor to a place or element.

```gherkin
 When I move the cursor to {Foo}
 When I move the cursor to <#bar>

 When I move the cursor to {Foo} at 100, 200
```

### `open`

> Opens something

```gherkin
 # Opens the device's notifications panel - Mobile only
 When I open the notifications panel
```

### `press`

> Presses a key or key combination, separated by comma.

```gherkin
 When I press "Enter"
 When I press "Control", "Alt", "Delete"
 When I press "Control", "S"
```

Some special keys (*case sensitive!*):

* `Add`
* `Alt`
* `ArrowDown` or `Down arrow`
* `ArrowLeft` or `Left arrow`
* `ArrowRight` or `Right arrow`
* `ArrowUp` or `Up arrow`
* `Backspace`
* `Command`
* `Control`
* `Del`
* `Divide`
* `End`
* `Enter`
* `Equals`
* `Escape`
* `F1` to `F12`
* `Home`
* `Insert`
* `Meta`
* `Multiply`
* `Numpad 0` to `Numpad 9`
* `Pause`
* `Pagedown` or `PageDown`
* `Pageup` or `PageUp`
* `Semicolon`
* `Shift`
* `Space`
* `Subtract`
* `Tab`

### `pull`

> Extracts a device's resource from a path.

```gherkin
 # Mobile only
 When I pull "/storage/emulated/0/DCIM/logo.png" to "some/path"
```

### `refresh`

> Refreshes/reloads the current page.

```gherkin
 When I refresh the page
 When I refresh the current page

 When I reload the page
 When I reload the current page
```

### `remove`

> Removes/uninstall an app by its internal name (mobile only).

```gherkin
 # Mobile only
 When I remove the app "com.example.android.myapp"
```

### `resize`

> Resizes a window.

```gherkin
 When I resize the window to 600, 400
```

### `rightClick`

> Performs a right click on something.

```gherkin
 When I right click {Foo}
 When I right click <#bar>
 When I right click "Some Text"
 When I right click [Contant]
```

### `run`

> Runs a console command or a database script (SQL command).

👉 Available for [Test Events](https://app.gitbook.com/s/-LyZeGFeFI9v0gasbqLP/language/language.md#test-events) only.

👉 *Commands and SQL scripts must be declared between single quotes (`'`), in a single line.*

*👉 SQL scripts must reference their database.*

```gherkin
 # Run a command in the console/terminal
 
 When I run the command 'rmdir foo'
 When I run the command './script.sh'
 When I run the command [My Command]
 
 # Run a SQL scripts in a database
 
 When I run the script 'INSERT INTO [MyDB].product ( name, price ) VALUES ( "Soda", 1.50 )'
 When I run the script 'INSERT INTO [MyDB].Users( UserName, UserSex, UserAge ) VALUES ( "Newton", "Male", 25 )'
 When I run the script 'INSERT INTO [MyDB].`my long table name`( `long column`, `another long column`) VALUES ("Foo", 10)'
 
 When I run the script 'UPDATE [MyDB].Users SET UserAge=26, UserStatus="online" WHERE UserName="Newton"'
 When I run the script 'UPDATE [MyDB].`my long table name` SET `long column` = "Bar" WHERE `another long column` = 70'
 
 When I run the script 'DELETE FROM [MyDB].Users WHERE UserName="Newton"'
 When I run the script 'DELETE FROM [MyDB].`my long table name` WHERE `another long column` = 70'
```

#### **SQL Syntax**

Concordia Compiler uses [database-js](https://github.com/mlaanderson/database-js) to access **databases and files** through SQL-like commands. The supported SQL syntax may vary from one database to another. Please see the [documentation of the corresponding driver](https://github.com/mlaanderson/database-js#drivers).

**JSON and CSV as databases:** INSERT accepts **JSON** objects or arrays as values. Example:

```gherkin
 When I run the script 'INSERT INTO [MyDB] VALUES { "name": "Mary", "surname": "Jane", "age": 21 }'
```

**Excel and Firebase databases:** Syntax similar to JSON and CSV databases. However, it has some limitations, as pointed out in [its documentation](https://github.com/mlaanderson/database-js-firebase) :

> *SQL commands are limited to SELECT, UPDATE, INSERT and DELETE. WHERE works well. JOINs are not allowed. GROUP BY is not supported. LIMIT and OFFSET are combined into a single LIMIT syntax: LIMIT \[offset,]number*

**INI databases:** INSERT and DELETE are not supported yet by [database-js-ini](https://github.com/mlaanderson/database-js-ini). UPDATE example:

```gherkin
 When I run the script 'UPDATE [MyDB] SET age = 22 WHERE name = "Mary"'
```

**SQLite databases:** Currently [database-js-sqlite](https://github.com/mlaanderson/database-js-sqlite) uses [sql.js](https://github.com/kripken/sql.js) that **doesn't persist the changes** in the file (only in memory).

### `saveScreenshot`

> Takes a screenshot an saves into a file.

```gherkin
 When I save a screenshot to "foo.png"

 When I take a photo to "bar.png"
```

### `scrollTo`

> Scrolls to a certain element.

```gherkin
 When I scroll to <#foo>
 When I scroll to {Bar}
```

### `see`

> Indicates that something can be seen. You can also **negate** the sentence to indicate something cannot be seen.

```gherkin
# Some text
 
 Then I see "Some Text"
 Then I see 3.1416
 Then I see [Some Contant]
  
 Then I do not see "Some Text"
 Then I don't see [Some Contant]
 
 Then see the text "Some Text"
 Then I don't see the text "Some Text"


# UI Element or a UI literal

 Then I see {Foo}
 Then I don't see <#bar> 

        
# Value is/isn't inside a UI Element or a UI literal

 Then I see "hello" in {foo}
 Then I see "world" in <#bar>
 
 Then I don't see "hello" in {foo}
 Then I don't see "world" in <#bar> 
 
 Then I do not see {Foo} with "hello"
 Then I don't see <bar> with "world"
 
 
# Attribute from a UI Element or UI literal 
 
 Then I see {Foo} with the attribute "maxlength" valued "200"

 Then I see the attribute "type" of <#bar> to be "text"


# CSS class or Style - WEB ONLY

 Then I see {Foo} with the class "primary-button"

 Then I see {Foo} with the style "color: blue"


# UI Element or ui literal is/isn't enabled

 Then I see {Foo} is enabled
 Then I see <#bar> is enabled
 
 Then I do not see {Foo} is enabled
 Then don't see <#bar> is enabled
 
 
# UI Element or ui literal is/isn't checked

 Then I see {Foo} is checked
 Then I see <#bar> is checked
 
 Then I do not see {Foo} is checked
 Then don't see <#bar> is checked


# Title

 Then I see "Some Text" in the title
 Then I don't see [My Constant] in the title
 
 Then I see the title with "foo"
 Then I don't see the title with [My Constant]
 
 
# URL 

 Then I see the url "/foo"
 Then I don't see the url "/bar"
 
 
# Cookie

 Then I see the cookie "foo"
 Then I don't see the cookie [My Cookie]
 

# App is installed/not installed - MOBILE ONLY

 Then I see that the app "com.example.android.myapp" is installed
  
 Then I see that the app "com.example.android.myapp" is not installed


# An activity - MOBILE ONLY

 Then I see that the current activity is ".HomeScreenActivity"
 
 # Device locked/unlocked - MOBILE ONLY
 
 Then I see that the device is locked
 
 Then I see that the device is locked
 
 # Device orientation - MOBILE ONLY
 
 Then I see that the orientation is landscape
 Then I see that the orientation is portrait
  
```

### `select`

> Selects a value for an element.

```gherkin
 When I select "foo" in {Foo}
 When I select [Contant] in <#bar>
```

### `shake`

> Shakes the device - MOBILE ONLY.

```gherkin
 When I shake the device
 When I shake the phone
 When I shake the tablet
```

### `swipe`

> Performs a swipe action - MOBILE ONLY

```gherkin
 # To a certain position
 When I swipe <#io.selendroid.myapp:id/LinearLayout1> to 100, 200
 
 # An UI Element/literal to another
 When I swipe {Foo} to {Bar}
 When I swipe <#foo> to <#bar>
 
 # Down
 When I swipe <#io.selendroid.myapp:id/LinearLayout1> down
 
 # Up
 When I swipe <#io.selendroid.myapp:id/LinearLayout1> up
 
 # Left
 When I swipe <#io.selendroid.myapp:id/LinearLayout1> left
 
 # Right
 When I swipe <#io.selendroid.myapp:id/LinearLayout1> right
 
```

### `switch`

> * Switches to a certain iframe and back to the application page; OR
> * Switches to a certain tab; OR
> * Switches an app to native mode or web mode - MOBILE ONLY.

**NOTE**: When switching to an **iframe**, all the commands that follow it will be applied to it.

```gherkin
# IFRAME

# To the first iframe

 When I switch to the iframe
 
# To a certain iframe
 
 When I switch to the iframe {My Frame}
 When I switch to the iframe <#frame1>
 
# To an iframe inside another iframe

 When I switch to the iframe {SubFrame 1} inside {Frame 1}
 When I switch to the iframe <#subframe1> inside <#frame1>
 
# Back to the application page

 When I switch to the application
 When I switch to the page  
  
# TAB

 When I switch to the next tab
 When I switch to the previous tab
 When I switch to the tab 3
 
 
 # MOBILE-WEB SWITCHING
 
 # To native app
 When I switch to native
 # To web app
 When I switch to web
 
```

### `tap`

> Performs a tap on an element - MOBILE ONLY

```gherkin
  When I tap {Confirm}
  When I tap <~confirm>

```

### `uncheck`

> Unchecks a checkbox.

```gherkin
 When I unckeck {Foo}
 When I uncheck <#bar>
 
 # Unchecks an element inside another element
 
 When I uncheck {Foo} in <#bar>
```

### `wait`

> Wait for something.

```gherkin
# -------
# ELEMENT
# -------

# An element

 When I wait for {Foo}
 When I wait for <#bar>
  
# An element to hide
 
 When I wait {Foo} to hide
 When I wait <#bar> to hide

# An element to be enabled
   
 When I wait {Foo} to be enabled
 When I wait <#bar> to be enabled
 
# An element to be visible
   
 When I wait {Foo} to be visible
 When I wait <#bar> to be visible

# An element to be invisible (same as to hide)
   
 When I wait {Foo} to be invisible
 When I wait <#bar> to be invisible

# Value inside element

 When I wait for the value "foo" in {Foo}
 When I wait for the value [My Constant] in <#bar>


# ----
# TEXT
# ----

 When I wait for the text "Foo"


# ----
# URL
# ---- 
 
 When I wait for the url "/foo"


# -------
# SECONDS
# -------

# Seconds

 When I wait 1 second
 When I wait 2 seconds
 
# Seconds for an element
 
 When I wait 1 second for {Foo}
 When I wait 5 seconds for <#bar>

# Seconds for an element to hide
 
 When I wait 1 second for {Foo} to hide
 When I wait 5 seconds for <#bar> to hide

# Seconds for an element to be enabled
 
 When I wait 1 second for {Foo} to be enabled
 When I wait 5 seconds for <#bar> to be enabled
 
# Seconds for an element to be visible
 
 When I wait 1 second for {Foo} to be visible
 When I wait 5 seconds for <#bar> to be visible

# Seconds for an element to be invisible (same as to hide)
 
 When I wait 1 second for {Foo} to be invisible
 When I wait 5 seconds for <#bar> to be invisible         
 
# Value inside element

 When I wait 1 second for the value "foo" in {Foo}
 When I wait 5 seconds for the value [My Constant] in <#bar>     
                                          
# Text
 
 When I wait 3 seconds for the text "Foo"
 
# URL
 
 When I wait 3 seconds for the url "/foo"
 
```
