Problem with connecting to websocket using TestCafe and Safari in BrowserStack - websocket

When running within a testcafe test in Safari using BrowserStack (command for run test: testcafe "browserstack:safari#15.3:OS X Monterey" src/ --skip-js-errors), upon loading an app that tries to connect to a websocket, I receive an error in the console of
"WebSocket connection to
'ws://localIP/FhPen2vWb!w!s*webAppAdress/https://websocketAdress'
failed: The request timed out".
I realized that when I run remote test in real safari - there wasn't this poblem. What can cause that? Is it bug? I can't find, if I can solve it..
enter image description here
Code example below. In this code after 'maximizeWindow()' the app tries to connect to websocket for getting data, but it isn't happened and the next code row don't do right thing and tests became failed.
import { Selector } from 'testcafe';
import { Role } from 'testcafe';
fixture('Create agent')
.page('https://${{webAppUrl}}')
.beforeEach(async t => {
await t.useRole(userRole);
});
test('Create agent for Ped Source', async t => {
await t
.click('span.icon.icon-add')
.typeText('input[name=\'modelName\']', 'testCafeModel')
.click('button[type=\'submit\']')
.maximizeWindow()
.click('div[title=\'Pedestrian Library\']')
});

Related

Failed to connect (500) to bot framework using Direct Line

We have a bot running in Azure (Web App Bot) that I'm trying to embed on a website. The bot is based of the Bot Builder V4 SDK Tamplate CoreBot v4.9.2. At first I used the iframe to embed the bod. This worked but didn't provide the features we need, so now im changing it to use DirectLine.
My code on the webpage looks like this:
<script crossorigin="anonymous"
src="https://cdn.botframework.com/botframework-webchat/latest/webchat.js"></script>
<div id="webchat" role="main"></div>
<script>
(async function () {
const res = await fetch('https://[my bot name here].azurewebsites.net/.bot/v3/directline/tokens/generate',
{
method: 'POST',
headers: new Headers({
'Authorization': "Bearer [my token here]"
})
});
const { token } = await res.json();
window.WebChat.renderWebChat(
{
directLine: await window.WebChat.createDirectLineAppServiceExtension({
domain: 'https://[my bot name here].azurewebsites.net/.bot/v3/directline',
token
})
},
document.getElementById('webchat')
);
document.querySelector('#webchat > *').focus();
})().catch(err => console.error(err));
</script>
After some struggles I managed to fetch a token from https://[my bot name here].azurewebsites.net/.bot/v3/directline.
And I can see the chat window on my webpage, but is says connecting for a while then it changes to Taking longer than usual to connect, like this:
In the Chrome console there is an error saying Failed to connect Error: Connection response code 500. When I check Chrome's Network tab I can see that the token generated completed with status 200 and that the websocket connection is open, like this:
----------EDIT---------
I just noticed that when go to https://[my bot name here].azurewebsites.net/.bot using a webbrowser, the resulting json is
{"v":"1.0.0.0.55fa54091a[some key?]","k":true,"ib":false,"ob":false,"initialized":true}
ib and ob should be true but are false, maybe this is part of the problem.
----------EDIT 2---------
OK so now I'm starting to go crazy.
Ashish helped me and at some point the ib and ob were true. They were true for most of yesterday. At some point yesterday they turned false for a short while (no more than 2 hours). I checked if someone had triggered the release pipeline but no recent releases. After that ib and ob magically turned true again and connecting to the direct line worked again.
Now this morning ib and ob were false again. And again no recent releases. I don't know what is causing this.
Does anybody know what's going on here or how to fix this? How do I find what causes ib and ob to be false?
Any help is appreciated! Thanks in advance. If you need more information, just ask and I'll post it.
If the ib and ob values displayed by the *.bot endpoint are false this means the bot and the Direct Line app service extension are unable to connect to each other.
Make sure you verify below things:
Double check the code for using named pipes has been added to the
bot.
Confirm the bot is able to start up and run at all. Useful
tools are Test in WebChat, connecting an additional channel, remote
debugging, or logging.
Restart the entire Azure App Service the bot
is hosted within, to ensure a clean start up of all processes.
Please check troubleshooting guide, it seems updated today. (still old date reflected some how, not sure why)

Why is my Websocket connection not working in the Developer Console?

I'm trying to connect to a server using websockets. I've set up the port on the server, and am trying to connect through the Dev console in Chrome (also tried Firefox and got the same result).
I connect from the console using:
var websocket = new WebSocket('ws://localhost:5001');
This gives me the message "undefined". However, if I do
websocket.readyState
I get "1".
I then do
websocket.binaryType = 'arraybuffer';
which prints "arraybuffer".
If I then do something like
websocket.send("1+1");
it says undefined.
However, if I do all of this in an HTML file with JavaScript, it connects fine and I get the result "2", so it looks as though the Websocket itself is ok, and what I'm typing in is ok, but it's something to do with it being in the Dev Console that's the issue.
I don't know anything much about setting up Websockets.
I solved this by adding an onmessage function to the websocket:
websocket.onmessage = function (result) {
console.log(result.data);
}

Debugging topshelf as a service

I am having problems running TopShelf as a service and I am not getting much info to help troubleshoot. I am using dotNet core 2.2.
I get this error when I start it:
Error: 1053: The service did not respond to the start or control
request in a timely fashion.
Event logs show:
A timeout was reached (30000 milliseconds) while waiting for the Test service to connect.
The Test service failed to start due to the following error: The service did not respond to the start or control request in
a timely fashion.
It message shows a 30 second timeout in the error popup happens in about 1 second. I don't think its a time out.
I my current setup I am using an IHostedService, but I have tried it without this. Here is the current setup.
var hostBuilder = SetupHost();
var rc = HostFactory.Run(x =>
{
x.Service<IHost>(s =>
{
s.ConstructUsing(name => hostBuilder.Build());
s.WhenStarted(tc =>
{
_logger = tc.Services.GetRequiredService<ILogger<Kickoff>>();
tc.StartAsync();
});
s.WhenStopped(tc => tc.StopAsync());
});
x.RunAsLocalService();
x.SetDescription("Test");
x.SetDisplayName("Test");
x.SetServiceName("Test");
x.EnableShutdown();
x.OnException(p => ExceptionOccured(p));
});
If you see something glaring people let me know.
My main goal is to find a technique to troubleshoot this. I've tried logging to a file with system.io but it does not produce results. I don't know how to debug it or get meaning information.

Problem using variables in test actions in Firefox

I am getting this error:
1) Error on page "http://localhost:8080/en/index.html":
import declarations may only appear at the top level of a module:
    No stack trace available
whenever I run my test on Firefox. My tests are written in Typescript and are testing my page locally. The tests have no problems in Safari and Chrome, only in Firefox does it complain about import declarations. I have tried to recreate the error in non-local sites but have not been able to.
import { Selector } from "testcafe"
const full = "http://localhost:8080/en/index.html"
fixture`This is my tests`
.page`http://www.example.com/`;
test("URL", async t => {
const logo = Selector(".Logo")
await t
.navigateTo(full)
.expect(logo.textContent).contains("LogoName")
})
Hoping someone can shed some light on how to fix this!
Can you open the page in Firefox and check if you have error message in the JS console?
Testcafe will fail if there is any JS error.
You can use --skip-js-errors flag to ignore js errors (https://devexpress.github.io/testcafe/documentation/using-testcafe/command-line-interface.html#-e---skip-js-errors) or ... fix that error on your page.

Android Nativescript won't connect to socket.io, IOS does

I'm running in a very frustrating error, trying to connect an android (nativescript) app with socket.io
I've developed my app for ios and trying to port it to Android but socket.io won't connect, I narrowed the problem down to a simple hello world from the templates with only the socket.io plugin. It works with IOS but not with Android. I get silent errors
running this bit of code :
export class AppComponent
{
socket;
constructor()
{
console.log('constructor!');
this.socket = SocketIO.connect('https://eaglecar.org');
this.socket.on('connect', ()=>
{
console.log('Connect!');
});
this.socket.on('error', (error) =>
{
console.log('Error!');
console.log(error);
});
}
}
For information, this connects to a server with a let's encrypt ssl certificate.
IOS console output
CONSOLE LOG file:///app/app.component.js:8:20: constructor!
CONSOLE LOG file:///app/tns_modules/#angular/core/./bundles/core.umd.js:3053:20: Angular is running in the development mode. Call enableProdMode() to enable the production mode.
CONSOLE LOG file:///app/tns_modules/nativescript-socket.io/common.js:41:22: nativescript-socket.io on connect []
CONSOLE LOG file:///app/app.component.js:11:24: Connect!
But with Android
it silently fails given neither Connect! nor Error!
JS: constructor!
JS: Angular is running in the development mode. Call enableProdMode() to enable the production mode.
At first I was thinking about a timing error, so I tried to attach the connect to a UI callback, the function gets called but with no errors.
Can't find anything interresting with adb logcat but this, seems normal :
08-04 15:10:24.377 11162 11162 V JS : constructor!
08-04 15:10:24.386 11162 11193 D NetworkSecurityConfig: No Network Security Config specified, using platform default
08-04 15:10:24.389 11162 11195 I System.out: (HTTPLog)-Static: isSBSettingEnabled false
08-04 15:10:24.389 11162 11195 I System.out: (HTTPLog)-Static: isSBSettingEnabled false
Just tried to change the connecting domain to something that does not exist and still no error in the console...
Additional tests :
2 tests I made :
I successfully loaded an image over https in the same app on the same
server with the same certificate
I successfully connected to a non secure socket.io server on
another port (3000) on Android.
Server side
var fs = require('fs');
var options = {
key: fs.readFileSync('../ssl/keys/[this_is_a_valid_key].key'),
cert: fs.readFileSync('../ssl/certs/[this_is_a_valid_cert].crt')
};
var server = require('https').createServer(options);
server.listen(443,'eaglecar.org');
var io = require('socket.io').listen(server);
io.on('connection', function(socket){
console.log('connected!!');
});
I had doubts and it appears to be true, Just replaced the certificate with a paid certificate from some well known vendor and now everything runs smoothly.. Apparently IOS recognises let's encrypt but android doesn't. At least the socket io plugin doesn't. because images are loaded just fine over https with let's encrypt.

Resources