Login Page Automation

Hi i am doing an automation of a login page…But the problem is when my application is opened there is a normal home page with just some text views and i have to slide it to the left to get to login page with a username and password and a login button. My question is how to automatically slide left to the login page and pass username and password and click login button automatically…I know its a bit lengthy but i have read many tutorials but havent found anything…Thanks in advance

Have you tried swipe method?
More info here

ok i check that out …
here is the code provided in that :

since i want to swipe right :
Swipe right-

appiumDriver.context(“NATIVE_APP”);
Dimension size = appiumDriver.manage().window().getSize();
int endx = (int) (size.width * 0.8);
int startx = (int) (size.width * 0.20);
int starty = size.height / 2;
appiumDriver.swipe(startx, starty, endx, starty, 1000);

Do i have to change anything or simply use the code as it is??

It should work, try it and let know…

i tried, it aint working :

package amazon;
import io.appium.java_client.android.AndroidDriver;
import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.HashMap;
import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;
import org.openqa.selenium.Dimension;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.Test;

public class StartApplication {

private static AndroidDriver driver;
public static void main(String[] args) throws MalformedURLException, InterruptedException {
	
	File classpathRoot = new File(System.getProperty("user.dir"));
	File appDir = new File(classpathRoot, "/apk");
	File app = new File(appDir, "sample.apk");

	DesiredCapabilities capabilities = new DesiredCapabilities();
	capabilities.setCapability(CapabilityType.BROWSER_NAME, "");
	capabilities.setCapability("deviceName", "Appium_AVD");
	capabilities.setCapability("platformVersion", "4.4.2");
	capabilities.setCapability("platformName", "Android");
	capabilities.setCapability("app", app.getAbsolutePath());
	capabilities.setCapability("appPackage", "com.sample.en");
	capabilities.setCapability("appActivity", "com.sample.en.activities.HomeActivity");
	driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
	driver.manage().timeouts().implicitlyWait(80, TimeUnit.SECONDS);
	Thread.sleep(9990000); 
}
	
	@Test
	
	public void testApp() throws Exception{
		
		driver.context("NATIVE_APP"); 
		Dimension size = driver.manage().window().getSize(); 
		int startx = (int) (size.width * 0.8); 
		int endx = (int) (size.width * 0.20); 
		int starty = size.height / 2; 
		driver.swipe(startx, starty, endx, starty, 1000);
	}
		
		
	
	
		
	@AfterMethod
    public void tearDown() {
           driver.quit();
    }

}

and m sorry i meant that i need to slide left not right

i like it :slight_smile: wait for 3h

1 Like

hahaha yeah man the screen keeps going off and i wanted to keep the activity running for a LITTLE more time thats why…So can u help me with the swiping issue

It seems you have wrong structure.
I see main method but also I see @Test annotations.

How do you run this script?
In you code you should call method testApp() after driver initialisation…

so did you remove this 3h first?

if you like you may put it after “driver.swipe(startx, starty, endx, starty, 1000);”

i removed the 3h…
i went thru a link about swiping in appium here

I will show u my code :

package amazon;
import io.appium.java_client.android.AndroidDriver;
import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.HashMap;
import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;
import org.openqa.selenium.Dimension;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.Test;

public class StartApplication {

 static AndroidDriver driver;
Dimension size;
public static void main(String[] args) throws MalformedURLException, InterruptedException {
	
	File classpathRoot = new File(System.getProperty("user.dir"));
	File appDir = new File(classpathRoot, "/apk");
	File app = new File(appDir, "sample.apk");

	DesiredCapabilities capabilities = new DesiredCapabilities(); 
	capabilities.setCapability("deviceName", "Samsung-T231"); 
	capabilities.setCapability("browserName", "Android"); 
	capabilities.setCapability("platformVersion", "4.4.2"); 
	capabilities.setCapability("platformName", "Android"); 
	capabilities.setCapability("appPackage", "com.vishnu.sample"); 
	capabilities.setCapability("appActivity","com.vishnu.sample.activities.HomeActivity"); 
	driver = new AndroidDriver(new URL("http://127.0.0.1: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 public void swipingHorizontal() throws InterruptedException {
	//Get the size of screen. 
	size = driver.manage().window().getSize();
	System.out.println(size); 
	//Find swipe start and end point from screen's with and height. 
	//Find startx point which is at right side of screen.
	int startx = (int) (size.width * 0.70);
	//Find endx point which is at left side of screen.
	int endx = (int) (size.width * 0.30);
	//Find vertical point where you wants to swipe.
	//It is in middle of screen height. 
	int starty = size.height / 2;
	System.out.println("startx = " + startx + " ,endx = " + endx + " , starty = " + starty);
	//Swipe from Right to Left. 
	driver.swipe(startx, starty, endx, starty, 3000); 
	Thread.sleep(2000);
	//Swipe from Left to Right. 
	driver.swipe(endx, starty, startx, starty, 3000);
	Thread.sleep(2000); 
	} 

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

Still not working…
Wat am i doing wrong
i copied the code from the link which i mentioned

It does not work because method ‘swipingHorizontal’ was not called.

How do you run your script?

You are trying combine simple run with Junit…