Last active
September 27, 2017 13:55
-
-
Save fboldog/d7f739767399fb82707981469ec17753 to your computer and use it in GitHub Desktop.
Dead simple tabs export for Chrome on Android
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package fboldog.chrometabsaver | |
import android.content.Intent | |
import android.support.test.InstrumentationRegistry | |
import android.support.test.InstrumentationRegistry.getInstrumentation | |
import android.support.test.uiautomator.UiDevice | |
import org.junit.Test | |
import android.support.test.runner.AndroidJUnit4 | |
import android.support.test.uiautomator.UiSelector | |
import android.util.Log | |
import org.junit.Assert.assertTrue | |
import org.junit.runner.RunWith | |
@RunWith(AndroidJUnit4::class) | |
class ChromeTabsSaver { | |
@Test | |
fun listTabs() { | |
val urls = mutableListOf<String>() | |
val device = UiDevice.getInstance(getInstrumentation()); | |
device.pressHome(); | |
val context = InstrumentationRegistry.getContext() | |
val intent = context.packageManager.getLaunchIntentForPackage("com.android.chrome") | |
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK) // Clear out any previous instances | |
context.startActivity(intent) | |
device.waitForWindowUpdate("com.android.chrome", 5000) | |
val urlBar = device.findObject(UiSelector().resourceId("com.android.chrome:id/url_bar")) | |
val toolbar = device.findObject(UiSelector().resourceId("com.android.chrome:id/location_bar")) | |
assertTrue(urlBar != null) | |
assertTrue(toolbar != null) | |
var last = "" | |
while(last != urlBar.text) { | |
last = urlBar.text | |
urls.add(last) | |
toolbar.swipeRight(10) | |
} | |
Log.d(this.javaClass.simpleName, urls.joinToString("\n")) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment