jeudi 24 septembre 2015

Add a custom matcher in Jasmine 1.3 - shows undefined

I'm using protractor with jasmine 1.3, tried adding a custom matcher to my spec using the example here

    beforeEach(function () {
        utils.log("beforeEach");

        this.addMatchers({
            toBeGoofy: function (expected) {

                if (expected === undefined) {
                    expected = '';
                }
                var pass = this.actual.hyuk === "gawrsh" + expected;
                if (pass) {
                    this.message = "Expected " + this.actual + " not to be quite so goofy";
                } else {
                    this.message = "Expected " + this.actual + " to be goofy, but it was not very goofy";
                }

                return pass;
            },
        });
    });

note that I didn't change anything from their example. after that, i try using it inside an "it" like that:

expect({ "hyuk": "j" }).toBeGoofy();

and i get an error:

TypeError: undefined is not a function

on the line that the matcher was used on.. any help?

NUnit test fails when not using lambda expression for assertion

If came across a weird problem while writing some NUnit tests. The tests were more complex, but I broke it down to the following code.

[Test]
public void MyTest()
{
    // Assert.That(test(), Is.True.After(1000, 100)); // Fail
    Assert.That(() => test(), Is.True.After(1000, 100)); // Success
}

static int count = 0;

bool test()
{
    Console.WriteLine(++count);
    if (count == 2)
        return true;
    return false;
}

Why does the test only succeed when I use the lambda expression?

EDIT:

To make it more clear: In the first line it seems that test() only gets executed once while () => test() gets executed multiple times.

Symfony Tests and enviroment

I have the following problem:

I have a route defined only for development or testing purposes, which I 'protect' by doing the following in my controller:

public function testAction()
{

    $env = $this->container->get('kernel')->getEnvironment();

    if ($env !== 'test' || $env !== 'dev')
    {
        throw $this->createNotFoundException('Oops, page not available in production environment...');
    }

    ...
}

Now this works well in production, but when I try to run my tests it keeps firing an 404.

When I echo the $env variable during tests it says: test

FtestFtestFtest.......... (output from phpunit)

I've tryed using != and " but no luck.

In the tests I do something alike:

$client = static::createClient();
$client->request('GET', '/basecontroller/test');
$this->assertEquals(200, $client->getResponse()->getStatusCode());

When I comment out the $env check all tests pass. What could be the cause of this ?

Thanks in advance

how to do flash file automation testing using selenium

I am trying automation of mobile app testing using Selenium. i used eclipse indigo with plugins. So far i tried using the but i get error message.

D:\Android\Android>java -jar selendroid.jar -app app.apk
Sep 24, 2015 3:50:58 PM io.selendroid.standalone.SelendroidLauncher main
INFO: ################# Selendroid #################
Sep 24, 2015 3:50:58 PM io.selendroid.standalone.SelendroidLauncher main
INFO: ################# Configuration in use #################
Sep 24, 2015 3:50:58 PM io.selendroid.standalone.SelendroidLauncher main
INFO: io.selendroid.standalone.SelendroidConfiguration@1270107[
  port=4444
  timeoutEmulatorStart=300000
  supportedApps=[app.apk]
  verbose=false
  emulatorPort=5560
  deviceScreenshot=false
  selendroidServerPort=8080
  keystore=<null>
  keystorePassword=<null>
  keystoreAlias=<null>
  emulatorOptions=<null>
  keepEmulator=false
  registrationUrl=<null>
  proxy=<null>
  serverHost=<null>
  keepAdbAlive=false
  maxSession=5
  maxInstances=5
  registerCycle=0
  noWebViewApp=false
  noClearData=false
  sessionTimeoutSeconds=1800
  forceReinstall=false
  logLevel=ERROR
  deviceLog=true
  serverStartTimeout=20000
  printHelp=false
  serverStartRetries=5
  folder=<null>
  deleteTmpFiles=true
]
Sep 24, 2015 3:50:58 PM io.selendroid.standalone.SelendroidLauncher launchServer

INFO: Starting Selendroid standalone on port 4444
Sep 24, 2015 3:50:58 PM io.selendroid.standalone.SelendroidLauncher launchServer

SEVERE: Error building server: Environment variable 'ANDROID_HOME' was not found
!
Exception in thread "main" io.selendroid.server.common.exceptions.SelendroidExce
ption: Environment variable 'ANDROID_HOME' was not found!
        at io.selendroid.standalone.android.AndroidSdk.androidHome(AndroidSdk.ja
va:98)
        at io.selendroid.standalone.android.AndroidSdk.platformToolsHome(Android
Sdk.java:87)
        at io.selendroid.standalone.android.AndroidSdk.aapt(AndroidSdk.java:39)
        at io.selendroid.standalone.android.impl.DefaultAndroidApp.deleteFileFro
mWithinApk(DefaultAndroidApp.java:107)
        at io.selendroid.standalone.builder.SelendroidServerBuilder.deleteFileFr
omAppSilently(SelendroidServerBuilder.java:133)
        at io.selendroid.standalone.builder.SelendroidServerBuilder.resignApp(Se
lendroidServerBuilder.java:142)
        at io.selendroid.standalone.server.model.SelendroidStandaloneDriver.addT
oAppsStore(SelendroidStandaloneDriver.java:121)
        at io.selendroid.standalone.server.model.SelendroidStandaloneDriver.init
ApplicationsUnderTest(SelendroidStandaloneDriver.java:155)
        at io.selendroid.standalone.server.model.SelendroidStandaloneDriver.<ini
t>(SelendroidStandaloneDriver.java:94)
        at io.selendroid.standalone.server.SelendroidStandaloneServer.initialize
SelendroidServer(SelendroidStandaloneServer.java:63)
        at io.selendroid.standalone.server.SelendroidStandaloneServer.<init>(Sel
endroidStandaloneServer.java:52)
        at io.selendroid.standalone.SelendroidLauncher.launchServer(SelendroidLa
uncher.java:65)
        at io.selendroid.standalone.SelendroidLauncher.main(SelendroidLauncher.j
ava:117)

D:\Android\Android>set ANDROID_HOME=D:\Android\Android\sdk

D:\Android\Android>java -jar selendroid.jar -app app.apk
Sep 24, 2015 3:52:18 PM io.selendroid.standalone.SelendroidLauncher main
INFO: ################# Selendroid #################
Sep 24, 2015 3:52:18 PM io.selendroid.standalone.SelendroidLauncher main
INFO: ################# Configuration in use #################
Sep 24, 2015 3:52:18 PM io.selendroid.standalone.SelendroidLauncher main
INFO: io.selendroid.standalone.SelendroidConfiguration@1270107[
  port=4444
  timeoutEmulatorStart=300000
  supportedApps=[app.apk]
  verbose=false
  emulatorPort=5560
  deviceScreenshot=false
  selendroidServerPort=8080
  keystore=<null>
  keystorePassword=<null>
  keystoreAlias=<null>
  emulatorOptions=<null>
  keepEmulator=false
  registrationUrl=<null>
  proxy=<null>
  serverHost=<null>
  keepAdbAlive=false
  maxSession=5
  maxInstances=5
  registerCycle=0
  noWebViewApp=false
  noClearData=false
  sessionTimeoutSeconds=1800
  forceReinstall=false
  logLevel=ERROR
  deviceLog=true
  serverStartTimeout=20000
  printHelp=false
  serverStartRetries=5
  folder=<null>
  deleteTmpFiles=true
]
Sep 24, 2015 3:52:18 PM io.selendroid.standalone.SelendroidLauncher launchServer

INFO: Starting Selendroid standalone on port 4444
Sep 24, 2015 3:52:18 PM io.selendroid.standalone.io.ShellCommand exec
INFO: Executing shell command: D:\Android\Android\sdk\platform-tools\aapt.exe re
move D:\Android\Android\app.apk META-INF/MANIFEST.MF
Sep 24, 2015 3:52:19 PM io.selendroid.standalone.io.ShellCommand exec
INFO: Executing shell command: D:\Android\Android\sdk\platform-tools\aapt.exe re
move D:\Android\Android\app.apk META-INF/CERT.RSA
Sep 24, 2015 3:52:19 PM io.selendroid.standalone.io.ShellCommand exec
INFO: Executing shell command: D:\Android\Android\sdk\platform-tools\aapt.exe re
move D:\Android\Android\app.apk META-INF/CERT.SF
Sep 24, 2015 3:52:19 PM io.selendroid.standalone.io.ShellCommand exec
INFO: Executing shell command: D:\Android\Android\sdk\platform-tools\aapt.exe re
move D:\Android\Android\app.apk META-INF/ANDROIDD.SF
Sep 24, 2015 3:52:19 PM io.selendroid.standalone.io.ShellCommand exec
INFO: Executing shell command: D:\Android\Android\sdk\platform-tools\aapt.exe re
move D:\Android\Android\app.apk META-INF/ANDROIDD.RSA
Sep 24, 2015 3:52:19 PM io.selendroid.standalone.io.ShellCommand exec
INFO: Executing shell command: D:\Android\Android\sdk\platform-tools\aapt.exe re
move D:\Android\Android\app.apk META-INF/NDKEYSTO.SF
Sep 24, 2015 3:52:19 PM io.selendroid.standalone.io.ShellCommand exec
INFO: Executing shell command: D:\Android\Android\sdk\platform-tools\aapt.exe re
move D:\Android\Android\app.apk META-INF/NDKEYSTO.RSA
Sep 24, 2015 3:52:19 PM io.selendroid.standalone.io.ShellCommand exec
INFO: Executing shell command: C:\Program Files\Java\jdk1.7.0_71\jre\bin\jarsign
er.exe -sigalg MD5withRSA -digestalg SHA1 -signedjar D:\Android\Android\resigned
-app.apk -storepass android -keystore C:\Users\Soma0013\.android\debug.keystore
D:\Android\Android\app.apk androiddebugkey
Sep 24, 2015 3:52:19 PM io.selendroid.standalone.SelendroidLauncher launchServer

SEVERE: Error building server: An error occurred while resigning the app 'app.ap
k'.
Exception in thread "main" io.selendroid.server.common.exceptions.SessionNotCrea
tedException: An error occurred while resigning the app 'app.apk'.
        at io.selendroid.standalone.server.model.SelendroidStandaloneDriver.addT
oAppsStore(SelendroidStandaloneDriver.java:123)
        at io.selendroid.standalone.server.model.SelendroidStandaloneDriver.init
ApplicationsUnderTest(SelendroidStandaloneDriver.java:155)
        at io.selendroid.standalone.server.model.SelendroidStandaloneDriver.<ini
t>(SelendroidStandaloneDriver.java:94)
        at io.selendroid.standalone.server.SelendroidStandaloneServer.initialize
SelendroidServer(SelendroidStandaloneServer.java:63)
        at io.selendroid.standalone.server.SelendroidStandaloneServer.<init>(Sel
endroidStandaloneServer.java:52)
        at io.selendroid.standalone.SelendroidLauncher.launchServer(SelendroidLa
uncher.java:65)
        at io.selendroid.standalone.SelendroidLauncher.main(SelendroidLauncher.j
ava:117)
Caused by: io.selendroid.standalone.exceptions.ShellCommandException: Error exec
uting shell command: C:\Program Files\Java\jdk1.7.0_71\jre\bin\jarsigner.exe -si
galg MD5withRSA -digestalg SHA1 -signedjar D:\Android\Android\resigned-app.apk -
storepass android -keystore C:\Users\Soma0013\.android\debug.keystore D:\Android
\Android\app.apk androiddebugkey
        at io.selendroid.standalone.io.ShellCommand.exec(ShellCommand.java:53)
        at io.selendroid.standalone.builder.SelendroidServerBuilder.signTestServ
er(SelendroidServerBuilder.java:296)
        at io.selendroid.standalone.builder.SelendroidServerBuilder.resignApp(Se
lendroidServerBuilder.java:154)
        at io.selendroid.standalone.server.model.SelendroidStandaloneDriver.addT
oAppsStore(SelendroidStandaloneDriver.java:121)
        ... 6 more
Caused by: io.selendroid.standalone.exceptions.ShellCommandException:
        ... 10 more

D:\Android\Android>

is there any documentation to refer the selendroid testing

In AngularJS, Is there a global way to check if any $timeout is pending?

I am using Protractor to test my code written in AngularJS

Probably there is some $timeout running in my AngularJS code which is making Protractor wait too long until it times out and gives error. But I am not able to figure out where in my code I am doing a continuous timeout/polling. Might be some library I am using but not sure.

Is there a global way to check in Angular how many timeouts are pending overall?

I am getting this error:

Uncaught exception: Timed out waiting for Protractor to synchronize with the page after 10 seconds. Please see http://ift.tt/OLBPn9

I have also tried increasing default timeout of page load from 10secs to upto 60secs which is way more than enough for my page to load. But still no success.

How do you share code between androidTest and test?

I have both unit tests in src/test and functional tests in src/androidTest. I have a few test util classes that I use to create mock models and I'd like to use in both test and androidTest. However, I don't know how to archieve this without putting these classes in /src/main or duplicating them for each test variant.

Does anyone know a good approach to share code between both?

Creating a large XML file for test data (quickly)

I have been looking into testing my program with a large Xml file to see how it performs with large datasets, however I do not want to go into the effort of generating a file with ~1000 entries. I would be here all week!

Is there a way to do it quickly to a certain structure? My program reads Xml Documents in this layout:

           @"<root> 
                <Person>
                    <Name>Joe Doe</Name>
                    <StartDate>2007-01-01</StartDate>
                    <EndDate>2009-01-01</EndDate>
                    <Location>London</Location>
                </Person>                    
                <Person>
                    <Name>John Smith</Name>
                    <StartDate>2012-06-15</StartDate>
                    <EndDate>2014-12-31</EndDate>
                    <Location>Cardiff</Location>
                </Person>
                ...

etc. I've found some online generators like Mockaroo but they are rigid in the structure they generate. I also looked into libraries such as autoFixture but I dont feel like that is what I am looking for in this case.

If anyone can provide me with some advice on how to accomplish this, I would really appreciate some help! Thanks!