JsTestDriver firefox browser crash - linux

I'm just starting out with JsTestDriver and I've created very simple demo code to see if I have configured my environment correctly. However about 40-50% of the time I'm getting the following error when Firefox is launched (via JsTestDriver) "Firefox Closed Unexpectedly While Starting".
This error does not occur if I use Chrome.
My environment consists of:
VirtualBox 4.1.18 running Ubuntu 10.04.4 LTS 32bit
Firefox 13.0.1
JsTestDriver-1.3.4.b
openjdk-6-jre-headless
I'm executing:
java -jar /home/developer/bin/JsTestDriver.jar --port 9876 --browser /usr/bin/firefox --tests all --testOutput results
My JsTestDriver config is:
server: http://localhost:9876
load:
- src/*.js
test:
- test/*.js
timeout: 10
The source code (code under test) is:
Person = function()
{
this.firstName = "";
this.lastName = "";
this.fullName = function()
{
if((this.firstName != "") && (this.lastName != ""))
{
return this.lastName + ", " + this.firstName;
}
var name = this.firstName + " " + this.lastName;
return name.trim();
}
};
The test code (JsTestDriver based code) is:
PersonTest = TestCase("PersonTest");
PersonTest.prototype.testFullName = function()
{
fixture = new Person();
fixture.firstName = "John";
fixture.lastName = "Doe";
assertEquals("Doe, John", fixture.fullName());
};
PersonTest.prototype.testFullName_FirstNameOnly = function()
{
fixture = new Person();
fixture.firstName = "John";
assertEquals("John", fixture.fullName());
};
PersonTest.prototype.testFullName_LastNameOnly = function()
{
fixture = new Person();
fixture.lastName = "Doe"
assertEquals("Doe", fixture.fullName());
};
Thanks!

Your problem may be in that you're spinning up your server opening your browser every time you run your tests. I think a less error prone solution would be to start your server and have it capture some browsers, and then leave it running. Then you can run your tests against that server as needed. Our solution at work involves three virtual machines running IE7,IE8,IE9,Firefox, and Chrome all the time, and our Maven build process runs our javascript unit tests at every build. Also, make sure that you always use the '--reset' argument as well. It will keep your browsers fresh. I wrote a post that shows how to integrate QUnit, Requirejs, and code coverage with JSTD that is independent of Maven: js-test-driver+qunit+coverage+requirejs. Hope it helps.

Related

Azure Linux App Service with .Net Core Stack. Unable to use NodeJS

I am hosting a .NET Core Application on MS Azure (on a Linux Service Plan) and I want to run some NodeJS code in the .NET Core Application. I did this a while ago on a Windows Service Plan, there it was working. Now I am trying with a Linux Plan and it is not working.
First I was trying to use "Jering.Javascript.NodeJS" and then also "INodeServices" from Microsoft (which is obsolete). But "node" was not found. I also tried to start directly a Process (Code below), but also not working. "node" is not found.
var proc = new System.Diagnostics.Process
{
StartInfo = new System.Diagnostics.ProcessStartInfo
{
FileName = "node",
Arguments = " -v",
RedirectStandardOutput = true
}
};
result += "RUN: " + proc.StartInfo.FileName;
proc.Start();
var reader = proc.StandardOutput;
NodeJS is installed on the server and also the command works there but it seems that the .NET Core app is hosted as docker and does not have any access outside to run NodeJS. Image
I found a useful information here.
The problem is that Node is not present in the container so it is
necessary to have a script to install and start it before starting the
app itself.
Reproduceļ¼š
Here is my script:
//using System.Diagnostics;
ProcessStartInfo startinfo = new ProcessStartInfo();
startinfo.FileName = "bash";
//startinfo.FileName = "/etc/opt/nodejs/14.15.0/bin/node"; //it's no use even node package located here.
Process process = new Process();
process.StartInfo = startinfo;
process.StartInfo.UseShellExecute = false;
process.StartInfo.RedirectStandardInput = true;
process.StartInfo.RedirectStandardOutput = true;
process.Start();
//install and start nodejs
process.StandardInput.WriteLine("apt-get install curl");
process.StandardInput.WriteLine("curl -sL https://deb.nodesource.com/setup_12.x | bash");
process.StandardInput.WriteLine("apt-get install -y nodejs");
//Run "node -v"
process.StandardInput.WriteLine("node -v");
string line = string.Empty;
while (!process.StandardOutput.EndOfStream)
{
line = process.StandardOutput.ReadLine();
_logger.LogInformation(line);
}
process.WaitForExit();
return string.Empty;
It works on my .net Core app based on Linux.
I think I found a better solution ;)
In an app service you can mount a storage. In my case I mounted a storage, which contains the nodeJS lib.
Azure Portal Screenshot
Now i can execute the following code:
string result = "";
var proc = new System.Diagnostics.Process
{
StartInfo = new System.Diagnostics.ProcessStartInfo
{
FileName = "/externallibs/node/bin/node",
Arguments = " -v",
RedirectStandardOutput = true
}
};
result += "RUN: " + proc.StartInfo.FileName;
proc.Start();
var reader = proc.StandardOutput;
return result + reader.ReadToEnd();
You can create on azure portal an environment var named POST_BUILD_COMMAND with a command to fix your environment path.
Linux Service Plans runs on Oryx which is documented here
POST_BUILD_COMMAND=PATH=/usr/bin/node:$PATH

Coded Ui Test - locally passed / remotely not

My Coded UI Test should Save/Download a File(Pdf, Excel) from IE10 and I am using this code:
var savePopUp = new UITestControl(GetBrowserWindow()) { TechnologyName = "MSAA" };
savePopUp.SearchProperties.Add(UITestControl.PropertyNames.ControlType, "ToolBar");
savePopUp.SearchProperties.Add(UITestControl.PropertyNames.Name, "Benachrichtigung");
var saveButton = new UITestControl(savePopUp) { TechnologyName = "MSAA" };
saveButton.SearchProperties.Add(UITestControl.PropertyNames.ControlType, "SplitButton");
saveButton.SearchProperties.Add(UITestControl.PropertyNames.Name, "Speichern unter");
Mouse.Click(saveButton);
If I run this locally for testing my code works fine but remotely the controls will not be found.
How do I make the test work remotely?

Coded UI Tests don't run on one machine, but run on another

My co-workers and I are working on a Coded UI project. We both have the same version of the project thanks to TFS, but on his computer all the test cases run, and on mine they don't. They used to run perfectly fine on my machine until one morning they decided to not work. I always keep getting the same error that the UI Test Controls are not found, even though the mappings are correct. Let me remind you that they work perfectly fine on my co-workers machine. We also have the same version of IE (11).
What could be the cause for this?
Thanks for the help in advance.
My co-worker seemed to resolve the situation, but we still don't understand why the previous version of the code worked for everyone but my machine. The problem occurred in our LaunchBrowser method which would use 2 different instantiations of the browser variable. He got rid of the unnecessary one and the playback commands and seemed to have fixed the problem.
Below are two versions of the code, the previous one and the newly written one:
Old:
public static void LaunchBrowser(string url)
{
GlobalVariable.browser = new BrowserWindow();
CloseAllBrowsers();
BrowserWindow.CurrentBrowser = GlobalVariable.BrowserType;
Playback.PlaybackSettings.WaitForReadyLevel = Microsoft.VisualStudio.TestTools.UITest.Extension.WaitForReadyLevel.Disabled;
GlobalVariable.browser = BrowserWindow.Launch();
System.Uri URI = new System.Uri(url);
GlobalVariable.browser.NavigateToUrl(URI);
Playback.PlaybackSettings.WaitForReadyLevel = Microsoft.VisualStudio.TestTools.UITest.Extension.WaitForReadyLevel.UIThreadOnly;
GlobalVariable.browser.Maximized = true;
if (BrowserWindow.CurrentBrowser == "Firefox")
{
Mouse.Click(_fireFoxAuthOK);
}
Logging.WriteLog("Browser was navigated to " + url + " in browser: <" + GlobalVariable.BrowserType + ">");
}
New:
public static void LaunchBrowser(string url)
{
CloseAllBrowsers();
BrowserWindow.CurrentBrowser = GlobalVariable.BrowserType;
GlobalVariable.browser = BrowserWindow.Launch(new Uri(url));
GlobalVariable.browser.Maximized = true;
if (BrowserWindow.CurrentBrowser == "Firefox")
{
Mouse.Click(_fireFoxAuthOK);
}
Logging.WriteLog("Browser was navigated to " + url + " in browser: <" + GlobalVariable.BrowserType + ">");
}
I think the problem is in this line :
Playback.PlaybackSettings.WaitForReadyLevel = Microsoft.VisualStudio.TestTools.UITest.Extension.WaitForReadyLevel.UIThreadOnly;
Because the browser's foreground thread is not ready to start the playback. you may try this
Playback.PlaybackSettings.WaitForReadyLevel = WaitForReadyLevel.Disabled;
or different alternative ways in your pc.
Refer this link Mathew Aniyan's Blog for further information.

Protractor running tests on PhantomJS

I can't seem to get PhantomJS through a test successfully. I tried to integrate it into my project, but after that failed I tried to just run the basic Angular Docs samples and I'm getting the same issue. My steps so far:
npm install -g phantomjs
phantomjs --webdriver=9515 // ... GhostDriver - Main - running on port 9515
protractor protractorConf.js
This is the same file from the example with only browserName, and seleniumAddress port changed:
// An example configuration file.
exports.config = {
// The address of a running selenium server.
seleniumAddress: 'http://localhost:9515',
// Capabilities to be passed to the webdriver instance.
capabilities: {
'browserName': 'phantomjs'
},
// Spec patterns are relative to the current working directly when
// protractor is called.
specs: ['onProtractorRunner.js'],
// Options to be passed to Jasmine-node.
jasmineNodeOpts: {
showColors: true,
}
};
I get the following error message:
UnknownError: Error Message => 'Detected a page unload event; asynchronous script execution does not work across page loads.'
I found this issue on github, which seemed to be related. I thought I had made enough sense of their brower-setup.md to include it in one of my beforeEach functions. Then I found here ptor is just wrapping the driver anyway. Wow, I know I'm a noob here in protractor/selenium land, but the signal to noise ratio is intensively dissuasive. I'd really like to get the performance benefits of using PhantomJS, but the prospect of losing several more hours on this is hurting my head. I'm on Windows 7 Enterprise 64-bit, in case that matters. Thanks!
Acutally this fix was solving the same issue for me:
https://github.com/pschwartau/protractor/commit/1eeff8b1b2e3e8f3b7c8152264411f26d4665a07
As originally described here: https://github.com/angular/protractor/issues/85#issuecomment-26846255 by renanmartins
Inside protractor/lib/protractor.js Replace
this.driver.get('about:blank');
this.driver.executeScript(
'window.name = "' + DEFER_LABEL + '" + window.name;' +
'window.location.href = "' + destination + '"');
with
var driver = this.driver;
this.getCapabilities().then(function (capabilities) {
if (capabilities.caps_.browserName === 'phantomjs') {
driver.executeScript('window.name = "' + DEFER_LABEL + '" + window.name;');
driver.get(destination);
} else {
driver.get('about:blank');
driver.executeScript(
'window.name = "' + DEFER_LABEL + '" + window.name;' +
'window.location.href = "' + destination + '"');
}
// Make sure the page is an Angular page.
driver.executeAsyncScript(clientSideScripts.testForAngular, 10).
then(function(hasAngular) {
if (!hasAngular) {
throw new Error('Angular could not be found on the page ' +
destination);
}
});
});

How do I get the code coverage output to display using expresso?

I'm working on getting Expresso set up and some tests running. I followed along with a tutorial on node tuts and have 4 tests running, and passing. Now I'm trying to get a code coverage output to show up when I run the tests, like the docs show. However, I'm sort of lost.
My super basic learning example tests are in a file called test.js in a folder called test:
var Account = require('../lib/account');
require('should');
module.exports = {
"initial balance should be 0" : function(){
var account = Account.create();
account.should.have.property('balance');
account.balance.should.be.eql(0);
},
"crediting account should increase the balance" : function(){
var account = Account.create();
account.credit(10);
account.balance.should.be.eql(10);
},
"debiting account should decrease the balance" : function(){
var account = Account.create();
account.debit(5);
account.balance.should.be.eql(-5);
},
"transferring from account a to b b should decrease from a and increase b": function(){
var accountA = Account.create();
var accountB = Account.create();
accountA.credit(100);
accountA.transfer(accountB, 25);
accountA.balance.should.be.eql(75);
accountB.balance.should.be.eql(25);
}
}
And the code itself is in lib/account.js:
var Account = function(){
this.balance = 0;
}
module.exports.create = function(){
return new Account();
}
Account.prototype.credit = function(amt){
this.balance += amt;
}
Account.prototype.debit = function(amt){
this.balance -= amt;
}
Account.prototype.transfer = function(acct, amt){
this.debit(amt);
acct.credit(amt);
}
Account.prototype.empty = function(acct){
this.debit(this.balance);
}
When I run expresso from the command line, I get:
$ expresso
100% 4 tests
Likewise, if I run expresso with a -c flag or a variety of other options, I get the same output. I'd like to get the code coverage output shown in the docs. I've also run the command $ node-jscoverage lib lib-cov, and the lib-cov folder has things in it now..
What am I missing?
Best result I've found so far was to edit paths on test run:
This is run_tests.sh
#! /bin/bash
rm -Rf ./app-cov
node_modules/expresso/deps/jscoverage/node-jscoverage app/ app-cov
NODE_PATH=$NODE_PATH:/usr/local/lib/node:/usr/local/lib/node_modules:./mmf_node_modules:./app-cov node_modules/expresso/bin/expresso -c

Resources