How do I run Xamarin UITests without hard coding the Device ID and path to apk? - xamarin.uitest

According to the Xamarin UI Test documentation I need to do this:
IApp app = ConfigureApp.Android
.DeviceSerial("0756edf000620ace")
.ApkFile(PathToAPK)
.StartApp();
But it seems odd to me to have the DeviceSerial and the ApkFile hard coded like this. Additionally, when submitting to appcenter.ms those two settings aren't required. It seems to me that there must be some way to externalize this information so that you can run the same test on multiple devices without having to go in and change the code.
Sure, I could use some other external external resource but what I really want is to be able to specify these values at run time without recompiling

I think you don't need to specify "DeviceSerial". Try launch the test only with:
IApp app = ConfigureApp.Android
.ApkFile(PathToAPK)
.StartApp();

Try something like this in AppInitializer class for the UiTest project:
public static IApp StartApp(Platform platform)
{
if (platform == Platform.Android)
{
return ConfigureApp
.Android
.InstalledApp(package_name)
.StartApp();
}
else
{
return ConfigureApp
.iOS
.InstalledApp(package_name)
.StartApp();
}
}
where package_name is the name of your application package. You can get it from android manifest under the name package

Related

'BitmapStub' does not exist in the namespace 'Android.Graphics' Using Xamarin.Forms

I implemented a application for Sunmi T1 mini device in-build printer in Xamarin forms and i want to print a image with some text like billing receipt.
I integrated AIDL file for Sunmi T1 mini device you can see in image.
But i am facing namespacing issue in IWoyouService.cs "the type of namespace name 'BitmapStub' does not exist in the namespace 'Android.Graphics'."
case TransactionPrintBitmap: {
data.EnforceInterface (descriptor);
Android.Graphics.Bitmap arg0 = default (Android.Graphics.Bitmap);
arg0 = Android.Graphics.BitmapStub.AsInterface (data.ReadStrongBinder ());
ICallback arg1 = default (ICallback);
arg1 = ICallbackStub.AsInterface (data.ReadStrongBinder ());
this.PrintBitmap (arg0, arg1);
reply.WriteNoException ();
return true;
}
I attach my AIDL Zip file https://drive.google.com/file/d/1lrCgZwDrfyqs6LAwTP3pQ6nMzYIW4hrY/view?usp=sharing.
How can resolve this error in Xamarin.Forms
I had this exact same problem, and managed to solve it by adding another AIDL file to define what a 'Bitmap' is.
I copied this file from the Android Open Source Project and just added it into my project and set the build action to Android Interface Definition like the other Sunmi AIDL files.
Not sure why Xamarin doesn't manage to handle this automatically, but adding this solved the problem for me and I was able to build and successfully invoke the interface methods that accept bitmap parameters.
In case the link ever goes bad, here is the entire file you need to add - it's very small:
/* Save this in Bitmap.aidl and add to your project alongside the others */
package android.graphics;
parcelable Bitmap;

How do I add an Apps Script Library to AppMaker?

I created this script to determine if the Session.getScriptTimeZone() would draw the time zone from the library file rather than AppMaker. Here's the script:
function getFormattedDateString(dt,format){
var format=format||"E MMM dd, yyyy HH:mm";
var dt=dt||new Date();
return Utilities.formatDate(new Date(dt), Session.getScriptTimeZone(), format);
}
I tested it in another script with the following code:
function test(){
Logger.log(AMSLib.getFormattedDateString(new Date()));
}
I went into AppMaker and this dialog:
I've tried the Script ID from here:
I've also tried several deployment ID's from the publish from Manifest dialog and I keep getting the same answer:
I've also tried the Project Key which is used with other apps scripts to load libraries.
I don't know what to try next.
First things first, you need to publish your Apps Script app, after that it'll be assigned Script ID(by the way it can also be found in the published app URL). Once you have Script ID, you can specify it in App Maker and select library version you want to use:
To access library's functions you need to use name specified in the object setting:
// Server side library call
var result = MyLibraryName.doSomeCoolStuff();
App Maker should be smart enough and pickup all library's public functions for autocomplete.
Learn more:
https://developers.google.com/apps-script/guides/libraries
https://developers.google.com/appmaker/scripting/libraries
That's really odd to not have a script key there. You might make a copy of your script, something might be corrupted. You can also get the key from the URL ex: https://script.google.com/a/ignitesynergy.com/d/1oHnk_xl76KagGS4g7O2pC1MM4R3iZR8-7FlmzKXxRDtO1o5nDU2/edit
Remember to File-> Manage Versions and create a version. You also need to set the sharing to public.

spring boot/spring web app embedded version number

What are the strategies to embed a unique version number in a Spring application?
I've got an app using Spring Boot and Spring Web.
Its matured enough that I want to version it and see it displayed on screen at run time.
I believe what you are looking for is generating this version number during build time (Usually by build tools like Ant, Maven or Gradle) as part of their build task chain.
I believe a quite common approach is to either put the version number into the Manifest.mf of the produced JAR and then read it, or create a file that is part of the produced JAR that can be read by your application.
Another solution would be just using Spring Boot's banner customization options described here: http://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-spring-application.html#boot-features-banner
However, this will only allow you to change spring-boot banner.
I also believe that Spring Boot exposes product version that is set in Manifest.MF of your application. To achieve this you will need to make sure Implementation-Version attribute of the manifest is set.
Custom solution for access anywhere in the code
Lets assume you would like to have a version.properties file in your src/main/resources that contains your version information. It will contain placeholders instead of actual values so that these placeholders can be expanded during build time.
version=${prodVersion}
build=${prodBuild}
timestamp=${buildTimestamp}
Now that you have a file like this you need to fill it with actual data. I use Gradle so there I would make sure that processResources task which is automatically running for builds is expanding resources. Something like this should do the trick in the build.gradle file for Git-based code:
import org.codehaus.groovy.runtime.*
import org.eclipse.jgit.api.*
def getGitBranchCommit() {
try {
def git = Git.open(project.file(project.getRootProject().getProjectDir()));
def repo = git.getRepository();
def id = repo.resolve(repo.getFullBranch());
return id.abbreviate(7).name()
} catch (IOException ex) {
return "UNKNOWN"
}
}
processResources {
filesMatching("**/version.properties") {
expand (
"prodVersion": version,
"prodBuild": getGitBranchCommit(),
"buildTimestamp": DateGroovyMethods.format(new Date(), 'yyyy-MM-dd HH:mm')
)
}
}
processResources.outputs.upToDateWhen{ false }
In the code about the following is happening:
We defined a function that can take a build number out of the VCS
(in this case Git). The commit hash is limited to 7 characters.
We configure the processResources task to process
version.properties file and fill it with our variables.
prodVersion is taken from Gradle project version. It's usually set
as version in gradle.properties file (part of the general build
setup).
As a last step we ensure that it's always updated (Gradle
has some mechanics to detect if files ened to be processed
Considering you are on SVN, you will need to have a getSvnBranchCommit() method instead. You could for instance use SVNKit or similar for this.
The last thing that is missing now is reading of the file for use in your application.
This could be achieved by simply reading a classpath resource and parsing it into java.util.Properties. You could take it one step further and for instance create accessor methods specifically for each field, e.g getVersion(), getBuild(), etc.
Hope this helps a bit (even though may not be 100% applicable straight off)
Maven can be used to track the version number, e.g.:
<!-- pom.xml -->
<version>2.0.3</version>
Spring Boot can refer to the version, and expose it via REST using Actuator:
# application.properties
endpoints.info.enabled=true
info.app.version=#project.version#
Then use Ajax to render the version in the browser, for example using Polymer iron-ajax:
<!-- about-page.html -->
<iron-ajax auto url="/info" last-response="{{info}}"></iron-ajax>
Application version is: [[info.app.version]]
This will then show in the browser as:
Application version is: 2.0.3
I'm sure you've probably figured something out since this is an older question, but here's what I just did and it looks good. (Getting it into the banner requires you to duplicate a lot).
I'd recommend switching to git (it's a great SVN client too), and then using this in your build.gradle:
// https://github.com/n0mer/gradle-git-properties
plugins {
id "com.gorylenko.gradle-git-properties" version "1.4.17"
}
// http://docs.spring.io/spring-boot/docs/current/reference/html/deployment-install.html
springBoot {
buildInfo() // create META-INF/build-info.properties
}
bootRun.dependsOn = [assemble]
And this in your SpringBoot application:
#Resource
GitProperties props;
#Resource
BuildProperties props2;
Or this way to expose those properties into the standard spring environment:
#SpringBootApplication
#PropertySources({
#PropertySource("classpath:git.properties"),
#PropertySource("classpath:META-INF/build-info.properties")
})
public class MySpringBootApplication {
and then referencing the individual properties as needed.
#Value("${git.branch}")
String gitBranch;
#Value("${build.time}")
String buildTime;

Conditional compilation "else"

In AS3 you can pass a constant to the compiler
-define+=CONFIG::DEBUG,true
And use it for conditional compilation like so:
CONFIG::DEBUG {
trace("This only gets compiled when debug is true.");
}
I'm looking for something like #ifndef so I can negate the value of debug and use it to conditionally add release code. The only solution I've found so far was in the conditional compilation documentation at adobe and since my debug and release configurations are mutually exclusive I don't like the idea of having both DEBUG and RELEASE constants.
Also, this format works, but I'm assuming that it's running the check at runtime which is not what I want:
if (CONFIG::DEBUG) {
//debug stuff
}
else {
//release stuff
}
I also considered doing something like this but it's still not the elegant solution I was hoping for:
-define+=CONFIG::DEBUG,true -define+=CONFIG::RELEASE,!CONFIG::DEBUG
Thanks in advance :)
This works fine and will strip out code that won't run:
if (CONFIG::DEBUG) {
//debug stuff
}
else {
//release stuff
}
BUT this will be evaluated at runtime:
if (!CONFIG::DEBUG) {
//release stuff
}
else {
//debug stuff
}
mxmlc apparently can only evaluate a literal Boolean, and not any kind of expression, including a simple not.
Use the if / else construct : the dead code will be removed by the compiler and it will not be tested at runtime. You will have only one version of your code in your swf.
If you are not sure use a decompiler or a dump tool to see what really happens.
http://apparat.googlecode.com/files/dump.zip
http://www.swftools.org/
...
While Patrick's answer fulfills the question's criteria, it does not cover all use cases. If you are in an area of code that allows you to use an if/else statement then this is a good answer. But if you are in a place where you cannot then you will need a better solution. For example, you may want to do something like this to declare a constant in a class:
private var server:String = "http://localhost/mystagingenvironment";
or for a live release:
private var server:String = "http://productionserver.com";
(this is an example and I'm not advocating this as production code).
I use xml configs and use the loadConfig+="myconfig.xml" to do my configuration instead of passing large numbers of command line params. So in the <compiler> section of your xml config:
<define>
<name>CONFIG::debug</name>
<value>false</value>
</define>
<define>
<name>CONFIG::release</name>
<value>!CONFIG::debug</value>
</define>
This works well for all use cases:
CONFIG::debug
{
private var server:String = "http://localhost/mystagingenvironment";
}
CONFIG::release
{
private var server:String = "http://productionserver.com";
}
This has the additional benefit of working consistently across applications. It also does not rely on the 'optimize' flag being true, like Patrick's answer (although I think we can assume that 99.999999% of all swfs have optimize=true, I only set it to false when the optimizer breaks my AS3).
It does have the drawback that it doesn't compile all code paths, just the ones that are included. So if you're not using a build server to create release builds and tell you when things break, be prepared for surprise errors when you do your release build ("But it compiled in debug! Crap, I need this to launch now!").
Just my two cents about Chris Hill's answer (which is the solution I also use regularly): it seems that using the loadConfig+="myconfig.xml" option makes the compiler searching for the myconfig.xml file in the Flex SDK directory whereas the -load-config+=myconfig.xml option makes it searching for the myconfig.xml file in the project's directory, which is the behavior I strongly prefer as you can then easily distribute this file with your project sources...

Convert local (JQuery) link to CDN link at deploy time

I am currently developing an ASP.NET web application and do most of my development on the road, i.e. offline. I plan to use Google/Microsoft/an-other CDN for JQuery and a couple of other script resources.
My question is, is there a straightforward way to develop with a link to a local file within the solution, but to point to the CDN upon deployment/release build?
Thank you in advance!
You could write a helper function:
public static string JQuerySource()
{
var config = WebConfigurationManager.OpenWebConfiguration("~");
var compilation = config.GetSection("system.web/compilation") as CompilationSection;
if (compilation == null || compilation.Debug)
{
// Running in Debug mode
return "/scripts/jquery.js";
}
// Running in Release mode
return "http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js";
}
That you would use like this:
<script type="text/javascript" src="<%=JQuerySource() %>"></script>
You could just change the link before you deploy...?
Update:
A simple Replace All will suffice if you have a link everywhere.
I know these might be really dumb and simple solutions, but it seems to me that your problem is too simple to require an abstraction or extra code writing.
However, if you must, this is one way of doing it:
Create an XML file that holds values:
MyAppSettings.xml
<?xml version="1.0" encoding="utf-8" ?>
<MyAppSettings>
<JqueryLink
value="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"
store1="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"
store2="../jquery.min.js"
>
</JqueryLink>
</MyAppSettings>
And get the value from the XML file:
public static string GetJqueryUrl()
{
XElement file = XElement.Load(HttpContext.Current.Server.MapPath("~/App_Data/MyAppSettings.xml"));
string jquerylink = file.Element("JqueryLink").Attribute("value");
return jquerylink;
}
You could make a helper function for the previous code and use it all over your code.
Whenever you want to switch between deploy and offline links, just change the "value" parameter in the xml file.
You can keep the attributes "store1" and "store2" in there just so I wouldn't have to remember what they are when I do switch them.

Resources