Skip to content

Instantly share code, notes, and snippets.

DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(MobileCapabilityType.DEVICE_NAME, "Android Emulator");
capabilities.setCapability(IOSMobileCapabilityType.LAUNCH_TIMEOUT, 900000);
// Session is created using Android Espresso Driver
capabilities.setCapability(MobileCapabilityType.AUTOMATION_NAME, AutomationName.ESPRESSO);
capabilities.setCapability(MobileCapabilityType.APP, System.getProperty("user.dir") + "/apps/ApiDemos.apk");
driver = new AndroidDriver<>(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
driver.findElementByAccessibilityId("Views").click();
// Switch to Android UIAutomator2 from Espresso
@dannyshain
dannyshain / SwipeGesture.java
Last active March 12, 2021 01:35
SwipeGesture
Point source = slider.getLocation();
PointerInput finger = new PointerInput(PointerInput.Kind.TOUCH, "finger");
Sequence sequence = new Sequence(finger, 1);
sequence.addAction(finger.createPointerMove(ofMillis(0),
PointerInput.Origin.viewport(), source.x, source.y));
sequence.addAction(finger.createPointerDown(PointerInput.MouseButton.MIDDLE.asArg()));
sequence.addAction(new Pause(finger, ofMillis(600)));
sequence.addAction(finger.createPointerMove(ofMillis(600),
PointerInput.Origin.viewport(), source.x + 400, source.y));
sequence.addAction(finger.createPointerUp(PointerInput.MouseButton.MIDDLE.asArg()));
@dannyshain
dannyshain / VisualTesting.java
Last active March 12, 2021 01:36
Visual UI Testing
// Start visual UI testing
eyes.open(driver, "iOS test application", "test");
// Visual validation point #1
eyes.checkWindow("Initial view");
driver.findElementByAccessibilityId("Views").click()
// Visual validation point #2
eyes.checkWindow("After compute");
// Android DataMatchers
driver.findElementByAndroidDataMatcher(orderJSON.toString().click()
// iOS NSPredicates
driver.findElement(MobileBy.iOSNsPredicateString("name IN {'chained VieW','Demos wheel picker color'} AND visible == 1")).click();
// iOS Class Chain
driver.findElement(MobileBy.iOSClassChain("'XCUIElementTypeWindow'/**/XCUIElementTypeStaticText[2]"));
@Test
public void mainActivityTest2() {
onView(withId(R.id.digit_1)).perform(click());
onView(withId(R.id.op_add)).perform(click());
onView(withId(R.id.digit_2)).perform(click());
onView(withId(R.id.eq)).perform(click());
onView(allOf(Matchers.instanceOf(android.widget.EditText.class),
withText("3"))).check(matches(isDisplayed()));
}
// XCTNSPredicateExpectation
let expectation = XCTNSPredicateExpectation(predicate: NSPredicate(format: "name IN {'chained VieW','Demos wheel picker color'} AND visible == 1 "), object: xCUIElement)
// Interacting with pickers
let first = NSPredicate(format: "label BEGINSWITH 'Picker'")
let picker = app.pickerWheels.element(matching: first)
picker.adjust(toPickerWheelValue: "value")
context('Home', () => {
beforeEach(() => cy.visit('https://demo.applitools.com'));
it('should log in to the application and land on the dashboard', () => {
cy.get('#log-in').click();
cy.get('.element-header').eq(0).contains('Financial Overview');
cy.get('.element-header').eq(1).contains('Recent Transactions');
});
context('Home', () => {
beforeEach(() => cy.visit('https://demo.applitools.com'));
it('should log in to the application and land on the dashboard', () => {
cy.eyesOpen({
appName: 'Demo App',
testName: 'Login',
});
cy.eyesCheckWindow({ tag: 'Login Window' });
@Test
public void getCompanyData_checkCeo_shouldBeElonMusk() {
GraphQLQuery query = new GraphQLQuery();
query.setQuery("{ company { name ceo coo } }");
given().
contentType(ContentType.JSON).
body(query).
when().