How to use HasSettings class of io.appium.java_client package

Best io.appium code snippet using io.appium.java_client.HasSettings

Run io.appium automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

RecordingTest.java

Source: RecordingTest.java Github

copy
1package com.appium.advacedUsecases;
2
3
4import com.appium.base.BaseTest;
5import io.appium.java_client.HasSettings;
6import io.appium.java_client.Setting;
7import io.appium.java_client.android.AndroidDriver;
8import io.appium.java_client.imagecomparison.OccurrenceMatchingOptions;
9import io.appium.java_client.imagecomparison.OccurrenceMatchingResult;
10import io.appium.java_client.ios.IOSDriver;
11import org.apache.commons.io.FileUtils;
12import org.openqa.selenium.OutputType;
13import org.testng.annotations.Test;
14
15import java.io.File;
16import java.io.IOException;
17import java.nio.file.Paths;
18import java.util.Base64;
19
20
21public class RecordingTest extends BaseTest {
22
23    @Test
24    public void iOSScreenRecordTest() throws IOException {
25        ((IOSDriver)driver).startRecordingScreen();
26        String s = ((IOSDriver) driver).stopRecordingScreen();
27        byte[] decode = Base64.getDecoder().decode(s);
28        FileUtils.writeByteArrayToFile(new File(
29            System.getProperty("user.dir")
30                +"/sample.mp4"),
31                decode);
32    }
33
34    @Test
35    public void androidScreenRecordTest() throws IOException, InterruptedException {
36        ((AndroidDriver)driver).startRecordingScreen();
37        Thread.sleep(10000);
38        String s = ((AndroidDriver) driver).stopRecordingScreen();
39        byte[] decode = Base64.getDecoder().decode(s);
40        FileUtils.writeByteArrayToFile(new File(System.getProperty("user.dir")+"/sample.mp4"),
41                decode);
42    }
43
44    @Test
45    public void testApp() throws IOException {
46        //((HasSettings)driver).setSetting(Setting.IMAGE_MATCH_THRESHOLD, "4.0");
47        ((AndroidDriver) driver).sendSMS("555-555-5555", "Your message here!");
48        ((HasSettings)driver).setSetting(Setting.FIX_IMAGE_TEMPLATE_SIZE, "true");
49        ((HasSettings)driver).setSetting(Setting.IMAGE_ELEMENT_TAP_STRATEGY, "touchActions");
50        File file = new File("/Users/saikrisv/Desktop/login.png");
51        File refImgFile = Paths.get(file.toURI()).toFile();
52
53        File screenshotAs = driver.getScreenshotAs(OutputType.FILE);
54        OccurrenceMatchingResult result = driver
55                .findImageOccurrence(screenshotAs, new File("/Users/saikrisv/Desktop/login.png") ,
56                        new OccurrenceMatchingOptions()
57                        .withEnabledVisualization());
58        System.out.println(result.getRect());
59        //driver.findElementByImage(s).click();
60    }
61}
62
Full Screen

DriverManager.java

Source: DriverManager.java Github

copy
1package managers;
2
3import java.net.MalformedURLException;
4import java.net.URL;
5import java.util.concurrent.TimeUnit;
6
7import org.openqa.selenium.WebDriver;
8import org.openqa.selenium.remote.CapabilityType;
9import org.openqa.selenium.remote.DesiredCapabilities;
10import io.appium.java_client.AppiumDriver;
11import io.appium.java_client.HasSettings;
12import io.appium.java_client.MobileElement;
13import io.appium.java_client.Setting;
14import io.appium.java_client.remote.MobileCapabilityType;
15
16public class DriverManager {
17
18	private WebDriver driver;
19
20	public WebDriver getDriver() {
21		driver = createDriver();
22		return driver;
23	}
24
25	private WebDriver createDriver() {
26		DesiredCapabilities caps = new DesiredCapabilities();
27
28		/*
29		 * Local Emulator settings
30		 */
31		caps.setCapability("platformName", "Android");
32		caps.setCapability(MobileCapabilityType.PLATFORM_VERSION, "11");
33		caps.setCapability(MobileCapabilityType.UDID, "emulator-5554");
34		caps.setCapability(MobileCapabilityType.NEW_COMMAND_TIMEOUT, 60);
35		caps.setCapability("automationName", "UiAutomator2");
36		caps.setCapability("waitForIdleTimeout", 200);
37		//caps.setCapability("automationName", "UiAutomator2");
38		caps.setCapability("appPackage", "com.stanbicibtc.mobile");
39		caps.setCapability("appActivity", "com.stanbicibtc.mobile.MainActivity");
40		
41		URL url = null;	
42		try {
43		url = new URL("http://127.0.0.1:4723/wd/hub");
44		} catch (MalformedURLException e) {
45			e.printStackTrace();
46		}
47
48		driver = new AppiumDriver<MobileElement>(url, caps);
49		driver.manage().timeouts().implicitlyWait(50, TimeUnit.SECONDS);
50		return driver;
51	}
52
53	public void closeDriver() {
54		if(driver == null) {
55	//	driver.close();
56		//driver.quit();
57		}
58	}
59}
60
Full Screen

Accelerate Your Automation Test Cycles With LambdaTest

Leverage LambdaTest’s cloud-based platform to execute your automation tests in parallel and trim down your test execution time significantly. Your first 100 automation testing minutes are on us.

Try LambdaTest

Most used methods in HasSettings

Run Selenium Automation Tests on LambdaTest Cloud Grid

Trigger Selenium automation tests on a cloud-based Grid of 3000+ real browsers and operating systems.

Test now for Free
LambdaTestX

We use cookies to give you the best experience. Cookies help to provide a more personalized experience and relevant advertising for you, and web analytics for us. Learn More in our Cookies policy, Privacy & Terms of service

Allow Cookie
Sarah

I hope you find the best code examples for your project.

If you want to accelerate automated browser testing, try LambdaTest. Your first 100 automation testing minutes are FREE.

Sarah Elson (Product & Growth Lead)