4/27/2016

Google Cloud Test Lab with Robotium

Last time I setup Cloud Test Lab to execute instrumentation tests on the cloud, and Espresso was used as a default testing framework, but we can, of course, choose other options!

This time, let's use Robotium!


Setup

If you setup the NotePad app by following my previous post or  the official guide of Cloud Test Lab, then Robotium should be configured already.

Otherwise, you need to configure it by yourself in advance.
Since official tutorial doesn't cover Android Studio, you can refer these helpful web pages:


As well, if you'd like to use screenshot functions with your own app, you can find the instructions from the official guide.

Implementation

Default NotePadTest class (Espresso) is written like the following:


So, just we can make new test class with Robotium!
Robotium API reference is available from here.


Edit configuration & Run! 😄


[Android Studio 2.0]
[Robotium 5.3.0]

4/26/2016

A quick tour of Cloud Test Lab

Following a guide of Cloud Test Lab, I successfully made instrumentation tests on the cloud with Android Studio! 😄
https://developers.google.com/cloud-test-lab/

1. Create a billing account on Google Cloud Platform (free trial)

*You need to input your credit card info, but won't be charged unless you change the plan.

2. Create/edit .vmoptions file with this line:

here is how to find .vmoptions file. (You can make new one if not found)
(e.g.) Mac+AndroidStudio 2.0:  ~/Library/Preferences/AndroidStudio2.0/studio.vmoptions

3. Download and set up a sample app (or use your own app with instrumentation tests)
You can get a sample app (notepad.zip) from the guidance page.
https://developers.google.com/cloud-test-lab/android-studio#download_and_try_a_sample_app

4. Edit configuration
Select "Edit Configurations..." from app pulldown


Create new Android Tests


Configure general info by following the guidance page.
(You need to configure it properly if you use your own app)
https://developers.google.com/cloud-test-lab/android-studio#configure_a_test_matrix_and_run_a_test


You need to connect to Google Cloud Platform after you choose a target option "Cloud Test Lab Device Matrix":


Then you can choose a project on Google Cloud Platform or create a new one from "click here" link:




As well, you can choose test devices, platforms, locales and orientations from three dots button next to Matrix configuration:


5. Run your test!
You can see progress in Run window.


Output URL link leads to Test Lab page on Google Cloud Platform where you can view test results.




Since NotePadTest contains following line, you can check screenshots from the console.



Even you can see a video for each test case!

Done! 😄
As well, I wrote Cloud Test Lab + Robotium in next post!

[Android Studio 2.0]

4/22/2016

Detect iOS or WatchOS

I wanted to share a class with iPhone and Watch Extension.
But some methods and properties are not supported by both targets.

I simply used preprocessor macros:

Done!😄
As well, we can use #if os(watchOS) too since Xcode 7.2!

[Xcode Version 7.3 (7D175)]
[Swift version 2.2 (swiftlang-703.0.18.1 clang-703.0.29)]
[WatchOS version 2.2]

4/20/2016

Logging in Swift

We have new keywords such as #file, #function, #line and #column in Swift 2.2, so I modified my logging function.


I can use the function in following way:


And get this output!😄

[Swift version 2.2 (swiftlang-703.0.18.1 clang-703.0.29)]

4/18/2016

NSLocalizedString in Swift

NSLocalizedString in Swift is defined like this:


So, we can use it simply in this way:

For some reason, comment is required...😟

What if I wanna replace some words?:

OK, it works!
But is there any more simple solution?

Inspired by this post on Stack Overflow, I added a small extension to String:


Now I can write this way:

Done! 😄

[Swift version 2.2 (swiftlang-703.0.18.1 clang-703.0.29)]

4/15/2016

403 Forbidden nginx on developer.apple.com with Chrome browser

For some reason, I couldn't open developer.apple.com with Chrome 😢


I could solve the issue by following this topic:
https://productforums.google.com/forum/#!topic/chrome/dAuyi8JMlA0

Shortly, opened settings window (Ctrl+Shift+Del or Command+Shift+Del for Mac) and removed all cache and cookies, then relaunched Chrome.
*This removed all login sessions, so I needed to login all web services after that.


Done! 😄


[Chrome Version 49.0.2623.112 (64-bit)]

4/14/2016

Change Seekbar thumb image size programatically

I needed to scale Seekbar thumb size based on physical device size (DP).
The layout was designed for 360 DP phones, so thumb image looked a bit too small for tablets.
And I didn't want to make other layout.xml just for this issue.

1. Added a static method to my Util class which scales thumb image size based on the current device size:


2. Then set padding to Seekbar so it wouldn't clip the scaled thumb image:


[Android Studio 2.0]
[compileSdkVersion 23]

Change font size based on physical device width

I needed to support both phones/tablets only with one layout file (layout-normal.xml).
The layout was very simple and originally designed for 360dp width phones, so there's no problem except for a bit small font size on 10 inches tablet.
I could just write a code to scale font size up for tablets.



[Android Studio 2.0]
[compileSdkVersion 23]

4/12/2016

System Health dialog

I updated Android Studio to version 2 and got this message.


My Java version was...
java -version


So, simply updated to the latest version from http://www.oracle.com/technetwork/java/javase/downloads/index.html

Or I could export STUDIO_JDK to launch Android Studio with specific JDK outside the problematic range.
export STUDIO_JDK=/path/to/specific/jdk1.8.0_**.jdk
STUDIO_JDK is used to run Android Studio.
It is different from JDK Location (File/Project Structure.../SDK Location) which is used for app build.

[Android Studio 2.0]

4/11/2016

"no such module" error with WatchOS 2

I encountered "no such module" error after migrating to WatchOS 2.



Watch Extension is no longer included in parent app, so it can't refer to frameworks linked to its parent.

I needed to add new Watch Framework target to the original framework project.


Added necessary sources to new framework.


Then linked it to Watch Extension.


Done! 😄

*Watch framework would fail to compile if its sources contain classes not supported by WatchKit.

[Xcode Version 7.3 (7D175)]