Protractor: Else statement isn't working as expected - if-statement

I'm trying to click on a link if it exists, if not it should add that corresponding link and then click on the same.
In below If loop, 'Else' condition is not getting executed if first condition is not satisfied. The same is working if its placed outside IF loop.
I'm confused.
Could anyone help me out in resolving this please ?
var ConfigLink = element.all(by.partialLinkText('Provide Configuration')).get(0);
ConfigLink.isDisplayed().then(function(result) {
if (result) {
ConfigLink.click();
}
else {
element.all(by.css('input[name="checks"]')).get(0).click();
}
});
If the initial If condition fails , I want the script to execute the else part, but this is not working.
kindly suggest how this can be resolved Thank you

Found the answer. Replaced isDisplayed() with 'isPresent()' and the code seems to be working fine now without any issues. This makes sense since, isDisplayed() assumes that the element is already present. If the element is not present, an error should be thrown.

Related

list package `MoveToFront` not working for me

New to Go and building a simple LRU cache in Go to get used to syntax and Go development.
Having an issue with the MoveToFront list method, it fails on the following check in the MoveToFront body
if e.list != l || l.root.next == e
I want to move the element (e) to the front of the list when I retrieve it from cache , like this
if elem, ok := lc.entries[k]; ok {
lc.list.MoveToFront(elem) // needs fixing
return elem
}
return nil
The Code can be seen here on line 32 the issue occurs
https://github.com/hajjboy95/golrucache/blob/master/lru_cache/lrucache.go#L32
There seem to be two problems, to me. First, this isn't how the List data type is meant to be used: lc.list.PushFront() will create a List.Element and return a pointer to it. That's not fatal, but at the least, it is kind of annoying—the caller has to dig through the returned List.Element when using Get, instead of just getting the value.
Meanwhile, presumably the failure you see is because you remove elements in Put when the LRU-list runs out of space, but you don't remove them from the corresponding map. Hence a later Put of the just-removed key will try to re-use the element in place, even though the element was removed from the list. To fix this, you'll need to hold both key and value. (In my simple experiment I did not see any failures here, but the problem became clear enough.)
I restructured the code somewhat and turned it into a working example on the Go Playground. I make no promises as to suitability, etc.

WTL CListViewCtrl getSelectedItem is causing an Assertion fail for me

This is my code in order to get the name of the item which has been selected in my CListViewCtrl:
LVITEM item = { LVIF_PARAM };
CString itemText;
clistViewCtrl.GetSelectedItem(&item);
clistViewCtrl.GetItemText(item.iItem, item.iSubItem, itemText);
Note that this code is working. I recently did another project, where I grabbed the name in exactly this way, however, I had no problems there with any assertion fails.
When I execute this with my current project, I always get a debug assertion:
"File: ... atlctrls.h"
Line: 3242
Expression: (GetStyle() & 0x0004) != 0
Even though the expression already states it pretty much, here is the line causing the failure:
ATLASSERT((GetStyle() & LVS_SINGLESEL) != 0);
I have barely any idea what the problem is. As I said, the exact same code worked on my other project, and I just went through both, trying to find any differences which could cause this behaviour, but nothing caught my eye.
Honestly, I don't even know if this is related to my code at all, considering the two compared elements seem to be predefined.
My first guess would have been that this part is being called before the items are created, but all items in the listview are created at the point I try to call this code passage.
Can anyone point me to a solution?
Your control is not created with style flag LVS_SINGLESEL. So calling GetSelectedItem is causing an assert. In case of multi selection use GetFirstSelectedItem and GetNextSelectedItem instead of GetSelectedItem. For single selection you can continue useing GetSelectedItem, but you have to add LVS_SINGLESEL style flag to your control.

Assert failed in OnInitDialog()

So I have an "assertion failed" error message when I want to run my program. I understand that it means that somewhere a condition that should be true isn't but I don't know how to correct that.
The error concerns the following line :
_AFXWIN_INLINE BOOL CEdit::SetReadOnly(BOOL bReadOnly)
{ ASSERT(::IsWindow(m_hind)); return (BOOL)::SendMessage(m_hWnd, EM_SETREADONLY, bReadOnly, 0L); }
So I get that it's about the "Read Only" condition, but I don't know where to correct that.
I am new in C++, so sorry if I forgot to put important information in my question.
Thanks in advance!
The OnInitDialog function contains a call to the base class function
CDialog::OnInitDialog();
Move your calls to SetReadOnly to after that line. The edit control variables are only initialized after that line.
Thank you for your help! Finally, after going through the whole code line by line, I realized in DoDataExchange I mixed up and put twice the same variable at some point instead of two different ones ... So I don't really know how that got me that error but I thought I'd keep you updated in case someone makes the same absent-minded mistake and gets that error :)

Element XMLZONE is undefined in REQUEST

I'm getting the error Element XMLZONE is undefined in REQUEST a few dozen times a day.
PageDisplay.cfm calls request.xmlzone which is set via the page ZoneManager.cfm, using the following (cut down) code
<cfscript>
variables.aZoneInfo = XmlSearch(application.xmlZones, "//zone[position() = 1]");
try {
request.xmlZone = ToString(variables.aZoneInfo[1]);
}
catch(any expt)
{
variables.objZoneDAO = CreateObject("component", "#application.sComponentDir#ZoneDAO").init(application.sDSN);
variables.objZoneDAO.Read(variables.objZone, 1); }
</cfscript>
Now, the XML will never ever change so is it worth adding the XML file/node to PageDisplay.cfm as a variable? I'd also like to know why it fails - any reason why?
Thanks,
JJ
Well, if the call to ToString(variables.aZoneInfo[1]); fails, then request.xmlZone won't get set. It's doubtful toString() itself will fail, but if variables.aZoneInfo isn't an array with at least one element, then that'll cause you grief. You should be checking this, rather than assuming it.
If it's essential that request.xmlZone is set, then you need to do more in your catch block than what you're currently doing. At the very least you should be logging the exception that was caught, so that when you go "I wonder why that happened?" you have a log to refer to.
I suspect your application is timing out, and when you're doing your xmlSearch(), application.xmlZones doesn't contain what you think it contains. But that's a guess.

C++ dll Loop Problem

Im having a problem with a loop inside a C++ dll being called from VB. I want this loop to update a global variable, but when I call the function the variable does not update the first time round, but does so every subsequent time.
This is how I am trying to update the variable.
else
{
::nScore = nHighest;
if (nScore != 0)
{
::nColourOn++;
}
}
As a workaroud I am forcing the variable to be what I want in the VB code, but am not happy with this solution. Does anyone have any idea what might be causing this?
Many Thanks.
If the value of nHighest isn't initialized, nScore will be 0 and nColorOn won't be incremented. Is that the error you're seeing? If so, set nHighest, otherwise, it's working fine. :)