Mobile Web Automation

@wreed @Priyank_Shah

Can we test with firefox,opera and ucbrowser using appium?

I have a requirement to execute mobile web application using above mentioned browsers in mobile.

Have anyone idea about this?

I have not done this. I do believe it’s possible to use another browser, but I don’t know which ones.

Thanks @wreed I have one more doubt. What is the exact desired capability for native mobile browser in Android if am using Samsung Galaxy S4?

Great question. I am almost exclusively working on iOS, so I’m not really sure.

browserName

Note that I haven’t tried mobile browser automation yet, but this is a good place to start checking.

Samsung come with Chrome pre-installed so we don’t have to automate the Browser app there.

Here your code:

public void setUp() throws MalformedURLException
{
DesiredCapabilities cap = new DesiredCapabilities();
cap.setCapability(“deviceName”, “”);
cap.setCapability(“platformName”, “Android”);
cap.setCapability(“browserName”, “Chrome”);
cap.setCapability(“newCommandTimeout”, “500”);
driver = new AppiumDriver(new URL(“http://”+ip+":"+port+"/wd/hub"),cap) {

		@Override
		public WebElement scrollTo(String arg0) {
			// TODO Auto-generated method stub
			return null;
		}

		@Override
		public WebElement scrollToExact(String arg0) {
			// TODO Auto-generated method stub
			return null;
		}
	};
	driver.manage().timeouts().pageLoadTimeout(60, TimeUnit.SECONDS);
	driver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);
	driver.get("https://m.facebook.com/");
}

@Chirag_Singh, Code is not proper. Driver objects are not properly used.

@Priyank_Shah As I am beginner, could you please share proper code so that we can learn.

``
AppiumDriver driver;
public void setUp() throws MalformedURLException
{
DesiredCapabilities cap = new DesiredCapabilities();
cap.setCapability(“deviceName”, “”);
cap.setCapability(“platformName”, “Android”);
cap.setCapability(“browserName”, “Chrome”);
cap.setCapability(“newCommandTimeout”, “500”);
driver = new AndroidDriver(new URL(“http://”+ip+":"+port+"/wd/hub"),cap);
driver.get();
`

@Priyank_Shah
Thanks for sharing the code.

I need your suggestion,
As you use AndroidDriver for Android same way we use iOSDriver for iOS. How can we manage these driver in framework?

One thing more if we use AppiumDriver as I used above then we could use same driver in both android and iOS. But I also observed that AppiumDriver does not have much inbuilt method compare with AndroidDriver.

So what would be the best practice to initialize driver.

Thanks!!

You can use AppiumDriver for both Android and IOS since it is generic class. if u want to use Android specific methods then u need to cast ur driver object with AndroidDriver.
You can identify Driver instance using instanceOf Operator of java.

@Priyank_Shah

I have created an Appium Driver with the below code:

AppiumDriver driver = new AppiumDriver(new URL(“http://127.0.0.1:4723/wd/hub”),cap) {

		@Override
		public WebElement scrollTo(String arg0) {
			// TODO Auto-generated method stub
			return null;
		}

		@Override
		public WebElement scrollToExact(String arg0) {
			// TODO Auto-generated method stub
			return null;
		}
	}; 

Now trying to cast AppiumDriver with AndroidDriver using below Code:

private AndroidDriver getAndroidDriver()
{
AndroidDriver d = (AndroidDriver) (driver);
return d;
}

But when I use getAndroidDriver().pressKeyCode(4); or another methods the below exceptions occurs:
java.lang.ClassCastException: xyz cannot be cast to io.appium.java_client.android.AndroidDriver

Note: Same exception is also appeared when I keep within try and catch block.

As per my understanding we could not type cast AppiumDriver to AndroidDriver.

So what is the best practice in industry to initialize driver?

Should I go to AppiumDriver or AndroidDriver/iOS driver while designing the framework.

Please suggest!!

Thanks,

@Chirag_Singh, It is wrong way to do what you are doing. You should not create instance of AppiumDriver because this is abstract class.
I feel sorry to say, but brush your java skills (Encapsulation/Inheritance etc) because learning appium is easy if you acquire good skills in programming (Any of languages). All your queries have nothing to do with Appium at all. It just basic java programming.

Below is the code for proper usage:
AppiumDriver driver = **new IOSDriver(<>) or AndroidDriver(<>)**; driver.findElement(MobileBy.AndroidUIAutomator(<>)).click(); ((AndroidDriver)driver).pressKeyCode(); # if you want to use Android Specific mehtods

@Priyank_Shah
Thanks for sharing your knowledge. These information are really helpful to me.