How to run using terminal on IntelliJ Idea using Maven?
21:30 05 May 2019

I'm new to IntelliJ IDEA and I would like to run my test through the terminal lines.

I already run my test using the Run button and my test are all passed. Now, my requirement in project is to run using the command lines/terminal. I really don't have any idea how to do it.

I'm using Appium as my tool for mobile automation.

This is all where my tests are located, C:\Users\ereyne\IdeaProjects\ioappium\src\test\java\io

Tests location

I already look on google but all are in high level, can anyone provide me step by step process on how to do it? Test java classes

This is my POM:



    4.0.0

    io.appium
    io.appium
    1.0-SNAPSHOT

    
        
        
            io.appium
            java-client
            7.0.0
        

        
        
            org.seleniumhq.selenium
            selenium-java
            3.141.59
        

        
        
            org.testng
            testng
            6.14.3
            test
        

        
        
            commons-lang
            commons-lang
            2.6
        
    


This is my code in IntelliJ:

//package io;//package appium;

import io.appium.java_client.remote.AndroidMobileCapabilityType;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.android.AndroidElement;
import io.appium.java_client.MobileElement;
import io.appium.java_client.remote.MobileCapabilityType;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.By;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import java.net.URL;
import java.net.MalformedURLException;

public class appium {

public AndroidDriver driver;
public WebDriverWait wait;
DesiredCapabilities dc = new DesiredCapabilities();
int CustomerNumber = 10088214;
int AccessCode = 44445555;
String SignIn = "/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.webkit.WebView/android.webkit.WebView/android.view.View/android.view.View/android.view.View[1]/android.view.View/android.view.View/android.view.View/android.view.View[2]/android.widget.Button[3]";
String MakeaPayment = "/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.webkit.WebView/android.webkit.WebView/android.view.View/android.view.View/android.view.View[1]/android.view.View/android.view.View/android.view.View[2]/android.view.View[2]/android.widget.Button[4]";

@BeforeMethod
public void setUp() throws MalformedURLException {
    dc.setCapability("deviceName", "Pixel XL API 28");
    dc.setCapability("udid", "ce041714789604830d"); //DeviceId from "adb devices" command //Tab S3-674ce8f9 S8-ce041714789604830d
    dc.setCapability("platformName", "Android");
    dc.setCapability("platformVersion", "9.0");
    dc.setCapability("skipUnlock","true");
    dc.setCapability("appPackage", "com.loans.smartmoney");
    dc.setCapability("appActivity","com.loans.smartmoney.MainActivity");
    dc.setCapability("noReset","true");
    dc.setCapability("automationName", "UiAutomator2");
    driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"),dc);
    wait = new WebDriverWait(driver, 30);
}

@Test
public void testLoginTest() {

    //Login
    wait.until(ExpectedConditions.visibilityOfElementLocated
            (By.xpath(SignIn)));
    driver.findElement(By.xpath(SignIn)).click();

    driver.findElement(By.className("android.view.View")).click();
    driver.findElement(By.className("android.widget.EditText")).sendKeys(String.valueOf(CustomerNumber));
    driver.findElements(By.className("android.widget.EditText")).get(1).click();
    driver.findElements(By.className("android.widget.EditText")).get(1).sendKeys(String.valueOf(AccessCode));
    driver.findElements(By.className("android.widget.Button")).get(1).click();

    wait.until(ExpectedConditions.visibilityOfElementLocated
            (By.xpath(MakeaPayment)));
}

@AfterMethod
public void tearDown() {
    driver.quit();
}
}

I run this is terminal: C:\Users\ereyne\IdeaProjects\ioappium>mvn appium.java

Errors: [ERROR] Unknown lifecycle phase "appium.java". You must specify a valid lifecycle phase or a goal in the format : or :[:]:. Available lifecycle phases are: validate, initialize, generat e-sources, process-sources, generate-resources, process-resources, compile, process-classes, generate-test-sources, process-test-sources, generate-test-resources, process-test-resources, test-compile, process-test-classes, test, prepare-package, package, pre-integr ation-test, integration-test, post-integration-test, verify, install, deploy, pre-clean, clean, post-clean, pre-site, site, post-site, site-deploy. -> [Help 1] [ERROR] [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch. [ERROR] Re-run Maven using the -X switch to enable full debug logging. [ERROR] [ERROR] For more information about the errors and possible solutions, please read the following articles:

I also try to run this in my terminal: C:\Users\ereyne\IdeaProjects\ioappium\src\test\java\io>javac appium.java

And the result is everything does not exist, just a sample error below.

appium.java:2: error: package io.appium.java_client does not exist import io.appium.java_client.MobileBy;

maven intellij-idea