Comments (5)
I've gotten this sort of working by creating these helper methods:
public void setConfigurationToNexus5() {
hasSetConfiguration = true;
Configuration config = getActivity().getResources().getConfiguration();
DisplayMetrics dm = getActivity().getResources().getDisplayMetrics();
dm.widthPixels = 1080;
dm.heightPixels = 1920;
dm.density = 3f;
dm.scaledDensity = 3f;
dm.densityDpi = 480;
dm.xdpi = 480;
dm.ydpi = 480;
setNoncompatSizeFields(dm);
config.orientation = Configuration.ORIENTATION_PORTRAIT;
config.densityDpi = 480;
config.screenWidthDp = 360;
config.screenHeightDp = 567;
config.smallestScreenWidthDp = 360;
config.screenLayout = 268435538;
getActivity().getResources().updateConfiguration(config, dm);
}
public void setConfigurationToNexus9() {
hasSetConfiguration = true;
Resources res = getActivity().getResources();
Configuration config = res.getConfiguration();
DisplayMetrics dm = res.getDisplayMetrics();
dm.widthPixels = 2048;
dm.heightPixels = 1440;
dm.density = 2f;
dm.scaledDensity = 2f;
dm.densityDpi = 320;
dm.xdpi = 320;
dm.ydpi = 320;
setNoncompatSizeFields(dm);
config.orientation = Configuration.ORIENTATION_PORTRAIT;
config.densityDpi = 320;
config.screenWidthDp = 1024;
config.screenHeightDp = 695;
config.smallestScreenWidthDp = 768;
config.screenLayout = 268435540;
res.updateConfiguration(config, dm);
}
public void setConfigurationToNexus9Landscape() {
setConfigurationToNexus9();
Resources res = getActivity().getResources();
Configuration config = res.getConfiguration();
config.orientation = Configuration.ORIENTATION_LANDSCAPE;
res.updateConfiguration(config, res.getDisplayMetrics());
}
However, it seems like some things like bitmaps and drawables are cached by the asset manager so there are slight differences when running on different devices and what these test renders vs their respective devices.
from screenshot-tests-for-android.
I've gotten testing with multiple devices to work with some gradle hacks. I modified recordDir
to have a suffix specific to the current device attached in adb (device codename + API version), that way recorded screenshots from different devices won't conflict with each other. It's pretty hacky and basic, but is decent enough for my use.
project.afterEvaluate {
def pullScreenshots = project.tasks.getByName("pullScreenshots")
pullScreenshots.dependsOn updateScreenshotDirs
}
task updateScreenshotDirs << {
def codeNameOut = new ByteArrayOutputStream()
exec {
commandLine 'adb', 'shell', 'getprop', 'ro.product.name'
standardOutput codeNameOut
}
def sdkOut = new ByteArrayOutputStream()
exec {
commandLine 'adb', 'shell', 'getprop', 'ro.build.version.sdk'
standardOutput sdkOut
}
def deviceName = codeNameOut.toString().trim()
def deviceSdk = sdkOut.toString().trim()
def outputDir = project.screenshots.recordDir + "/" + deviceName + "_api" + deviceSdk
project.screenshots.recordDir = outputDir
System.out.println("New screenshot output dierctory: " + outputDir)
}
from screenshot-tests-for-android.
We're trying to figure out the best way to do this internally too. In a record-verify style environment, multiple devices can have a lot of extra load on developers to keep the screenshots in sync. (Not so much of an issue with automatic recording on the server which we do internally at Facebook but haven't realeased the tooling for yet.)
In the meantime, it's possible to simulate some parts of a tablet configuration in a non-tablet run using this method: http://developer.android.com/reference/android/content/res/Resources.html#updateConfiguration(android.content.res.Configuration,%20android.util.DisplayMetrics)
We don't really use this for this purpose, although we do use this for switching Locales within a single test run, so I do know this is pretty powerful. Just make sure to clean up any configuration in your tearDown because it sets things globally as opposed to just the current Context.
Let me know if this helps, and I'll update this task once I have a better story for multiple devices.
from screenshot-tests-for-android.
Do you know where/what these caches are in AssetManager? I'm sure it should be technically possible to invalidate those caches with the hammer of reflection
from screenshot-tests-for-android.
Merging into a more up-to-date issue #112
from screenshot-tests-for-android.
Related Issues (20)
- verifyDebugAndroidTestScreenshotTest:RuntimeError HOT 1
- java.lang.OutOfMemoryError: Failed to allocate a 8781536 byte allocation with 4981712 free bytes and 4MB until OOM, max allowed footprint 536870912, growth limit 536870912 at java.util.Arrays.copyOf(Arrays.java:3260) HOT 2
- Library forces arbitrarily small image width HOT 1
- Found 0 Screenshots
- Recording a single test deletes all other screenshots
- Fail to execute runDebugAndroidTestScreenshotTest due to syntax error HOT 1
- Add support to Kotlin DSL
- RunScreenshotTestTask doesn't support configuration cache
- Performance?
- Value error: Operation on closed image when recording/verifying screenshots HOT 2
- Can't record very large view inside ScrollView HOT 4
- Screenshot record fails because of --> "Accessibility content change on non-UI thread"
- Is it possible to hideout dynamic content on the screen before capturing screenshot HOT 1
- Is it possible to vertical scroll and capture full screen
- Incorrect accessibility actions checks in `AccessibilityUtil`
- How to run plugin tests (plugin:check)
- How to install all the artifacts to local maven repository
- plugin id 'com.facebook.testing.screenshot:plugin' version '0.14.0' apply false Fail for android DSL files
- Add SurfaceView support
- test failure: Is your sdcard directory read-only?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from screenshot-tests-for-android.