How to handle signout when the browser in close in flex 3? - javascript

My project had audit module, which includes each and every action of the user to be recorded.
When the user closes the browser the audit regarding the logout has to be stored in the database.
I found one solution on the net, but it is working in my machine's IE but failed to work in the friends machine's IE why?
The code is:
window.onbeforeunload = clean_up;
function clean_up()
{
var flex = document.${application} || window.${application};
flex.myFlexFunction();
}
I placed this code in the index.template.html file in the html-template folder under flex src.
I also placed the below code in my main application.mxml file:
ExternalInterface.addCallback("myFlexFunction",btnLogout);
and I defined the logout function.

Ok, here is the deal. CAN NOT BE DONE RELIABLY. If this is for audit... you are out of luck and deliver a half baked approach to start with.
Why?
Go to your task manager, kill the IIS process - nothing logs out. No audit. Ergo - the solution does most likely not fulfill the legal audit requirements ;)
Another approach:
Call a service exvery X seconds from the running page. Like every 5 seconds.
Assume client dies when you dont receive call for 2 * X seconds (like after 10 seconds).
This way you realize when the client does not connect anymore. Does not stop the user from pulling the network cable and conrinuing viewing, so a failure of the audit method call should wipe the HTML content ;)
But at least you handle browser crashes / terminations, too.

Related

How Can I Test A File Download Using Cypress When Running In Chrome

I have the following test that needs to verify that clicking a link downloads a PDF. This is especially important as we are using Gatsby, which in turn uses Reach Router's Link Component, and it is relatively easy to misconfigure things so that the router takes over the link and navigates to a 404 page instead of initiating a download.
describe.skip(`Downloads`, () => {
it(`Downloads the expected file`, () => {
cy.visit(pagePath)
cy.getByHref(downloadPath)
.should(`have.attr`, `target`, `_blank`)
.click()
cy.location(`pathname`).should(`eq`, pagePath)
})
})
While this isn't perfect, it does at least check that there is no navigation as a result of clicking the link.
The problem is that when running this test using cy run, which runs the tests in Chrome, the test hangs, due to Chrome's download dialogue.
How can I prevent the test from hanging?
Note that the downloadPath resolves to a pdf in the static directory, for example /static/example.pdf. There is no server component.
Also note that this is a different question to: How can I use Cypress.io to assert that a file download has been initiated without actually downloading?
Actually I searched alot about it and found that
It is not possible to run tests in headless mode with browser extensions installed, because the only supported browser in headless mode is Electron, and Electron doesn't support extensions as stated in the documentation.
Running headless Chrome is not supported yet. See this issue: #488
https://github.com/cypress-io/cypress/issues/488
And this is a an issue not so old it was tagged in Feb 2019
https://github.com/cypress-io/cypress/issues/832
https://github.com/cypress-io/cypress/issues/1235
There are a lot of ways to test this, so it depends. You’ll need to be aware of what actually causes the download, then think of a way to test that mechanism.
If your server sends specific disposition headers which cause a browser to prompt for download, you can figure out what URL this request is made to, and use cy.request() to hit that directly. Then you can test that the server send the right response headers.
If it’s an anchor that initiates the download, you could test that it has the right href property. As long as you can verify that clicking the button is going to make the right HTTP request, there’s nothing else to test for.
In the end, it’s up to you to know your implementation and to test enough to cover everything.
You can prevent the test from hanging by disabling the dialog asking where to save the file. Once you do that chrome will happily download your file and Cypress can continue running your test.
In chrome go to settings->Advanced->Downloads->Ask where to save each file before downloading and make sure it is off.
There are more complicated solutions in the links Apolo provided but this is a quick workaround.

Windmill in Python hanging when using getPageText()

I'm trying to write a simple script with Windmill to open a page (which has javascript) and then download the entire html. My code is:
from windmill.authoring import setup_module, WindmillTestClient
from windmill.conf import global_settings
import sys
global_settings.START_FIREFOX = True
setup_module(sys.modules[__name__])
def my_func():
url = "a certain url"
client = WindmillTestClient(__name__)
client.open(url=cur_url)
html = client.commands.getPageText()
This last line, with getPageText() just seems to hang. Nothing happens and it never returns.
Also, is it necessary for windmill to open up the whole GUI every time? And if it is, is there a function in python to close it when I'm done (a link to any actual documentation would be helpful; all I've found are a few examples)?
Edit: solved the problem by just using Selenium instead, took about 15 minutes vs 3 hours of trying to make Windmill work.
A colleague of mine came up with an alternate solution, which was to actually watch the network traffic coming into the browser and scrape the GET requests. Not totally sure how he did it though.

Use javascript to launch local file on user's machine?

I have an Excel macro that runs in a workbook that our company uses. I've made cells look like hyperlinks, so when someone double-clicks on the link it opens IBM mainframe and loads up some data. I'm writing another app for us that's web based, and I'm wondering if this same functionality is possible. I haven't seen anything on the internet that would lead me to believe I could do this, but I thought I'd ask anyway....
Public SODD As String
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
If Target.Column = 2 And (Target.Row >= 1) Then
SODD = Target.Value
Call SOLookup
End If
End Sub
Sub SOLookup()
Dim autECLPS As Object
Dim s As New AutSess
AppActivate "3270 Terminal"
s.SetConnectionByName ("A")
s.autECLPS.StartCommunication
s.autECLPS.SendKeys "[Clear]"
s.autECLOIA.WaitForInputReady (500)
s.autECLPS.SetText "SODD " & SODD
s.autECLOIA.WaitForInputReady (500)
s.autECLPS.SendKeys "[ENTER]"
s.autECLOIA.WaitForInputReady (500)
End Sub
This loads the IBM mainframe and types in the sales order number into their screen and hits Enter.
Would I be able to accomplish this same feat using something like Javascript?
Javascript may not execute files on the user's local environment. However, a server side language may do what you require. For instance, you can use AJAX(javascript) to make a call to a PHP script which can execute, say, a batch file (.bat) which can then run your macro. The PHP file could have code as simple as
system("cmd /c C:[path to your macro/.bat file]");
Again, this all depends on your configuration and environment. So to recap: Web Browser->AJAX->PHP->Macro.
Neither Javascript nor any other script that runs inside the browser is allowed to execute any file locally on a user's computer. And this is a good tihng. Imagine what would happen if any website could randomly execute programs on your computer...
Internet ressources are not trusted, therefore they are not allowed to do anything on your local computer.
If the website is running in your company's intranet, there might be a way using proprietary MS technology and the Internet Explorer with properly configured trusted sites - but I wouldn't bother with it.

How can I run multiple auto-runs from my USB?

I am attempting to make my USB somewhat like a "plug-and-go" device. I am putting scripts I need ran onto my USB, and making it so I only have to click a button or two for all the scripts to begin. I was wondering what commands I would use to do the following;
1) Whenever I plug in the USB, I would like to either hold or press a key (such as 1,2,3,4,etc) that would choose which script I ran. Is this possible?
2) Is it possible for me to plug in a USB, and with the correct scripts, not have to unplug the USB and have it run through a series of scripts (through start-ups/restarts)
A better Explanation
Is it possible that I run one script, which would require a restart, for my to keep the USB in, and as soon as the computer starts again it would run the next script specified.
Sorry if I am unclear. If you are willing to help, I am willing to explain it in a way you can understand.
Thanks!
You may be able to achieve something similar by using the Task scheduler in Windows (assuming your in a windows environment). As far as auto running scripts from flash drives its a bad idea, the majority of Antivirus software will block autorun scripts on a flash drive.
Lovely, I wanted to do this and I did. I used Command Prompt, batch language, I think, to do that.
I used this method:
record that the USB had run the first script automatically
restart the computer
login and the autorun would pop up, logically
it would run the second script because, from the record, the program knows to run another since the first had finished already
#echo off
title autorun
color 0a
mode con: cols=82 lines=25
set /p ran=<"check.txt"
if "%ran%" == "true" (goto second) else (goto first)
:first
echo Merry Easter~ (^u^)
timeout /nobreak /t 3 >nul
echo true>"check.txt"
shutdown -r -t 0
pause >nul
echo Shutdown doesn't seems to be successful, but if you want, press any key to see the next message~
pause >nul
goto second
:second
echo Happy Christmas~ [>u<]
timeout /nobreak /t 3 >nul
del "check.txt"
exit

appMobi / phonegap setting/deleting cookie click action required 2 times before working?

I can't figure out for the life of me whats up with this. I dunno if this is appMobi/phonegap centric, cause they have there own special ways of setting cookies, and handling them. But I have what seems to be a unique problem overall, and it only occurs in the process of actually writing a cookie for the first time. Or removing it if it exists which is kind of like writing it.
Anyway I have 2 functions that worked perfectly up til the point of introducing the cookies to them. But I need the cookies also as its part of a login check, and a handful of other things. So this is my issue.
I type my user/pass, hit login. get nothing. hit login again, works.
I hit logout after being logged in, nothing works. hit it again.. works..
These are ajax driven functions as well. Dunno if that has anything to do with it or not, but in both cases cookies are being written in one shape form or another and thats when the functions seem to break in respect to the fact that I need to click the buttons that trigger them twice to get the desired effect despite them being a single click action.
If I remove the cookie lines from my functions everything works normally again without problem, with exception that the cookies are required to actually use half the stuff I am building. Also its a lone cookie being written with a numeric value.
Ideas?
AppMobi.cache.setCookie('AutoRemember', uid, 90);
This one line if its there, i have to double click for my functions to work, if its not there my functions work as expected..
a sample of one of my function would be (quickly typing one out here for example sake)
$('#buttonX').click(function(){
url = 'http://www.domain.com';
$.post(url, function(data)
{
if(data.status == "good")
{
AppMobi.cache.setCookie('AutoRemember', uid, 90);
window.location = 'dashboard.html';
}
}, 'json')
});
Ah yes, I ran into the same thing. You'll need to download and init the local_bootstrap.js lib and something from "Develop In Eclipse For Android " (I downloaded the .zip "appMobi Cloud Services library for PhoneGap Android development"). I'm doing the Android app with Eclipse, and I assume you are too, your post didn't mention what IDE you were using.
The .zip file has a great readme.txt on where & what to copy (.java files, jar file, etc.)
found here: http://www.appmobi.com/?q=node/85
Well, come to find out or as far as I can figure at least. This appears to be a glitch between browser and emulator more so than it is my coding. When I run the app in the sandboxed appMobi application from "Test Anywhere" things work as expected all around.
I will be opening up a bug ticked on appMobi where every they take bug reports and I will come back here with a link later so others may follow it as well when and if they come across a similar issue.

Categories

Resources