I need help. I have written code for launch appium programmatically but it is not working
Main Java file:
package com.example;
import io.appium.java_client.android.AndroidDriver;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.testng.Assert;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
import com.example.pages.HannaPagesTest1;
import Demo.AppiumServerJava;
public class HannaTest1
{
AndroidDriver driver;
@BeforeTest
public void setUp() throws MalformedURLException, InterruptedException
{
AppiumServerJava appiumServer = new AppiumServerJava();
appiumServer.startServer();
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(“deviceName”, “ZX1B32FFXF”);
//capabilities.setCapability(“browserName”, “Android”);
// capabilities.setCapability(“platformVersion”, “4.4.2”);
//capabilities.setCapability(“platformName”, “Android”);
//capabilities.setCapability(“rotatable”, true);
capabilities.setCapability(“appPackage”, “com.hannainst.hannalab”);
capabilities.setCapability(“appActivity”,“com.hannainst.hannalab.ManagerActivity”);
driver = new AndroidDriver(new URL(“http://0.0.0.0:4723/wd/hub”), capabilities);
driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);
WebDriverWait wait = new WebDriverWait(driver, 300);
wait.until(ExpectedConditions.elementToBeClickable(By.className(“android.widget.RelativeLayout”)));
}
@Test(priority = 0)
public void checkAppElementPresent()
{
HannaPagesTest1 hanna=new HannaPagesTest1(driver);
if(hanna.verifyResult1(“No Probe Connected”))
System.out.println(“App Launch TC Passed”);
else
System.out.println(“App Launch TC Failed”);
}
@Test(priority = 1)
public void CheckAppVersion()
{
HannaPagesTest1 hanna=new HannaPagesTest1(driver);
if(hanna.verifyResult2("Version 2.0.0 Beta"))
System.out.println("App Version TC Passed");
else
System.out.println("App Version TC Failed");
}
@AfterTest
public void End() throws IOException
{
//driver.removeApp("com.hannainst.hannalab");
driver.resetApp();
driver.quit();
AppiumServerJava appiumServer = new AppiumServerJava();
appiumServer.stopServer();
//driver.close();
}
}
Java file 2:
package com.example.pages;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.PageFactory;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.pagefactory.AndroidFindBy;
import io.appium.java_client.pagefactory.AppiumFieldDecorator;
public class HannaPagesTest1
{
public HannaPagesTest1(AndroidDriver<WebElement> driver)
{
PageFactory.initElements( new AppiumFieldDecorator(driver), this);
}
@AndroidFindBy(id="com.hannainst.hannalab:id/textView19")
public static WebElement text1;
@AndroidFindBy(xpath="//*[@class='android.widget.ImageButton' and @content-desc='Navigate up']")
public static WebElement text2;
@AndroidFindBy(id="com.hannainst.hannalab:id/versionName")
public static WebElement text3;
public boolean verifyResult1(String result)
{
if(text1.getText().equals(result))
return true;
else
return false;
}
public boolean verifyResult2(String result)
{
text2.click();
if(text3.getText().equals(result))
return true;
else
return false;
}
}
Appium start File:
package Demo;
import org.openqa.selenium.remote.DesiredCapabilities;
import io.appium.java_client.service.local.AppiumDriverLocalService;
import io.appium.java_client.service.local.AppiumServiceBuilder;
import io.appium.java_client.service.local.flags.GeneralServerFlag;
public class AppiumServer {
private AppiumDriverLocalService service;
private AppiumServiceBuilder builder;
private DesiredCapabilities cap;
public void startServer() {
//Set Capabilities
cap = new DesiredCapabilities();
cap.setCapability("noReset", "false");
//Build the Appium service
builder = new AppiumServiceBuilder();
builder.withIPAddress("0.0.0.");
builder.usingPort(4723);
//builder.withCapabilities(cap);
builder.withArgument(GeneralServerFlag.SESSION_OVERRIDE);
builder.withArgument(GeneralServerFlag.LOG_LEVEL,"error");
//Start the server with the builder
service = AppiumDriverLocalService.buildService(builder);
service.start();
}
public void stopServer() {
service.stop();
}
public static void main(String[] args) throws InterruptedException {
AppiumServerJava appiumServer = new AppiumServerJava();
appiumServer.startServer();
appiumServer.stopServer();
}
}
Please let me know how to add appium lauch code into above files