'Failed script timeout error' in protractor test case - protractor

im trying to execute this tests and I got: 'Failed: Script timeout' and i don't undesrstand where is the error, literally i have do copy paste, in the last test case is working, but in this code i got that error. Thanks in advance.
var name_filter = browser.element(by.xpath(browser.params.constants.GENERALPATHS.CATALOG.NAMEFILTER));
var seriestitle_filter = browser.element(by.xpath(browser.params.constants.GENERALPATHS.CATALOG.SERIESTITLEFILTER));
var catalog_title = browser.element(by.xpath(browser.params.constants.GENERALPATHS.CATALOG.CATALOGTITLE));
await browser.wait(EC.elementToBeClickable(name_filter), waitLongTime);
await browser.wait(EC.elementToBeClickable(seriestitle_filter), waitLongTime);
var catalogues = await element.all(by.className('ui-grid-cell-contents ng-binding ng-scope'));
for(var i=0; i<catalogues.length; i++) {
var catalogue_text = await catalogues[i].getText();
await catalogues[i].click();
await browser.wait(EC.elementToBeClickable(name_filter), waitLongTime);
await browser.wait(EC.elementToBeClickable(seriestitle_filter), waitLongTime);
expect(catalog_title).toEqual(catalogue_text);
}

I've given a recommendation to you some time ago to switch to async/await. I see you're using that, and I hope that made your experience working with protractor better
Unfortunately I can't give you direct answer to your question again, because the script may be causing problems in any line and no way to find out where exactly without the app you're testing. Additionally, there may be a few problems related your config.
However, I tend to help to solve problems with the processes people choose for test development
In this example, I highly recommend you to setup a run configuration in webstorm or vs studio. This will allow you to execute any script line by line, explore variables etc. If you do that, you can easily find the line where you script fails and troubleshoot immediately. If you find the line with the problem but still don't understand why it happens, let me know, I'll try to walk you through the steps I'd do to figure out the issue
Hope it helps, and sorry for a vague answer

Related

VSCode Custom Extension: Seem not to work

I'm currently trying to write an VS Code extension and it's a bit frustrating. I did everything as said here:
https://code.visualstudio.com/docs/extensions/example-hello-world
But after using yo code and entering all necessary information, I opened the respective folder VS Code hit F5 and VS Code says I should configure my launch.json (this should be done by yo code, shouldn't it?). However, when I press the debug start button, a extension-host window opens as described in that tutorial. BUT: When I try to execute the extension the command palette won't find it.
I tried several command names such as "hello world" "helloworld" or variants of the name of the extension that I gave in yo code. I also noticed the
"commands": [{
"command":"extension.sayHello",
"title":"Hello World"
}]
section of the package.json, but somehow I don't manage it to put it all together in order to get a simple, working vs code extension. In tutorial videos on youtube everyone can simply hit F5 after launching VS Code, what I cannot. Pretty weird somehow.
Any help is appreciated!
Thanks in advance.
EDIT: Additional information.
When I activated vs code to show all exceptions (even handled) vs code stops at the following point (see default:)
at internal/process/stdio.js (core module)
// ...
case 'PIPE':
case 'TCP':
var net = require('net');
stream = new net.Socket({
fd: fd,
readable: false,
writable: true
});
stream._type = 'pipe';
break;
default:
// VS CODE STOPS AT THE LINE FOLLOWING!
// Probably an error on in uv_guess_handle()
throw new Error('Implement me. Unknown stream file type!');
}
// Ignore stream errors.stream.on('error', function() {});
} catch (error) {
stream = createDevNull();
}
//...
Hopefully it helps :(
I solved my problem by reading the tutorial with more attention. The tutorial tells you to activate the command palette by Hitting F1 not CTRL P. This solved my Problem.
I did not change anything in the code; rather it seems to be important to hit F1 instad of [CTRL] + [P] despite it actually brings up the same input. I'm still wondering why to differenciate between CTRL + P and F1 if both bring up the same control. :/
Hope it helps other beginners, too.
cheers!
I had the same issue (though didn't debug to see if it failed on the same line) and I resolved it by restarting VSCode.

How to stop automatically closing browser when writing protractor test cases

I am new to writing test cases using protractor for non angular application. I wrote a sample test case.Here the browser closes automatically after running test case.How can I prevent this. Here is my code
var submitBtnElm = $('input[data-behavior=saveContribution]');
it('Should Search', function() {
browser.driver.get('http://localhost/enrollments/osda1.html');
browser.driver.findElement(by.id('contributePercentValue')).sendKeys(50);
submitBtnElm.click().then(function() {
});
});
I was also struggling with a similar issue where i had a test case flow where we were interacting with multiple application and when using Protractor the browser was closing after executing one conf.js file. Now when I looked into the previous response it was like adding delay which depends on how quick your next action i performed or it was hit or miss case. Even if we think from debugging perspective most of the user would be performing overnight runs and they would want to have browser active for couple of hours before they analyze the issue. So I started looking into the protractor base code and came across a generic solution which can circumvent this issue, independent of any browser. Currently the solution is specific to requirement that browser should not close after one conf.js file is executed, then could be improved if someone could add a config parameter asking the user whether they want to close the browser after their run.
The browser could be reused for future conf.js file run by using tag --seleniumSessionId in command line.
Solution:
Go to ..\AppData\Roaming\npm\node_modules\protractor\built where your
protractor is installed.
Open driverProvider.js file and go to function quitDriver
Replace return driver.quit() by return 0
As far as my current usage there seems to be no side effect of the code change, will update if I came across any other issue due to this change. Snapshot of code snippet below.
Thanks
Gleeson
Snapshot of code snippet:
Add browser.pause() at the end of your it function. Within the function itself.
I found Gleeson's solution is working, and that really helped me. The solution was...
Go to %APPDATA%Roaming\npm\node_modules\protractor\built\driverProviders\
Find driverProviders.js
Open it in notepad or any other text editor
Find and Replace return driver.Quit() to return 0
Save the file
Restart your tests after that.
I am using
node v8.12.0
npm v6.4.1
protractor v5.4.1
This solution will work, only if you installed npm or protractor globally; if you have installed your npm or protractor locally (in your folder) then, you have to go to your local protractor folder and do the same.
I suggest you to use browser.driver.sleep(500); before your click operation.
See this.
browser.driver.sleep(500);
element(by.css('your button')).click();
browser.driver.sleep(500);
Add a callback function in It block and the browser window doesn't close until you call it.
So perform the action that you need and place the callback at your convenience
var submitBtnElm = $('input[data-behavior=saveContribution]');
it('Should Search', function(callback) {
browser.driver.get('http://localhost/enrollments/osda1.html');
browser.driver.findElement(by.id('contributePercentValue')).sendKeys(50);
submitBtnElm.click().then(function() {
// Have all the logic you need
// Then invoke callback
callback();
});
});
The best way to make browser NOT to close for some time, Use browser.wait(). Inside the wait function write logic for checking either visibilityOf() or invisibilityOf() of an element, which is not visible or it will take time to become invisible on UI. In this case wait() keep on checking the logic until either condition met or timeout reached. You can increase the timeout if you want browser visible more time.
var EC=protractor.ExpectedConditions;
var submitBtnElm = $('input[data-behavior=saveContribution]');
it('Should Search', function() {
browser.driver.get('http://localhost/enrollments/osda1.html');
browser.driver.findElement(by.id('contributePercentValue')).sendKeys(50);
submitBtnElm.click().then(function() {
browser.wait(function(){
EC.invisibilityOf(submitBtnElm).call().then(function(isPresent){
if(isPresent){
return true;
}
});
},20000,'error message');
});
});
I'm sure there is a change triggered on your page by the button click. It might be something as subtle as a class change on an element or as obvious as a <p></p> element with the text "Saved" displayed. What I would do is, after the test, explicitly wait for this change.
[...]
return protractor.browser.wait(function() {
return element(by.cssContainingText('p', 'Saved')).isPresent();
}, 10000);
You could add such a wait mechanism to the afterEach() method of your spec file, so that your tests are separated even without the Protractor Angular implicit waits.
var submitBtnElm = $('input[data-behavior=saveContribution]');
it('Should Search', function() {
browser.driver.get('http://localhost/enrollments/osda1.html');
browser.driver.findElement(by.id('contributePercentValue')).sendKeys(50);
submitBtnElm.click().then(function() {
});
browser.pause(); // it should leave browser alive after test
});
browser.pause() should leave browser alive until you let it go.
#Edit Another approach is to set browser.ignoreSynchronization = true before browser.get(...). Protractor wouldn't wait for Angular loaded and you could use usual element(...) syntax.
Protractor will close browsers, that it created, so an approach that I am using is to start the browser via the webdriver-reuse-session npm package.
DISCLAIMER: I am the author of this package
It is a new package, so let me know if it solves your problem. I am using it with great success.

MongoDB shell: Run command asynchronously?

Lately I have found I have to do a lot of long running operations like:
db.whois.find({"basic.last_updated":"1970-01-01 00:00:00"}).forEach(function (doc) {
var parts = doc._id.split('#');
doc.basic.last_updated = parts[1];
db.whois.save(doc);
})
That's fine but since the shell prompt doesn't return until it's complete I am finding I have to keep lots of shells open. Is there any way I can issue a command and send it async so that I can continue using the same shell? Maybe even get a little message when the process is done?

How do I detect if XenApp Client is installed on user machine?

We are upgrading from Citrix Metaframe to XenApp, and I need to know if there's a way to programmatically detect if the XenApp Web Plugin v11.0 is already installed on a client machine when it contacts our webserver for login -- this was previously done for the Metaframe Web Client by attempting to instantiate the ICA client in an ASP script, which used the results to determine whether to offer the client as a download/install.
The current code for this detection is:
Set icaObj = CreateObject("Citrix.ICAClient")
The above code does not find the XenApp plugin.
I continued my research after posting this question and I finally found the answer. Only 3 views on this question since I posted it, but despite the disinterest I believe I should answer my question, "Just in Case" someone else has this problem.
I was mistaken in my statement in question that the code I posted didn't find the XenApp plugin. In fact, it does. It returns a valid object in the presence of both Metaframe and XenAppWeb. I posted this question on Citrix's own forums, and no answers there either.
What I did to find the answer was to create a VS2008 project to which I added a COM reference to the Citrix ICA library -- both of them, installed separately one at a time. I found that both had a COM library named WFICALib, and searched through both of them to see if there was something that might distinguish them. What I found was a property, ClientVersion, which was 9.0.xxx for Metaframe, and 11.0.xxxx for XenAppWeb.
BINGO!
From this I cut the following code to return the version as a function in VBScript:
Function GetVer()
Dim icaObj, Ver
On Error Resume Next
Set icaObj = CreateObject("Citrix.ICAClient")
if err.number = 0 then
if IsObject(icaObj) then
GetVer = icaObj.ClientVersion
else
GetVer = 0
end if
set icaObj = nothing
else
GetVer = 0
end if
End Function
ADDENDUM:
Since posting this answer, I have discovered that this script in the newer versions of Internet Explorer (e.g. IE9) is not reliably detecting the plugin -- sometimes it worked, and other times not! What I did to fix the problem was to switch the script to JScript instead of JavaScript, and the new version looks like this:
<script type="text/jscript">
function GetCitrixVersion() {
try {
var icaObj = new ActiveXObject("Citrix.ICAClient");
return icaObj.ClientVersion;
}
catch (e) {
return 0;
}
}
</script>
Note the script type is text/jscript, not text/javascript.

Watin Unit Tests with Nunit Timing problem

Hi i am using WatiN (version 2.0.10.928) with NUnit (2.5.2.9222)
if I have something like
[Test]
public void WebPageTest()
{
string url = "www.google.com";
IE ie = new IE(url);
ie.TextField(Find.ByTitle("Google Search")).TypeText("Watin");
ie.Button(Find.ByName("btnG")).Click();
ie.Element(Find.ByText("WatiN")).Click();
// ie.WaitForComplete();
Assert.IsTrue(ie.Text.Contains("Welcome at the WatiN"));
ie.Close();
}
Then usually this will work and the test will pass but sometimes when I hit the assert it seems that Watin hasn't finished loading the page and is still on the previous page. I have this problem using the IE.Text or the IE.Url properties. I tried using WaitForComplete() (even though that shouldn't be neccessary) but still sometimes have the same problem.
Has Anybody had this problem with WatiN before?
Has anybody succesufully managed to use WatiN with NUnit like this? Or Maybe it would work better with a different unit testing framework like MBUnit? Has anyone had better luck with MBunit?
The test framework you use will make no difference, I'm afraid -- this is one of the "gotchas" of any screen-scraping test framework, and WaTin is no different.
The WaitForComplete() call is definitely necessary, I'm afraid.
Some of my colleagues have reported that the version of IE can make a difference; IE6 in particular has some internal timing issues that can cause problems. IE8 appears to be quite a bit better.
I've had the same problem with my tests; unfortunately it doesn't seem as though you can assume that the WaitForComplete() that's supposed to be inherent in the Click() method will function correctly. Even explicitly calling WaitForComplete() afterward hasn't always worked.
As a last resort we have used System.Threading.Thread.Sleep(int timeout_in_milliseconds) to force the browser to give the page time to load. This isn't a completely bulletproof means of doing it, but it has eliminated about 90% of these sorts of errors. For the timeout we have used anything from 500 to 2000 milliseconds, depending on how long it takes to load and how quickly we want the test to run.
Try using
[Test]
public void WebPageTest()
{
string url = "www.google.com";
IE ie = new IE(url);
ie.TextField(Find.ByTitle("Google Search")).TypeText("Watin");
var btnG = ie.Button(Find.ByName("btnG"));
btnG.ClickNoWait();
ie.WaitForComplete(400);
var elementWatin = ie.Element(Find.ByText("WatiN"));
elementWatin.ClickNoWait();
ie.WaitForComplete(400);
Assert.IsTrue(ie.Text.Contains("Welcome at the WatiN"));
ie.Close();
}
Thanks
Gandhi Rajan
I have used ie.WaitForComplete() but it still does enforce waiting, and sometimes it times out, so I use
Settings.AttachToBrowserTimeOut = 200;
Settings.WaitForCompleteTimeOut = 200;
This worked for me.