Skip to content

Instantly share code, notes, and snippets.

View sbabcoc's full-sized avatar
💭
All I Really Need to Know I Learned in Kindergarten

Scott Babcock sbabcoc

💭
All I Really Need to Know I Learned in Kindergarten
View GitHub Profile

Introduction

The scriptExecRuntime wrapper is a self-contained JavaScript execution runtime designed to sit inside a browser (or WebView) and provide structured, Selenium/Appium-friendly execution semantics. Its features line up closely with the needs of executeScript / executeAsyncScript when Java is on the other side.

Below is a structured description of what it provides and why each piece exists.


1. Idempotent, safe runtime injection

Good question — and this is a common need when testing Android apps directly through Appium + UiAutomator2.

Here’s how you launch your app at a specific activity instead of the default one.


🔹 Option 1: Use Desired Capabilities (simplest)

When you start your session, specify both appPackage and appActivity:

package com.nordstrom.automation.selenium.support;
import java.io.BufferedInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.net.URL;
import java.util.HashSet;

Yes, you can replicate this kind of Intent verification in an integration test, where you validate that your application actually sends an intent to the system as part of its behavior when interacting with the UI. For integration testing with intents, Espresso-Intents is often the go-to library in Android. Here’s how you can use Espresso-Intents for integration testing of intent actions.

Integration Testing Intents with Espresso-Intents

Espresso-Intents lets you intercept and verify outgoing intents without actually launching the external application (like the browser). This approach is more robust in integration tests because it ensures your app is interacting correctly with the Android system.

Steps to Set Up and Use Espresso-Intents

  1. Add Espresso-Intents Dependency Ensure you have Espresso-Intents in your build.gradle file for your androidTest scope:

Certainly! When you use Mockito for testing intent actions, you're primarily concerned with verifying that your application correctly creates and sends the Intent for specific actions (like opening a URL in a browser). Here’s a breakdown of how to set up and use Mockito to test Intent actions in Android:

Step-by-Step Guide to Mocking Intents with Mockito

  1. Add Mockito Dependencies Ensure you have the necessary dependencies for Mockito in your build.gradle file:

    testImplementation 'org.mockito:mockito-core:4.x.x'
    testImplementation 'org.mockito:mockito-inline:4.x.x' // For mocking final classes/methods
private static final String UPDATE_VALUE =
"arguments[0].value=arguments[1]; arguments[0].dispatchEvent(new Event('input',{bubbles:true}));";
private static final String ELEMENT_MESSAGE = "[element] must be non-null";
/**
* Update the specified element with the indicated value
*
* @param element target element (checkbox)
* @param value desired value
* @return 'true' if element value changed; otherwise 'false'
@sbabcoc
sbabcoc / gist:a352393751df63a340840f89244cb5a5
Last active September 6, 2024 19:31
How to add arbitrary headers to HTTP requests

In Selenium 4, you can add arbitrary headers to HTTP requests using the DevTools protocol, which is now integrated into Selenium. Here's how you can do it with Chrome or Edge:

Example in Java (Selenium 4):

  1. Set up the ChromeDriver or EdgeDriver:
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.devtools.DevTools;
@sbabcoc
sbabcoc / XCUITest page components.md
Last active February 1, 2024 01:08
XCUITest page components
layout post
title XCUITest Automation: Page Components for iOS Test Automation
category mobile
author Scott Babcock
tags
xcuitest
mobile
swift
summary-image /articles/xcuitest/XCUITest.jpg

Creating Stable, Maintainable User Interface Test Automation in Swift

@sbabcoc
sbabcoc / XCUITest page object models.md
Last active January 31, 2024 20:48
XCUITest page object models
layout post
title XCUITest Automation: Page Object Models for iOS Test Automation
category mobile
author Scott Babcock
tags
xcuitest
mobile
swift
summary-image /articles/xcuitest/XCUITest.jpg

Creating Stable, Maintainable User Interface Test Automation in Swift

@sbabcoc
sbabcoc / XCUITest element locator enums.md
Last active February 24, 2024 18:50
XCUITest element locator enums
layout post
title XCUITest Automation: Encapsulating Element Locators in Swift Enumerations
category mobile
author Scott Babcock
tags
xcuitest
mobile
swift
summary-image /articles/xcuitest/XCUITest.jpg

Creating Stable, Maintainable User Interface Test Automation in Swift