I am not sure how I to check that the value for the header is not null.
I have a test to ensure the header is there:
pm.test("Check there is an header", function() {
pm.response.to.have.header("random");
});
However, due to the value changing with every tag, I just want to make sure random is not null.
OMG!
It was as simple as pm.response.to.be.header("random").to.not.eql( null);
Related
I want to verify 'About Us', 'Contact Us' and 'FAQ' text links under 'More Information' footer section are displayed or not
How I can check it? Do I have to get xpath of each list web-element and then check whether its displayed on the web page? or lists of all web-elements at once,and then trace through for loop?
And also help me in writing xpath for 'About Us' element
You can verify all at once or you can verify individually also, try the below code which will fetch all the options, verifies whether those are present or not and checks they are displayed or not:
// Get all the options using the below line
List<WebElement> elements = driver.findElements(By.xpath("//div[#class='footer-section']//a"));
// Check they are present or not?
if(elements.size() > 0) {
System.out.println("=> The Options are present...");
} else {
System.out.println("=> The Options are nor present...");
}
// Check they are displayed or not?
for(WebElement element : elements) {
System.out.println(element.getText()+" is displayed? "+element.isDisplayed());
}
If you want to verify individually then you need to do like below:
driver.findElement(By.xpath("//div[#class='footer-section']//a[text()='About Us']")).isDisplayed();
If you want to verify that each element is present or not then yes you need to check separately for every element. Though you can make one generic method to check its present or not using assert.
For example:
public void checkElementPresent(String elementText){
Assert.assertTrue(driver.findElements(By.xpath("//a[text()="+elementText+"]")).size()>0);
}
Or if you dont want to use assert then you can use if else condition as well, like:
public void checkElementPresent(String elementText){
if(driver.findElements(By.xpath("//a[text()="+elementText+"]")).size()>0){
System.out.println("Element is present");
}else{
System.out.println("Element is not present");
}
}
And you can just call the method by sending the text of the link you want to verify if its present or not:
checkElementPresent("About Us"); or
checkElementPresent("Contact Us");
I'm trying to remove a field from a changeset (or set it to undefined) so that when the changeset is applied the field will be removed (or set to undefined) on the model. How can this be achieved?
Cheers
ember-changeset does not support setting a value to undefined. Calling changeset.set() with undefined as value does not set the value.
let obj = Ember.Object.create({
foo: 'a',
bar: 'b'
});
let changeset = new Changeset(user);
changeset.set('foo', null);
changeset.set('bar', undefined);
changeset.get('bar'); // b
changeset.get('change'); // { foo: null }
I'm quite surprised about that myself. Since it's not expected behavior and it does not seem to be documented, I think it should be considered a bug and get fixed.
I've opened a pull request for ember-changeset adding a failing test: https://github.com/DockYard/ember-changeset/pull/191
I debug my API using Xdebug and PHPStorm's debugging features. For this to work, the client needs a cookie named XDEBUG_SESSION.
When using Postman, I used to use a Chrome extension to add this cookie, and Postman's cookie interception feature to get this to work in Postman (since it's a sandboxed app).
However, I cannot create cookies in Paw. So, as a workaround, I modified the API response cookie to have the key as XDEBUG_SESSION and value as PHPSTORM, and debugging worked fine. However, this is not ideal as I would also like to set the expiry date to something far in the future (which I can't in Paw).
So, my questions are:
Is there a way to add custom cookies in Paw?
If not, is there a way to to edit the expiry date for an existing cookie (considering that name, value, domain and path are editable)?
Are there any other alternatives to achieve my objective?
I just managed to achieve this exact thing to debug my APIs with Paw (2.1.1).
You just have to Add a Header with the name Cookie and a value of Cookies picked from the dropdown that will appear. You then have to insert a Cookie named XDEBUG_SESSION with a value of PHPSTORM inside the Cookies value of the header just created.
To be more clear, you can see it in the screenshot below:
I messed around with it to see if I could create an extension. I wasn't able to, and the below does not work but thought I'd share in case anyone knows the missing pieces.
First off, there is no extension category (generator, dynamic value, importer) that this functionality falls into. I tried to make use of the dynamic value category but was unsuccessful:
CookieInjector = function(key, value) {
this.key = "XDEBUG_SESSION";
this.value = "PHPSTORM";
this.evaluate = function () {
var f = function (x,y) {
document.cookie=this.key+"="+this.value;
return true;
}
return f(this.key, this.value);
}
// Title function: takes no params, should return the string to display as
// the Dynamic Value title
this.title = function() {
return "Cookie"
}
// Text function: takes no params, should return the string to display as
// the Dynamic Value text
this.text = function() {
return this.key+"="+this.value;
}
}
// Extension Identifier (as a reverse domain name)
CookieInjector.identifier = "com.luckymarmot.PawExtensions.CookieInjector";
// Extension Name
CookieInjector.title = "Inject Cookie Into Cookie Jar";
// Dynamic Value Inputs
CookieInjector.inputs = [
DynamicValueInput("key", "Key", "String"),
DynamicValueInput("value", "Value", "String")
]
// Register this new Extension
registerDynamicValueClass(CookieInjector);
The main thing stopping this from working is I'm not sure how the request is built in PAW and not sure how to attach the cookie. I've looked through the documentation here: https://luckymarmot.com/paw/doc/Extensions/Reference/Reference, and can't find what I need.
Hello StackOverflow experts,
I would like to know if it would be possible to use Ember.js' computed properties to modify the value of the property before returning to whatever object requests it.
Imagine this simple example:
I have a User object with mail property
When I set the property, I want the email address to change from first.last#example.com to first.last#anotherexample.com, then return it
When I request the property ( via User.get ) I want to get the modified property back.
I think it should be pretty simple by utilising another 'helper' property, like formatted_mail, where I would store and retrieve the formatted value, but I wonder if something like this can be done without additional model properties.
So far, I have this coffescript code, but I always get 'undefined' when reading the property, even though I set it before, so I suspect the value does not get saved by Ember anywhere:
mail: ( ( key, value ) ->
if arguments.length == 1
return this.get 'mail'
else
return value.split( '#' )[0] + '#anotherexample.com'
).property 'mail'
Thank you for your assistance!
You are close to solution.
As computed properties are always cached by default in Ember (you could disable this behaviour using .volatile()), you do not have to specify what to do when arguments.length is 1, except if you want to specify a default value.
So here it should looks like:
App.User = Ember.Object.extend({
mail: function(key, value) {
if (arguments.length === 2) {
return value.split('#')[0] + "#tieto.com";
}
return null;
}.property()
});
The return null just specify the default value.
When you set the mail property, it will cache the returned value and always returns it without recomputing this property.
Note that you can do that only because the mail property does not depend on other properties. If you were declaring it with .property('anotherProperty'), the mail property will be recomputed any time anoterProperty changes. So in the example above it will reset it to null.
You can try it in this JSFiddle.
In a handlebars template in Ember.js, I have blocks like the following:
{{content.some_attribute}}
{{content.some_other_attr}}
{{content.more_attr}}
Some of these attributes don't exist and I'm implementing them slowly.
Is there a way to get these templates to compile and either ignore the blocks that don't evaluate or better yet, replace them with a html element so they're easier to spot in the browser?
(the template is pretty large and it's being converted from ERB slowly,
Is there a way to get these templates to compile and either ignore the blocks that don't evaluate
Properties that don't exist are undefined, and don't get rendered at all. In other words {{thisDoesNotExist}} will simply be invisible -- it will compile just fine.
or better yet, replace them with a html element so they're easier to spot in the browser
As Cory said, you could use a helper for this that checks for undefined, using Ember.Handlebars.registerBoundHelper.
This seems like a perfect case for a handlebars helper. The helper could validate the value and return the value or the html that you desire.
The following code should be used very carefully, since it has not been tested within an application.
A possible solution to replace the possible undefined value in a template is to overwrite Ember.getPath, which is used to lookup the value of a path in a template, see http://jsfiddle.net/pangratz666/hKK8p/:
var getPath = Ember.getPath;
Ember.getPath = function(obj, path) {
var value = getPath(obj, path);
return (Ember.none(value) ? 'OMG %# is not defined!!'.fmt(path) : value);
};
If this code would be used temporarily in an application, I would also restrict the check for undefined values to a specific obj. So something along those lines:
App.objectWhichHasUndefinedProps = Ember.Object.create({
...
});
Ember.View.create({
templateName: 'templateWithAttributes',
objBinding: 'App.objectWhichHasUndefinedProps'
}).append();
var getPath = Ember.getPath;
Ember.getPath = function(obj, path) {
var value = getPath(obj, path);
if (obj === App.objectWhichHasUndefinedProps) {
return (Ember.none(value) ? 'OMG %# is not defined!!'.fmt(path) : value);
}
return value;
};