How to test all the test cases using appium and java

Hi all,

I want to test all the test cases for login functionality using appium. I am using excel sheet to read the input data and printing the output in another excel sheet.

Below are my test cases:

  1. correct username,correct password
  2. Enter input(incorrect )username and password on the respective fields 2)click submit/login
  3. valid username and empty password
  4. empty username and valid password
  5. username and password are empty.

I want to test all these test cases in same appium session for android.

Hi sankar
You can cover the positive and negative scenario of login module, for that you have to create the data driven framework.:slight_smile:

Hi Amit,

I am using dd frame work but unable to print the output in excel sheet. What conditions i need to check after i click on Login button.

Below is my code, please go through it

package login;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.net.URL;
import java.util.concurrent.TimeUnit;

import org.junit.After;
import org.junit.Before;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.openqa.selenium.support.ui.Select;
import org.testng.annotations.Test;

import io.appium.java_client.MobileBy;
import io.appium.java_client.android.AndroidDriver;
import jxl.Sheet;
import jxl.Workbook;
import jxl.write.Label;
import jxl.write.WritableSheet;
import jxl.write.WritableWorkbook;

import org.testng.annotations.BeforeTest;
import org.testng.Assert;
import org.testng.annotations.AfterClass;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeClass;

public class customer_login {
public WebDriver driver;
public String str;
String Text = “Login • TATX sharjeelbaig®gmail.com 'Password 0 Please enter Password minimum 6-digits FORGOT PASSWORD? LOGIN WITH f raceboo $8 goosIs “(ksername OR E (Password L TATX Please enter Emailld Cmh FORGOT PASSWORD? LOGIN WITH f faceboo $8 000010”;
@Test
public void f() throws Exception{

driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);

  Thread.sleep(3000);

FileInputStream fi=new FileInputStream(“D:\Sankar\workspace\Tatx.xls”);
Workbook w=Workbook.getWorkbook(fi);
Sheet s=w.getSheet(“Signin”);
FileOutputStream fo=new FileOutputStream(“D:\Sankar\workspace\Tatx_Results.xls”);
WritableWorkbook wb=Workbook.createWorkbook(fo);
WritableSheet ws=wb.createSheet(“tatx1”, 0);

String[] sh=w.getSheetNames();
System.out.println("No of sheets :"+sh.length);

for (int i = 1; i < 2; i++) {
try{
System.out.println(“P”);
driver.findElement(By.name(“SIGN IN”)).click();

driver.findElement(By.name("Username OR Email")).clear();

driver.findElement(By.id("com.tatx.userapp:id/et_email")).sendKeys(s.getCell(0, i).getContents());

driver.findElement(By.id("com.tatx.userapp:id/et_password")).clear();

driver.findElement(By.id("com.tatx.userapp:id/et_password")).sendKeys(s.getCell(1, i).getContents());

driver.findElement(By.name("SIGN IN")).click();

if (Text.contains("Please enter Password minimum 6-digits Please enter Emailld")) {
	str = "Failed";
	System.out.println(str);
	
}
else {
	str = "Passed";
	System.out.println(str);
}
/*Assert.assertTrue(Text.contains("Please enter Password minimum 6-digits Please enter Emailld"),"Please enter Password minimum 6-digits Please enter Emailld");
System.out.println("Not showing error");*/

Thread.sleep(3000);
String st = driver.findElement(MobileBy.name(“Order”)).getText();
System.out.println(st);
Assert.assertEquals(“Order”, st);
if (“Order”==st) {

	str="Pass";	
}
else {
	str="Fail";
}	
}
catch (Exception e) {
}

Label result=new Label(3, i, str);
ws.addCell(result);

for(int j=0; j<s.getColumns(); j++)
{
System.out.println(s.getCell(j, i).getContents());
Label un=new Label(j, i, s.getCell(j, i).getContents());
ws.addCell(un);
}
}
Label or=new Label(0,0,“Username”);
Label dn=new Label(1,0,“Password”);
Label ot=new Label(2,0,“Manual Result”);
Label td=new Label(3,0,“Automation Result”);

ws.addCell(or);
ws.addCell(dn);
ws.addCell(ot);
ws.addCell(td);

wb.write();
wb.close();
}

@AfterClass
public void afterTest() {
driver.close();
driver.quit();
driver = null;
}

@BeforeClass
public void beforeTest() throws Exception {
DesiredCapabilities dc=new DesiredCapabilities();
//dc.setCapability(“deviceName”, “Moto X”);
dc.setCapability(“deviceName”, “Galaxy Grand Prime”);
dc.setCapability(“platformVersion”, “5.1”);
dc.setCapability(“platformName”, “Android”);
dc.setCapability(“appPackage”, “com.tatx.userapp”);
dc.setCapability(“appActivity”, “com.tatx.userapp.activities.SplashScreen”);
//driver=new RemoteWebDriver(new URL(“http://127.0.0.1:4723/wd/hub”),dc);
driver = new AndroidDriver(new URL(“http://127.0.0.1:4723/wd/hub”), dc);
}
}