codeception do not see field but the browser does (Chrome Driver) - codeception

I have a codeception test on angular 5 application. with HTML5 pretty url.
I am testing 2 steps forms.
url: /register/ fields: first_name,email,password
when success redirect to:
url: /personal-details/ fields: date_of_birth
First step goes perfectly fine. I test all the scenarios. when step one ends, the browser redirects with HTML5 redirection to /personal-details/ as expected.
The problem is that codeception does not see #date_of_birth even though it is existed.
To verify that, I puased the execution and in the console I run
document.getElementById('date_of_birth')
and the field was found. it is on the page.
I though that it is related to the redirection, so I have added a special redirect in order to cause the first form to have the same problem, and it is working fine.
this is the error:
Test fields second step
Test tests\acceptance\FirstCest.php:testFieldsSecondStep
Step See element "#date_of_birth"
Fail Failed asserting that an array is not empty.
Scenario Steps:
What could possibly go wrong?
Thanks

Maybe Codeception checks if element exists before the page is fully loaded.
Try to use waitForElement instead of seeElement
$I->waitForElement('#date_of_birth', 10);

I came across this post with a similar issue. For (in my opinion) no valid reason I got the message
"Failed asserting that an array is not empty."
when using $I->canSeeElement() or $I->canSeeElementInDom(). In my case, I was not dealing with elements that are loaded asynchronously, those elements were present.
This is what my code looked like:
$I->canSeeElementInDOM('//*[#id="MyId"]//input[#name="myCheckbox"][not(#checked)]');
Using the following syntax fixed the problem:
$I->canSeeElementInDOM('//*[#id="MyId"]//input[#name="myCheckbox" and not(#checked)]');
Hope this helps someone too.

Related

Best way to automate a page and check if it is loaded correctly

I am looking to verify if this page loads correctly - http://www2.hm.com/en_ca/women.html
These are the things I think it would be best to verify if the page is loaded correctly, please let me know if I am missing anything
1) Verify all the links on this page works?
2) Verify if the menu on the top is loaded correctly, Do I need to verify the menu names?
3) Check if the classes are loaded properly?
4) get/post request status 200 and other ajax calls?
As per your question a seperate test to check if the page is loaded correctly will be a complete overhead because the Client (i.e. the Web Browser) will never return the Execution Control back to the WebDriver instance until and unless 'document.readyState' is equal to "complete". Once this condition is fulfilled Selenium performs the next line of code.
You can find a detailed discussion on this topic in Selenium IE WebDriver only works while debugging
Next as you want to Verify if all the links on this page works or not , you can write a function() and invoke the function() whereever required.
Moving on to next question, there is no necessity to Verify if the menu on the top is loaded correctly or not as you can't test each and every aspect of each and every WebElement present on a WebPage. The best approach would be to verify and validate the attributes of only those elements with whom we need to interact.
Again Checking if the classes are loaded properly will be a overhead as JVM takes care of it in the best possible way.
Finally, to validate get/post request status 200 you have to write Tests as per your requirement.

Selenium WebDriverException missing ) after argument list

js.executeScript("document.querySelector('input[name='password']');");
This line is throwing the following Exception in thread:
"main" org.openqa.selenium.WebDriverException: missing ) after argument list
Try the following code.
js.executeScript("document.querySelector('input[name=\'password\']')");
Try
js.executeScript("document.querySelector('input[name='password']')");
Let me know if this Answers your Question.
You can try one of the following
js.executeScript("document.querySelector(\'input[name=\'password\']\');");
js.executeScript("document.querySelector(\"input[name='password']\");");
Although in your comments you added this line
js.executeScript("document.querySelector('input[name=\'pas‌​‌​sword\']').value='ga‌​‌​mb'");
Which wouldn't work because if you look at .value you'll need to escape your .value setting as well more than likely.
Given that I don't have access to your site or your code, I would suggest that you test to make sure your javascript is valid for your page. One way to do so would be to take the javascript itself (everything insdie the .executeScript) and run it through your browsers dev tools console or script execution window.
If the value sets using the browsers dev tools, great...issue is with selenium. If the value does not set using browser dev tools...you'll need to refactor your javascript as the problem is likely not with selenium, rather your JS selector more than likely.
Although, the following, from your comment, works...you may not need to execute it via javascript.
driver.findElement(By.cssSelector("input[name='password']"‌​‌​)).sendKeys("gamb"‌​);

Page Factory - how does it work

I've tried to implement one of our app modules by using PageFactory (for iOS)
Most of the elements are located by name and others by classname
In general everything works (more or less) but the thing is that the appium server has tons of logs , it seems that each time I'm trying to use some page control , and all the declared controls within that page are being update (?) which cause to longer time execution.
In case and I'm trying to debug my test , it takes a lot of time to move step by step (the appium server works extra hours ...)
I do use "CacheLookup" whenever it possible ...
Where my mistake is, or it's just should be like that ?
Thanks
Updated
Not enough info provided to say for sure. If you have a bunch of cucumber steps and each step is creating a new page instance then yes, you could create a class variable to communicate between cucumber steps
Class variables get thrown out at the end of each scenario so no cross scenario contamination. However, if a single scenario leaves a page and comes back you would need to explicitly set the class page handle to nil/null so that it is reinitialized upon reentry to that page. You want to avoid stale element errors.

Getting web driver logging information running Protractor

So I am in the process of writing some tests with Protractor for an angular application I am working on. I ran into an issue where a test was failing because I tried to click on an element that while existed, it could not be clicked because another element was above it and it was receiving the click event. The error was just that true not does equal false which gives no insight to the real underlaying issue. I have run into this issue many times with other tests so I knew pretty quickly was the issue was but if I had not experienced this before, I don't know how long it would take me to figure it out.
I am 99% sure that when you send a click event with the JSON Wire Protocol that if the element does receive the click, there will be a message relating to that in it's response. Is there any way with Protractor to get the JSON Wire Protocol responses on to the screen when running the tests or at least get the responses captured in a file or something?
Assuming you are using Jasmine (the default) i suggest you start using explicit waits for elements to be present and visible before interacting with them like in your example.
I'm using this custom mathers.
Then:
var theElementFinder = $('#someElm');
expect(theElementFinder).toBePresentAndDisplayed();
Regarding
a way with Protractor to get the JSON Wire Protocol responses
You already see selenium errors in your Terminal / Console output.

Selenium RC - t.replace is not a function

[edit for godman] I am working on a web based application, written in PHP. I am using Selenium RC to run tests on the webpages produced by this application, through a browser.
I just upgraded to Firefox 14, so I had to upgrade to Selenium RC 2.25.0.
Now I'm seeing this error when running a test with htmlSuite:
Command execution failure. Please search the user group at
https://groups.google.com/forum/#!forum/selenium-users for error
details from the log window. The error message is: t.replace is not a
function
The command executed is:
clickAndWait //a[text()='! selenium test customer']
As you can see, it's not doing anything too tricky - just clicking a link. The test runs fine in the IDE, it's just when run via RC that it's a problem.
Searching in the groups revealed only really old threads dating back to version 1 of selenium.
Any ideas anyone?
[edit] I've been running the test that has these problems several times a day for the last week - and it doesn't seem to fail like this every time. This looks like it's a random problem. Has anyone seen this happen before?
[edit after the bounty got me no answers] Another example of it failing is with:
clickAndWait css=a.edit_company
This same call works fine earlier in the same test, on the same page.
[edit] Now I'm seeing the same error with a completely separate command:
type id=Address1 Address1
Does anyone have any suggestions about this? Any way I can even debug what's going on (I don't see this in the IDE at all)
I am not terribly familiar with clickAndWait. I personally prefer clicking and then doing my own custom waiting.
Try just clicking and add a Thread.Sleep(5000), or something similar, and see if the error is a result of the click or the wait part.
If it is the wait part, then I have a different suggestion than if it is the click part.
I've seen similar issues across various platforms. It has always been somewhat random for me, so I don't use clickandWait. Generally is is much more reliable to do a plain click, and then wait for specific condition. You could do a waitforpageload, but that has also been unreliable for me so I prefer things like waitfortextpresent and waitforelementpresent.
Usually, this kind of error would occur if you are dealing with something that is not a string. Could you just make sure that you are dealing with strings only?
2 possibilities where it is arising from:-
When text() is executed -> it might be dealing with a non-string
a[expression] -> the expression(text() = '! selenium test customer') when evaluated to False/True might be the problem because if a is a Map/array, the corresponding key should be a string and not a bool, probably.
text()='! selenium test customer' -->> is it an assignment operation? if yes, make sure that text() returns a lvalue or a mutable object (based on the language you are using selenium rc with)