why we use return true or false in appDelegate? - swift4.1

In this method what is the means of true and false?
application: didFinishLaunchingWithOptions: -> Bool{
return true
}
if I write return true application Launch and works fine either I write return false application work's fine.
so what is the mean of return true and false?.

As of official documentation.
Return Value
false if the app cannot handle the URL resource or continue a user
activity, otherwise return true. The return value is ignored if the
app is launched as a result of a remote notification.
The return result from this method is combined with the return result
from the application(_:willFinishLaunchingWithOptions:) method to
determine if a URL should be handled. If either method returns false,
the URL is not handled. If you do not implement one of the methods,
only the return value of the implemented method is considered.
For more details see https://developer.apple.com/documentation/uikit/uiapplicationdelegate/1622921-application

If you return false in didFinishLaunchingWithOptions then operating system will know that you cannot open the url coming in the launchOptions dictionary.
There is no other use of returning value in didFinishLaunchingWithOptions.

Related

Getting children of an element in Puppeteer: element.children.length works but element.children returns undefined

I have this code snippet:
const historicalDataTable = await findElementByClass(
"table",
elementClass,
page
); // This is a custom function I wrote. Works as expected.
const tableBody = await historicalDataTable.$eval(
"tbody",
(el) => el.children.length
);
console.log(tableBody);
This works as expected and returns the correct amount of children. However when I do
const tableBody = await historicalDataTable.$eval(
"tbody",
(el) => el.children
);
And remove the length, it returns undefined. What is going on here?
el.children (Element#children) will yield an HTMLCollection which is not serializable and can't be marshalled from the page's execution context into yours, so evaluate returns undefined instead.
Now, this isn't fully obvious when looking at the elementHandle.$eval docs as the only indication is that the return value is <Promise<Serializable>>, but it becomes clear from the executionContext.evaluate docs:
returns: <Promise<Serializable>> Promise which resolves to the return value of pageFunction
[...]
If the function passed to the executionContext.evaluate returns a non-Serializable value, then executionContext.evaluate resolves to undefined. DevTools Protocol also supports transferring some additional values that are not serializable by JSON: -0, NaN, Infinity, -Infinity, and bigint literals.
(Emphasis mine.)
el.children.length (HTMLCollection#length) on the other hand is a simple number which is serializable.
You have to do whatever you want to do with those elements inside of your pageFunction and return only some serializable value.
Alternatively, you could also use elementHandle.evaluateHandle to return a JSHandle to the HTMLCollection and use that handle later in another call to an evaluate-type function. (Note that that would be the only thing you can do with it though. You couldn't access .length for example from your own execution context, only from another pageFunction1.)
1: This is not entirely true, since you could for example use jsHandle.getProperty to get another JSHandle for the length, followed by jsHandle.jsonValue to get the value as number - but both of these operations are asynchronous and probably it's a lot more efficient to write your code in such a way that you can handle all the necessary operations inside the page's execution context in the first place, without too many context switches.

How to fail the test case - Cucumber with Groovy

When I check the particular cucumber step in the step definition file, if the condition is false, I wanted to make that particular test case should be stopped and fail and continue with the next test case.
If I have to use the FailureHandling.STOP_ON_FAILURE, how to code the line?
#When("User enters the (.*) in the Login")
def user_enter_userid_in_the_Login(String uid) {
if (uid=='')
/** FAIL the TEST CASE **/
else
WebUI.setText(findTestObject('Object Repository/ORTC01/Page_/input_userid'), uid,
FailureHandling.STOP_ON_FAILURE)
WebUI.delay(5)
}
def user_enter_userid_in_the_Login(String uid) {
assert uid!='' //this will fail test if uid==''
...continue success code
}
also possible to provide the error message
assert uid!='' : "the parameter 'uid' could not be empty"
it approximately corresponds to:
if(uid=='')throw new Exception("the parameter 'uid' could not be empty")

How to Enable/Disable Particular Assertion in all Test Case using Groovy?

I have suite to run the regression Test Case in Soap UI. It has a Assertion Capture Response which measures the time of each request. This is needed on demand.
If metrics needed then I need to Enable the Capture Response Time assertion and if it is not needed then I don't need the capture response time.
I have written the below code to check that whether it is disabled or not. If it is disabled then OK else i need to disable it.
The following code returns
java.lang.NullPointerException: Cannot get property 'disabled' on null object.
Can any one help on this?
def project = testRunner.getTestCase().getTestSuite().getProject().getWorkspace().getProjectByName("Regression");
//Loop through each Test Suite in the project
for(suite in project.getTestSuiteList())
{
//log.info(suite.name)
//Loop through each Test Case
if(suite.name == "ReusableComponent")
{
for(tcase in suite.getTestCaseList())
{
log.info(tcase.name)
for(tstep in tcase.getTestStepList())
{
stepName = tstep.name
suiteName=suite.name
caseName=tcase.name
def testStep = testRunner.testCase.testSuite.project.testSuites["$suiteName"].testCases["$caseName"].getTestStepByName("$stepName")
log.info(testStep.getAssertionByName("CaptureResponseTime").disabled)
}
}
}
}
Below statement is causing NullPointerException:
log.info(testStep.getAssertionByName("CaptureResponseTime").disabled)
In order to avoid NPE, then change it to:
log.info(testStep.getAssertionByName("CaptureResponseTime").isDisabled)
If you need to disable the assertion, then use below statement:
testStep.getAssertionByName("CaptureResponseTime")?.disabled = true
Another input:
In order to get the project, do not use workspace.
Instead use:
def project = context.testCase.testSuite.project

how to test the JSonResult in xunit test case?

I am doing unit testing with xunit (ASP.NET MVC).
I have written Action in controller which returns JsonResult.
For returning JsonResult, in Action I have written:
return Json(new { ok = true, newurl = Url.Action("Login") });
For testing the action, I have written in unit test case as:
JsonResult jsonResult = _accountController.ForgotPassword(ValidUserName) as JsonResult;
Assert.Equal("{ ok = true, newurl = Url.Action('Login') }", jsonResult.Data.ToString());
But, it's not working. Please guide me to correct it.
I would suggest debugging your unit test and looking at the value returned by jsonResult.Data.ToString(). My guess is newurl doesn't contain what you think it does. Assuming you're using VS2013 you can easily debug a unit test by setting a breakpoint, right-click inside the test method body, and select Debug Tests.
An alternative approach to verifying the information is to cast the JsonResult.Data to a dynamic. This allows you to compare each property individually instead of stringifying the JSON and comparing the results. This approach is, in my opinion, cleaner when the JSON becomes larger than a few properties.
var dynData = (dynamic)jsonResult.Data;
Assert.IsTrue( (bool)dynData.ok );
Assert.AreEqual( Url.Action("Login"), (string)dynData.newurl );

Using angulars ngResource get method

I have a basic controller defined in C#, its only purpose is to return whoever the current user is.
namespace ProjectName.Controllers
{
public class UserController : ApiController
{
// GET api/user/
public string Get()
{
return User.Identity.Name;
}
}
}
I then have an ngResource defined to look at that controller
cript.factory('User', function ($resource) {
return $resource('/api/User')
});
finally I try to get that user in my Angular Controller
$scope.checkIfAuth = function () {
$scope.user = User.get();
console.log($scope.user);
if ($scope.user === '"DS//:lemieszr"') {
console.log("success");
}
};
The problem is $scope.user is a resource object that looks like this
Resource {$get: function, $save: function, $query: function, $remove: function, $delete: function}
0: """
1: "D"
2: "S"
3: "\"
4: "\"
5: "l"
6: "e"
7: "m"
8: "i"
9: "e"
10: "s"
11: "z"
12: "r"
13: """
__proto__: Resource
Is there anyway to just get the string containing my Username. User.query() only returns an empty array.
I would advise looking into Angular's implementation of Kris Kowal's Q promise library ($q). I'm working with mvc 4.0 right now as well and I have found it to be much more flexible than ngResource.
However with respect to your question specifically, your issue here is you are making an async request to your server while synchronously invoking its response. Well, the data hasn't gotten there yet (why you are seeing an empty array []). That empty array is basically the server saying "Hey, good work following protocol on your http request, we are getting your data, to prove it to you here is an empty array where we will put the data there when it gets to you."
In other words, your problem is that you are asking setting checking the value of $scope.user before it even has one (roughly speaking).
You two options for simple fixes (at least to my knowledge):
You can set $scope.user to the response from the server in a SEPARATE function, or some other service, and then use the response once it gets there. OR (the better 'simple' fix) use the $timeout service, which essentially tells your system to "chill until my async request gets done and I have my data."
User.query() returns an empty array because it needs an array of json objects [{...},{...}] as a response from your back-end. User.get assumes that your server returns an object like {"name":"Andi"} for example, so if your server response is correct there is no problem with get method.
$scope.user = User.get();
Than you have access to you name property as $scope.user.name
This plumk may help you link

Resources