codeceptjs react testing - Clickable element was not found by text|CSS|XPath - reactjs

I have a project made with react and rest api(php+mysql).I have to put it through a codeceptjs test.The app is working properly with countless of manual testing, and as far as I can see, the codeceptjs test is working too, but it gives the following error:
Error: Clickable element "ADD" was not found by text|CSS|XPath
at new ElementNotFound (node_modules/codeceptjs/lib/helper/errors/ElementNotFound.js:14:11)
at assertElementExists (node_modules/codeceptjs/lib/helper/WebDriver.js:2835:11)
at WebDriver.click (node_modules/codeceptjs/lib/helper/WebDriver.js:917:7)
at processTicksAndRejections (internal/process/task_queues.js:97:5)I }) => {
I.amOnPage('/');
I.click('ADD');
I.seeElement('#product_form');
I.fillField('#sku', 'SKUTest000');
I.fillField('#name', 'NameTest000');
I.fillField('#price', '25');
I.waitForElement('#productType');
I.selectOption('#productType','DVD');
I.waitForElement('#size');
I.fillField('#size','200');
I.click('Save');
My add element looks like this:
<Link title="ADD" to="/add-product">ADD</Link>
Can someone please help me out why is this error appearing and how can I solve it? Thanks in advance!
Update:
I did a couple more tests, and I noticed that sometimes it gives back less/different errors depending on the test's time. For example:
http://165.227.98.170/open?testName=ed
http://165.227.98.170/open?testName=ah
http://165.227.98.170/open?testName=bc
My guess is that is has to do with how react loads in the html elements and manages the rest api calls. How/what should I change in the app to accomodate the test script?

Seems like the problem was I put the whole home page's load after the rest api call by accident.

Related

Non-angular page opened with click - angular not defined using ignoreSynchronization or waiting for Angular without

After a lot of research, and tinkering, I can't seem to actually get my Protractor test to do anything else other than have an Angular related error, even though I am using browser to avoid Angular being detected at all.
The test involves an Angular app, opening a dropdown in it, and clicking on the link for the console; the console opens a non-Angular admin page in a separate window.
So based on the many informative SO posts I found, I first used this...
browser.driver.getAllWindowHandles().then(function(handles) {
browser.driver.switchTo().window(handles[1]).then(function() {
//expect for new window here
});
});
Which appeared to work, as I could get to the window through repl pretty easily.
The issue is when either of the following were added...
browser.driver.getAllWindowHandles().then(function(handles) {
browser.driver.switchTo().window(handles[1]).then(function() {
expect(browser.getLocationAbsUrl()).toContain('/console/login.jsp');
expect(browser.driver.findElement(By.css('th.login')).getText()).toEqual('Login');
});
});
One expect check the URL and the other checks for the header element on the page, which is a table header. When I run this, I get the following:
Error while waiting for Protractor to sync with the page: "angular could not be found on the window"
When I decide to use browser.ignoreSynchronization = true, both in the function, or in a beforeEach, with or without a following afterEach setting it to false, I get the following:
JavascriptError: angular is not defined
I can't seem to get any "useful" errors to help me debug it, and trying it in repl does not help, as I get the same issue.
To be comprehensive, trying my URL expect without getting the second window will give me the root, and the other will fail.
Just doing one or the other will cause the same problem.
Changing to regular syntax (element(by.css...)) does not change things.
So much for my first question...
It appears that my use of browser.getLocationAbsUrl() is meant to be used for an Angular page, and was causing my issue...
Essentially, even though I believed I was using pure Webdriver calls, that call still required Angular on the page to work...
As stated in another post, the use of browser.driver.getCurrentUrl() is a non-Angular call using Webdriver, and fixed the problem. Thus, the final code is the following...
browser.sleep(1000); //to wait for the page to load
browser.driver.getAllWindowHandles().then(function(handles) {
browser.driver.switchTo().window(handles[1]).then(function() {
expect(browser.driver.getCurrentUrl()).toContain('/console/login.jsp');
expect(browser.driver.findElement(By.css('th.login')).getText()).toEqual('Login');
});
});
This works without setting ignoreSynchronization, BTW.
I realized it would probably be something relatively simple to fix it, just didn't expect I'd get it that quickly (I intended on submitting the question last night, but posted it this morning instead).
In any case, I hope this will at least be a good reference for anyone else facing the same issue.
Seems like getLocationAbsUrl is angular abs url.
Try using the native driver getCurrentUrl instead.
-- expect(browser.getLocationAbsUrl()).toContain('/console/login.jsp');
++ expect(browser.driver.getCurrentUrl() ...

Protractor locator can't find html element in phantomjs only

I have a few tests that are running fine in chrome, but if I switch to phantomjs, I have the following error:
Unable to find element with css selector '.selected-recipients a'
My test is simply this:
it('should navigate when clicking edit', function() {
var editLink = element(by.css('.selected-recipients a')).element(by.css('.edit-preview'));
editLink.click();
expect(browser.getCurrentUrl()).toContain('#/recipients');
});
This works fine on chrome. The problem is phantomjs. I found a post that suggests that the problem might have to do with window size, but that didn't solve the problem for me:
https://github.com/angular/protractor/issues/585
I also tried to use by.id instead of by.css and I have the same problem. All other tests in this file work fine and some do use by.css, so it doesn't look like a problem with phantomjs understanding this locator. It seems like the element is not in the page at all.
Any ideas? Thanks
When phantomjs is acting in a strange way I dump a screen shot.
Probably not what you are looking for, but it is an idea. :)
page.open("http://www.stackoverflow.com", function()
{
page.render('script_ending.png');
}
Another idea is to try dumping the html to a file, to see if the element is there.
Or try changing the DOM, inserting an element, then see if you can find it.
Or try searching by just the class name, to see at what point it fails... maybe there is no child element of tag a.

Jstree and angularJS using promise

I lost two days trying to solve this problem by myself, but I give up. pleaseee help .
i want to load my tree using jstree and promise AngularJS
but I keep getting this error:
Uncaught Neither data nor ajax settings supplied.
i can see im my html page jsut the pluging loading and no result :(
y'll find in thi link my code .
http://plnkr.co/edit/kDjFCa4x6Ghyb3pwghXc?p=preview
Thank you very much :)
After some playing with your code, I got this: http://plnkr.co/edit/JfTVNdQnaGZV01wyQHtn
changes: third argument of scope.$watch to true, setting "json_data" to
"json_data" :{
"data":scope.jstree.data
}
(looks strange, but it's quirks of jsTree)

Backbone.js model not defined in view?

I've decided that I am going to try and learn backbone.js by making a web app. This is the first time I have done anything extensive in javascript, so the answer to my problem may be right in front of my face.
I have the web app on github, along with a running version that doesn't work. The javascript console just says that something is undefined when I don't think it should be. Here's the error that chrome gives for line 30 of app.js:
Uncaught TypeError: Cannot read property 'el' of undefined
I've sort of been referencing the backbone-fundamentals example modular to-do app, and it doesn't seem to have any issues with a similar thing.
If anyone could point out what I am doing wrong, I would be most appreciative!
Thanks in advance!
Your Machine view render method was missing return this and by default all methods return undefined - that's why chaining didn't work
Edit: and a small tip:
jQuery, Underscore and Backbone register globally - and thanks to that you don't have to define them as dependencies every time - it's enough if you require them in your main script once and after that you can access them from the global scope as you normally would
In my case i was returning this without the return keyword. As i was using javascript and not coffeescript it failed on me. So, if you are using javascript use return this; instead of just this in the last line of the render() function.
I also had a problem when using this.collection.on('reset', this.render(), this). I instead had to use this.collection.on('reset', this.render.bind(this));

object error in ie7

How can i solve object error in ie7. Once i load my page. ie7 shows [object Error] in an alert box. i want to know why it happens and how to solve this.
(EDIT) this just in:
It now seems that IE7 sometimes displays this popup when an error occurs. It almost looks like it's trying to display an alert() with an object in it, called error. Here's how I found out. I was trying to set a table row's CSS display attribute to table-row, but after some debugging and internet seaching, I found out that IE7 and earlier do not support table-row as a display value. What I had:
document.getElementById('writeoff_tablerow').style.display = 'table-row';
What solved the problem:
try {
document.getElementById('writeoff_tablerow').style.display = 'table-row';
}
catch(e) {
document.getElementById('writeoff_tablerow').style.display = 'block';
}
(EARLIER ANSWER)
I've been stumped with this same thing today. Ultimately, the cause of the problem boiled down to the fact that I was using document.body.addEventListener to make the page respond to a mouse click:
document.body.addEventListener('click',function(){document.getElementById('blah_div_id').style.display='none';},false);
When I changed the code to the following, the problem was gone in IE7:
document.body.onclick=function(){document.getElementById('blah_div_id').style.display='none';};
post some code, otherwise we cant help you.
try the website in Firefox with Firebug installed, and maybe you will get additional information in the console there (if the problem is in FF as well, that is)
Since i am using Protovis Graph library. This is cause for my error. Since Protovis is not compactable with ie7 it araise object error.

Resources