If-else in testcomplete - testing

I have application "Application" , which have same autorization service as skype, QQ etc (You must log using yours login/password)
I need to test some functionality in settings of this application, so I`m using testcomplete :
I need tu run application
Go to settings
Change something
Save
And its quite simple. But if you are logged of, I need to reproduce such scenario:
run application
1.1. if logged of - log using (testlogin/testpassword)
Go to settings
Change something
Save
How I can reproduce such functionality in TestComplete?
I`m newbie with it so I need help :)
Thanks

Make your test check whether the login window is displayed. You can do this using one of the Wait* methods. If the login window is displayed then call a test routine/keyword test that will perform a login and then continue the general test flow.
...
var loginWindow = Sys.Process("Application").WaitWinFormsObject("loginDialog", 3000);
if (loginWindow.Exists) {
doLogin();
}
...
function doLogin()
{
// perform login
}

While your answer is totally right, I'd like to know if this is possible:
If the loginWindow does not exist, TC gives an error, is it possible to ignore this error and keep it out of the log besides locking the log or disabling it?
Like in Java or C#:
if(object.Exists)
do something;
else
do other thing;
this throws an error in TC and I don't want it to because I'm already checking for the existence of the object...

You cannot use a method on a object that is not there.
Workaround would be to first check for an object and then to use the Exists method like so..
if (object && object.Exists) {
// doSomething
} else {
// doSomethingElse
}

Related

[JETPACK COMPOSE]: is there a way to restart whole app programmatically?

I need a way to make my app close and opens again. Or just restart everything inside of it.
Since the issue with my app can be fixed by closing app and opening again (When creating user the loading function to firebase the collection inside user document does not load for some reason)
Below code can do it:
val context = LocalContext.current
val packageManager: PackageManager = context.packageManager
val intent: Intent = packageManager.getLaunchIntentForPackage(context.packageName)!!
val componentName: ComponentName = intent.component!!
val restartIntent: Intent = Intent.makeRestartActivityTask(componentName)
context.startActivity(restartIntent)
Runtime.getRuntime().exit(0)
So... you could write ways to "restart everything", but I am going to strongly suggest not doing that. When building an app, you will run into edge cases. You will hit some failure states that you can't recover from. That happens. But, solving these cases by just "restarting" doesn't actually address the issue and will probably result in wonky and undesirable UX.
I would instead suggest you post here some steps to reproduce and debugging results.
Under what circumstance/flow does this document stop loading?
When it does happen, can you capture the call to Firebase where it is trying to load the document?
If so, what does that call look like?
Is it looking for the document in the correct place?
Can you show an example of the call when it fails and also what the database hierarchy looks like?
Can you show us a snippet of code where this is failing?
Without more information, this sounds more like a race condition - you might be trying to find the document before it is actually created and not handling the error path for when the document is not found. However, we would need to do some debugging to verify.

Changing language in UWP doesn't change system features language - only on app restart

I have a UWP application.
And i have a need to change locale on the fly, so i have this for language changing:
Windows.Globalization.ApplicationLanguages.PrimaryLanguageOverride = language.FourDigitCode;
ResourceContext.GetForViewIndependentUse().Reset();
ResourceContext.GetForCurrentView();
But there is a problem that system features language doesn't switch ( only after application relaunch ) how can i fix it?
Here is an example:
Now i run this code:
Windows.Globalization.ApplicationLanguages.PrimaryLanguageOverride = "lv-LV";
ResourceContext.GetForViewIndependentUse().Reset();
ResourceContext.GetForCurrentView();
The UI gets localized, but system features still remain unlocalized:
But when i restart the app, all is OK:
Any ideas how can i fix it?
I'm afraid there is no fix for this and what you've seen is by design. Ref Remarks of PrimaryLanguageOverride property:
When you set the PrimaryLanguageOverride, this is immediately reflected in the Languages property. However, this change may not take effect immediately on resources loaded in the app UI. To make sure the app responds to such changes, you can listen to the QualifierValues property on a default resource context and take whatever actions may be needed to reload resources. Those requirements may vary depending on the UI framework used by the app, and it may be necessary to restart the app.
For your scenario, a restart is needed. I'd suggest that you can add a tip to tell users to restart the app and also a button to close the app like what used in News App.
And to close the app, we can call Application.Exit method like the following.
Application.Current.Exit();
Maybe page reloading can fix it? Try to re-navigate to the same page.
Found the example below here.
//like this
private bool Reload(object param = null)
{
var type = Frame.CurrentSourcePageType;
Frame.Navigate(type, param);
Frame.BackStack.Remove(Frame.BackStack.Last());
}
// or like this
private bool Reload(object param = null)
{
var frame = Window.Current.Content as Frame;
frame.Navigate(frame.CurrentSourcePageType, param);
frame.BackStack.Remove(frame .BackStack.Last());
}

Using an URL scheme in XCTestCase

I want to run a test which awaits the response of a browser.
A test target has an Info.plist where I can register custom URL schemes. But those are never called. I know that an test target is not a real application.
Is there a way?
EDIT (for bounty): I want to write an integration test for a class that calls openUrl("tel://" + some phone number). How do I subscribe to this URL scheme in an XCTestCase?
The question was retagged to OS X so my answer is no longer valid
Original answer
This is impossible. The basic reason is that the tests are connected to one running application instance, they have no control over the device, they are running as part of the application. You can probably open the URL but you won't be able to return to the application and do an assert.
Also note that XCUnit is a unit testing framework. You won't be able to write advanced integration test in it. You might be more successful with UI Automation but this specific test case will be very complicated even for it. For example, to open a link by your app in the simulator, you can create a HTML page that will redirect to the link and then use shell to exec open testLink.html -a "iOS Simulator". However, in my humble opinion this kind of tests is unreliable and realy hard to write and debug.
My advice would be to:
Write an unit test that mocks [UIApplication openURL:] and verify that you are passing a correct URL to it. Or if you want the other direction, write a unit test that will call UIApplicationDelegate methods in the called order, simulating opening a link by your app. This is as far you can go with XCUnit.
Test the rest manually.
I am uncertain what exactly that you are trying to test. I assume that it is something more than whether the URL can be opened or not. The test case below checks whether FaceTime will open and can open a URL. If the app you are testing registers a custom scheme, then simply changing pathToTestApplication should work.
class NSURL_SchemeTests: XCTestCase {
func testWhoHandlesSchemeTel() {
let testAppURL = NSURL(string: pathToTestApplication)
// create a NSURL for the test
let tel = "tel:5555555555"
let url = NSURL(string: tel)
XCTAssert(url != nil, "Could not create a URL from \(tel)")
// determine whether any application is registered to handle the URL
let workspace = NSWorkspace.sharedWorkspace()
let urlHandler = workspace.URLForApplicationToOpenURL(url!)
XCTAssert(urlHandler != nil, "No application found to open URL \(tel)")
// determine whether the expected test application is registered to handle the URL
XCTAssert(urlHandler! == testAppURL,
"Application \(pathToTestApplication) was not registered to handle URL \(tel)")
// attempt to open the URL
XCTAssert(workspace.openURL(url!), "Could not open URL \(tel)")
}
}

User Specific App Settings

I have started working with server side app settings and it would appear the default mechanics for a shared app is to save the app settings across the entire project scope; so if an individual makes changes to the app settings, those changes are reflected for all future users. This is not the ideal use in my specific case. I would like it if I could have different settings for each user, without them each adding separate instances of my custom HTML. Is this possible using server side settings, or will I need to look into using cookies to save the settings on each user?
Note: I've read the documentation on app setting scope (https://help.rallydev.com/apps/2.0rc1/doc/#!/guide/settings-section-define-scope) but it doesn't appear as though "user" is an option.
Thanks!
Conner, you're making a good argument for User-level settings for an app.
Unfortunately, we don't support that currently. The settingsScope option in AppSettings only supports the values app, project, or workspace.
Creating an instance of the app for each user (such as on their individual dashboard) is the best alternative I can think of. But as you mentioned, this is not ideal for you.
I have solved this issue by prepending the user ObjectID to each setting value before I save or load it from the Rally servers. Here is the code for my user settings set/get functions:
setUserSetting : function(settingName, settingValue, callback) {
var settings = {};
settings[App.getContext().getUser().ObjectID + settingName] = settingValue;
App.updateSettingsValues({
settings : settings,
success : function() {
App.setSettings(Ext.Object.merge(App.getSettings(), settings));
callback();
}
});
},
getUserSetting : function(settingName) {
return App.getSetting(App.getContext().getUser().ObjectID + settingName);
}
BTW, it seems kind of strange that I have to save the settings in the way I have. The "updateSettingsValues" function sets the settings on the next load of the app and the "setSettings" function sets it for the current runtime of the app. It's a strange way to have to do it, but it works.

Fiddler Reissue and Edit and Reissue from composer

I'm using Fiddler on daily life. However, the most used feature for me, such as Reissue and Edit and Reissue from composer don't have any shortcuts. I don't know how to use fiddler script for this. Can anybody point a solution for this?
Hit CTRL+R to open the FiddlerScript editor.
Inside the OnBoot() function add the following code:
FiddlerApplication.UI.lvSessions.add_KeyDown(HandleAKey);
Immediately after the closing brace for the OnBoot function, add the following code:
static function HandleAKey(Sender, theKey:KeyEventArgs) {
if (theKey.KeyData == Keys.E)
{
var oS: Session = FiddlerApplication.UI.GetFirstSelectedSession();
if (null == oS) return;
theKey.Handled = theKey.SuppressKeyPress = true;
FiddlerApplication.DoComposeByCloning(oS);
}
}
Save the file. Restart Fiddler. Now, when you press the E key on any selected session in the Web Sessions list, that session will be cloned to the composer to resend.
Currently, the FiddlerApplication.UI.actReissueSelected() function is not public, which means that there's no simple way to invoke that functionality without calling FiddlerApplication.oProxy.SendRequest() directly.