How to close the current tab of the browser in protractor with out closing the complete browser - protractor

In the application i have two options "Google , Twitter" . When i click on any option it will open in new tab.
In my test case , i would like to click on google or twitter option and close the google or twitter tab and return back to the my application.
Is there any way to close only newly opened tab.
I tried below solutions.
browser.close(); is closing the entire browser.
Can any one help me how to close only tab of the browser ( in my case google tab or twitter tab) with out closing the entire browser in protractor

You can try the following:
Switch to the new opened tab. Close the current windows (in this case, the new tab). Switch back to the first window.
browser.getAllWindowHandles().then((handles) => {
browser.driver.switchTo().window(handles[1]);
browser.driver.close();
browser.driver.switchTo().window(handles[0]);
});

This is how I used it in one project.
const allWindowHandlers = await browser.getAllWindowHandles();
if (allWindowHandlers.length > 1) {
for (let windowHandlerIndex = 1; windowHandlerIndex < allWindowHandlers.length; windowHandlerIndex++) {
const windowHandler = allWindowHandlers[windowHandlerIndex];
await browser.switchTo().window(windowHandler);
await browser.close();
}
}
await browser.switchTo().window(allWindowHandlers[0]);
You can use it inside your steps implementation.
You can use it before starting a new scenario, to be sure that only the first window is selected and everything else is closed.

I did and this and it works for me :
browser.getAllWindowHandles().then(function(handles) {
let newWindowHandle = handles[1]; // this is your new window
browser.switchTo().window(newWindowHandle).then(function() {
browser.close();
browser.switchTo().window(handles[0]);
});
});

Related

is there a way to check if the PWA was launched through a file or not?

I'm using the file handle API to give my web app the optional capability to launch through double-clicking files in the file explorer.
Writing the code below, I expected if (!("files" in LaunchParams.prototype)) to check if a file was used to launch the app, but apparently, it checks if the feature is supported. OK, that makes sense.
After that, I thought the setConsumer callback would be called in any launch scenario, and files.length would be zero if the app was launched in other ways (like by typing the URL in the browser). But on those use cases, the callback was not called at all, and my init logic was never executed.
if (!("launchQueue" in window)) return textRecord.open('a welcome text');
if (!("files" in LaunchParams.prototype)) return textRecord.open('a welcome text');
launchQueue.setConsumer((launchParams) => {
if (launchParams.files.length <= 0) return textRecord.open('a welcome text');
const fileHandle = launchParams.files[0];
textRecord.open(fileHandle);
});
I've also followed the Launch Handler API article instructions and enabled the experimental API.
The new code confirms that "targetURL" in LaunchParams.prototype is true, but the setConsumer callback is not executed if the user accesses the web app through a standard browser tab.
function updateIfLaunchedByFile(textRecord) {
if (!("launchQueue" in window)) return;
if (!("files" in LaunchParams.prototype)) return;
console.log({
'"targetURL" in LaunchParams': "targetURL" in LaunchParams.prototype,
});
// this is always undefined
console.log({ "LaunchParams.targetURL": LaunchParams.targetURL });
// setConsumer does not trigger if the app is not launched by file, so it is not a good place to branch what to do in every launch situation
launchQueue.setConsumer((launchParams) => {
// this never run in a normal tab
console.log({ setConsumer: launchParams });
if (launchParams.files.length <= 0) return;
const fileHandle = launchParams.files[0];
textRecord.open(fileHandle);
});
}
This is the result...
Is there a universal way to check if the web app was launched through a file?
Check out the Launch Handler origin trial. It lets you determine the launch behavior exactly and lets your app detect how the launch happened. This API works well together with the File Handling API that you already use. You could, for example, check the LaunchParams.targetURL to see how the app was launched. Your feedback is very welcome.
Since I was not able to guarantee that the setConsumer callback was called in every situation (especially when the app is launched in a regular browser tab), I hacked it through setTimeout:
function wasFileLaunched() {
if (!("launchQueue" in window)) return;
if (!("files" in LaunchParams.prototype)) return;
return new Promise((resolve) => {
let invoked = false;
// setConsumer does not triggers if the app is not launched by file, so it is not a good place to branch what to do in every launch situation
launchQueue.setConsumer((launchParams) => {
invoked = true;
if (launchParams.files.length <= 0) return resolve();
const fileHandle = launchParams.files[0];
resolve(fileHandle);
});
setTimeout(() => {
console.log({ "setTimeout invoked =": invoked });
if (!invoked) resolve();
}, 10);
});
}

Opening a new window in MAUI

In WPF the below code opens a new window.
Window abc = new Window();
abc.Show();
But for MAUI window, I cant find the show option. How to open a window in MAUI?
var secondWindow = new Window {
Page = new MySecondPage {
// ...
}
};
Application.Current.OpenWindow(secondWindow);
https://devblogs.microsoft.com/dotnet/announcing-dotnet-maui-preview-11/
Try;
Navigation.PushAsync(new MainPage());
Try this,
await Shell.Current.GoToAsync("///MainPage");

cannot react to close tab event with cloudfare app

I am using the app creator and trying to react to close tab window event using the code below.
I then preview the app in a separate window, but when I close the tab I don't get the confirmation pop up.
When I inject this code in the js console it works as expected.
Doesn't cloudfare app support such functionality?
window.onbeforeunload = function (e) {
// Your logic to prepare for 'Stay on this Page' goes here
return "Please click 'Stay on this Page' and we will give you candy";
};
I tested this and was able to see the pop up when after clicking to close the tab. Are you certain that this assignment is happening? In the previewed window, what is the output of window.onbeforeunload?
You also need to make sure to set the returnValueof e to something other than null e.g. :
function sendAlert() {
window.onbeforeunload = (e) => {
const dialogText = 'Random Text';
e.returnValue = dialogText;
return dialogText; }
}

How to Download Facebook Look back Video?

What should Do, If I want to download Facebook Lookback Video
Reference
Simple JS Script to get Video URL from Facebook's Look Back
Copy paste this whole code into Chrome Console and press enter.
You can execure this script on any page on Facebook.
It will give you the video URL, open it, view it, download it, do whatever you want to. :P
The video URL will popup in front of you, press Ctrl + C to copy it.
To do so, open Chrome Console, Ctrl + Shift + J, "Console" tab.
Copy paste the whole thing there.
To share it, just open the link and download it by pressing Ctrl + S.
Upload it to YouTube or wherever you want to. Share, enjoy! :)
Keep Sharing this with everyone! :)
var xmlhttp;
if (window.XMLHttpRequest) {
xmlhttp = new XMLHttpRequest();
} else {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
ss = xmlhttp.responseText.split('[["params","')[1].split('"],["width","960"]')[0];
var x = ss;
var r = /\\u([\d\w]{4})/gi;
x = x.replace(r, function (match, grp) {return String.fromCharCode(parseInt(grp, 16)); });
x = unescape(x);
console.log(JSON.parse(x).video_data[0].hd_src);
prompt("Here's your video URL (HD)! Press Ctrl + C to copy it!", JSON.parse(x).video_data[0].hd_src)
}
}
xmlhttp.open("GET", "/lookback", true);
xmlhttp.send();
You can also get the SD and HD sources directly from the flashvars of the embed used to display the video. In Google Chrome inspect the page for the "content" div you'll find a div with class "swfObject".
Decoding the flasvar, you'll get something similar to:
params={
"autoplay":true,
"autorewind":true,
"default_hd":false,
"dtsg":"AQAAJp6S",
"inline_player":false,
"lsd":null,
"min_progress_update":300,
"pixel_ratio":1,
"preload":false,
"source":"lookback",
"start_index":0,
"start_muted":false,
"use_spotlight":false,
"video_data":[
{
"hd_src":"https:\/\/lookbackvideo7-a.akamaihd.net\/hvideo-ak-ash2\/v\/t55\/1774977_10104243234253383320144_17978_n.mp4?oh=7d70ce01b4c6dff2345d48e6e938a9df65f&oe=52F59B08&__gda__=1391855368_9ae234b1cce92effd53d05cdfb6e884f323",
"is_hds":false,"index":0,"rotation":0,
"sd_src":"https:\/\/lookbackvideo7-a.akamaihd.net\/hvideo-ak-ash2\/v\/t54\/1785524_101045234234383320144_19170_n.mp4?oh=1116ee0f06e59c4180648234bac62a148ea&oe=52F5A983&__gda__=1391848771_03b13324ffa3791cc64e0d070465107c7c8",
"thumbnail_src":"https:\/\/fbcdn-vthumb-a.akamaihd.net\/hvthumb-ak-prn1\/t15\/1542287_101045533833922349984_10104553383320144_60544_503_b.jpg",
"thumbnail_height":540,"thumbnail_width":960,
"video_duration":62,
"video_id":"101045523423383320144"
}]}
The two important values here are hd_src and sd_src (i've garbled mine for security purposes):
"hd_src":"https:\/\/lookbackvideo7-a.akamaihd.net\/hvideo-ak-ash2\/v\/t55\/1774977_10104553382342320144_17978_n.mp4?oh=7d70ce01b4c6dff5d48e6e938234a9df65f&oe=52F59B08&__gda__=1391855368234_9aeb1cce92effd53d05cdfb6e884f323",
"sd_src":"https:\/\/lookbackvideo7-a.akamaihd.net\/hvideo-ak-ash2\/v\/t54\/1785524_101045532342343320144_19170_n.mp4?oh=1116ee0f06e59c4180623424448bac62a148ea&oe=52F5A983&__gda__=139184232428771_03b13ffa3791cc64e0d070465107c7c8",
Load your desired quality (High Definition or Standard Definition) URL into a new browser window, right click on the video and "Save Video As."
www.fundawn.com is the best web place where people can download and watch public videos and photos of top facebook celebrities and others, all in one place.
Just check it.

webworks blackberry 10 window.open twitter facebook

i am just trying to implement facebook and twitter in my Webworks App and cannot get them work together.
I am using the FaceBook-OAuth-2 and the Twitter-OAuth-1 sample and i just put both stuff together and my problem is that only the first startOAuth() opens a window in the app to login the second doesn't so if i first clicked facebook it works after when i try twitter nothing happens.
https://github.com/blackberry/BB10-WebWorks-Samples
thanks
function setClickHandlers() {
console.log('set click handlers');
var fb = document.getElementById('facebookOn');
fb.addEventListener('click', function(e) {
// if the childWindow is already open, don't allow user to click the button
if(childWindow !== null) {
return false;
}
e.preventDefault();
toast('Contacting Facebook...');
setTimeout(function() {
startOAuth();
}, 500);
});
console.log('set twitter click handlers');
var tw = document.getElementById('twitterOn');
tw.addEventListener('click', function(e) {
// if the childWindow is already open, don't allow user to click the button
if(childWindow !== null) {
return false;
}
e.preventDefault();
toast('Fetching access token...');
setTimeout(function() {
twittergetAccessToken();
}, 500);
});
}
I would start by adding some debug code in your click handler to see if that's getting called when you click the button in the first place.
If it is, then I recommended you use Web Inspector (console) to see if there are any errors. If there are, they'll show up there.
Good reference for Web Inspector here - http://developer.blackberry.com/html5/documentation/web_inspector_overview_1553586_11.html
If the click handler is not being fired then perhaps you have the wrong element ID, or the setClickHandlers function is not being executed.