There is a similar question out there (an older one in Python) but this one has to do with JS. Testing using Selenium in a NodeJS, Mocha environment. What I'd like to do is click on a Bootstrap dropdown and check the HTML to look for changes. I've tried the following:
test.it('should click on all header links',
function() {
var elem = driver.findElement(By.id('Profile'));
console.log(elem.getAttribute('innerHTML'));
console.log(elem.getInnerHtml());
});
Both calls return the same thing.
{ then: [Function: then],
cancel: [Function: cancel],
isPending: [Function: isPending] }
I plan to feed the HTML into cheerio so i can check for structure changes. Appreciate any help on this.
I was able to retrieve the HTML as a string by doing the following.
driver.findElement(By.id('Profile')).getAttribute("innerHTML").then(function(profile) {
console.log(profile);
});
I got the inner HTML with:
element.getAttribute('innerHTML').then(function (html) {
console.log(html)
})
Related
I was trying to add an additional url attribute as a function to my page-object while using nightwatchjs.
Like:
module.exports = {
url: function() {
return this.api.launchUrl + '/content/site1.xhtml';
},
cancelUrl: function() {
return this.api.launchUrl + '/content/cancel_site1.xhtml';
}
}
Anyhow nightwatch is not able to get that 2nd attribute cancelUrl, ie undefined.
Why is that so? Shouldn't nightwatch be able to access that attribute as it is nothing more than a function call returning a string or am I misunderstanding a javascript or special page-object concept?
--
I am aware that there should be a page-object for each site so there should not be a 2nd site. Anyhow I would like to understand why this is not working technically.
Not sure I can answer the "why" (other than to say that when nightwatch loads up your page objects as globally available it must be wrapping your js file and filtering on 'known' functions) but I can offer a solution: add a command to your page object with the desired function. For example:
let pageCommands = {
cancelUrl: function() {
return this.api.launchUrl + '/content/cancel_site1.xhtml';
}
};
module.exports = {
commands: [pageCommands],
...
}
It's not the typical use of page commands, but your test would then be able to access the cancelUrl function on the page object instance.
More on page commands here
This only happens on the device, not in the simulator. I can get as far as the 1st alert which leads me to believe it's not a html issue (very open to correction on this of course...). In the weinre debugger, I tried copying and pasting the $(document).on function but it said $(document) was null. This was working fine yesterday evening until i accidentally opened the file with libre office instead of notepad++. Notepad++ shows the line breaks as CR CF, could that have something to do with it?
Edit: I copied the contents of index.html to a notepad file and saved it as html in order to get rid of any hidden formatting. I've also added jQuery as the first script in index.html.
Finally, if I look at the elements in the weinre debugger, I can see index.html.
jQuery(document) gives me ReferenceError: jQuery is not defined so something seems to be wrong with jquery...
<script type="text/javascript" src="js/jquery-2.1.3.min.js"></script>
<script type="text/javascript" src="cordova.js"></script>
The paths are correct
Answer ahem... my bat script to package the contents of bin/debug/ only packed the files and not the folders, so no js folder went into the zip...
Thanks in advance for the help!
window.PhotoScan = window.PhotoScan || {};
alert("we can get this far");
$(function () {
alert("how do we not get to here???!!!!!");
$(document).on("deviceready", function () {
alert("index #5");
navigator.splashscreen.hide();
if(window.devextremeaddon) {
window.devextremeaddon.setup();
}
$(document).on("backbutton", function () {
DevExpress.processHardwareBackButton();
});
});
function onNavigatingBack(e) {
if (e.isHardwareButton && !PhotoScan.app.canBack()) {
e.cancel = true;
alert("index #6");
exitApp();
}
}
function exitApp() {
switch (DevExpress.devices.real().platform) {
case "android":
navigator.app.exitApp();
break;
case "win8":
window.external.Notify("DevExpress.ExitApp");
break;
}
}
alert("index #7");
PhotoScan.app = new DevExpress.framework.html.HtmlApplication({
namespace: PhotoScan,
layoutSet: DevExpress.framework.html.layoutSets[PhotoScan.config.layoutSet],
navigation: PhotoScan.config.navigation,
commandMapping: PhotoScan.config.commandMapping
});
alert("index #8");
PhotoScan.app.router.register(":view/:id", { view: "home", id: undefined });
PhotoScan.app.on("navigatingBack", onNavigatingBack);
PhotoScan.app.navigate();
});
Not sure where you have gone wrong, but typically i just wrap my bootstrap code inside the device ready. As i typically create a db schema first anyways.
document.addEventListener('deviceready', function () {
alert("index #5");
navigator.splashscreen.hide();
if(window.devextremeaddon) {
window.devextremeaddon.setup();
}
$(document).on("backbutton", function () {
DevExpress.processHardwareBackButton();
});
});
// ... your other functions here
If you want to keep them off global scope, can just wrap them in a self executing function:
(function() {
document.addEventListener('deviceready', function () {});
})();
I haven't used document ready in cordova apps, as i just have the js scripts load at the bottom. Then i load most content through handle bar templates and javascript.
Edit
As per the comments, you need to make sure that each time you add a new file or make a change to files in a cordova project, it must be rebuilt:
cordova run ios --device
cordova run android
#rory,
you wrote $(function(){})
This is NOT a good way to do things. If your function fails, for whatever reason, your program will NOT work.
Did you intend to do this?
Jesse
I am trying to verify that correct option is selected from selectbox using protractor.
This is how I pick value from selectbox:
element(by.id('form-mileage-unit')).click().then(function() {
element(by.cssContainingText('option', browser.params.lengthUnit)).click();
});;
So base on this I write code below:
it('Verify paint color', function() {
element(by.id('form-mileage-unit')).click().then(function() {
element(by.cssContainingText('option', browser.params.lengthUnit).getAttribute("value")).toEqual(browser.params.lengthUnit);
});;
});
Unfortunately I am getting error:
TypeError: Object by.cssContainingText("option", "Motohodin") has no method 'getText'
Can someone advise me with this?
You are closing the parenthesis in the wrong place and there is no expect(). Replace:
element(by.cssContainingText('option', browser.params.lengthUnit).getAttribute("value")).toEqual(browser.params.lengthUnit);
with:
var option = element(by.cssContainingText('option', browser.params.lengthUnit));
expect(option.getAttribute("value")).toEqual(browser.params.lengthUnit);
If you are dealing with select->option constructions a lot, consider using an abstraction over it that would make your tests cleaner and more readable, see:
Select -> option abstraction
This is my file which was contain template 'website_fb.fb_shared_post'
Qweb.add_template('website_fb_redertemplate.xml');
Below code through create a website side widget so now if call this widget then how to do.
I refer the Odoo documentation but nothing to understandable for me so please help me.
var RenderTemplate = Widget.extend({
template: 'website_fb.fb_shared_post',
events: {
// DO some code
},
init: function (el) {
// DO some code
},
start: function () {
// DO some code
}
});
First, when you create widget it will automatically render above XML file that you mention in the first line so below line render another widget template XML file
$(Qweb.render("fb_shared_post", {'res':'Hello'})).prependTo('<TemplateDivID or Class>');
I have the following piece of code
<div class="cv-uploader" id="customid">Upload CV</div>
$('.cv-uploader').fineUploader({
debug: true,
request: {
endpoint: '/process',
params:{ elementId:$(this).attr('id') }
},
//some other code
});
I need to send in the request parameters the ID of the element that triggered fineuploader. I tried $(this).attr('id') but it wont work.
Please help
Thanks
Sergiu
This is more of a general JavaScript question then a Fine Uploader question. The problem is that you are misunderstanding how context works in JavaScript. In your code, this will always refer to the window object. Obviously, this is not what you want.
You can either do this:
$('.cv-uploader').fineUploader({
debug: true,
request: {
endpoint: '/process',
params:{ elementId:$('.cv-uploader').attr('id') }
},
//some other code
});
...or this:
$('.cv-uploader').fineUploader({
debug: true,
request: {
endpoint: '/process'
},
//some other code
})
.on("submitted", function(event, id) {
$(this).fineUploader('setParams', {elementId: $(this).attr('id')}, id);
});
The latter example is possible as Fine Uploader's jQuery plug-in wrapper sets the context of any jQuery event handlers you bind to a Fine Uploader instance as the jQuery object that represents that element.
However, I would recommend the first approach as it is more efficient.