Skip to content

Instantly share code, notes, and snippets.

View sahajamit's full-sized avatar

Amit Rawat sahajamit

View GitHub Profile
@Test
public void doWebNotificationTesting() throws Exception {
driver = utils.launchBrowser();
driver.navigate().to("https://pushjs.org/#");
UINotificationService uiNotificationService = UINotificationService.getInstance(driver);
uiNotificationService.startWebNotificationListener();
driver.findElement(By.id("demo_button")).click();
utils.waitFor(2);
Map<String,String> notificationFilter = new HashMap<>();
package com.sahajamit.utils;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.ArrayList;
import java.util.Map;
import java.util.concurrent.atomic.AtomicBoolean;
// To Stop Listening to all Web Push Notifications
clearInterval(window.notificationListener);
window.notificationsMap = Object.create(null);
window.notifications = [] ;
// To Collect all the notifications arrived till now
function getCollectedNotifications(){
window.notifications = [] ;
var count = 0;
for (var prop in window.notificationsMap)
count++; window.notifications.push(window.notificationsMap[prop]);
}
console.log("Total notifications count is: " + count);
return window.notifications;
};
// To Start Listening to all Web Push Notifications
window.notificationsMap = Object.create(null);
async function getServiceWorkerRegistration(){
window.myServiceWorkerRegistration = await navigator.serviceWorker.getRegistration("https://framework.realtime.co/demo/web-push/");
return window.myServiceWorkerRegistration;
};
async function getNotifications() {
window.myNotifications = await window.myServiceWorkerRegistration.getNotifications();
};
window.notifications = [];
window.Notification = window.DefaultNotification;
// To Start Listening to all the Web Notifications
window.notifications = [];
window.DefaultNotification = window.Notification;
(function () {
function notificationCallback(title, opt) {
console.log("notification title: ", title);
console.log("notification body: ", opt.body);
console.log("notification tag: ", opt.tag);
console.log("notification icon: ", opt.icon);
}
@sahajamit
sahajamit / intercept_web_notification.js
Last active August 28, 2019 14:41
Code to listen to Web Push Notifications
//inject before starting the notification testing
window.notifications = [];
window.DefaultNotification = window.Notification;
(function () {
function notificationCallback(title, opt) {
console.log("notification title: ", title);
console.log("notification body: ", opt.body);
console.log("notification tag: ", opt.tag);
console.log("notification icon: ", opt.icon);
}
@sahajamit
sahajamit / patch_configmap.sh
Created August 13, 2019 04:34 — forked from mwinters0/patch_configmap.sh
Patch / update a configmap from inside Kubernetes using curl
KUBE_TOKEN=$(</var/run/secrets/kubernetes.io/serviceaccount/token)
NAMESPACE=myapp-dev
CONFIGMAP_NAME=testconfig
curl -sSk \
-X PATCH \
-d @- \
-H "Authorization: Bearer $KUBE_TOKEN" \
-H 'Accept: application/json' \
-H'Content-Type: application/strategic-merge-patch+json' \
https://$KUBERNETES_SERVICE_HOST:$KUBERNETES_PORT_443_TCP_PORT/api/v1/namespaces/$NAMESPACE/configmaps/$CONFIGMAP_NAME <<'EOF'
https://stackoverflow.com/questions/41789470/files-write-appending-new-lines-in-a-text-file
Files.write(Paths.get(filePath), (columnHeaders + System.lineSeparator()).getBytes(UTF_8), StandardOpenOption.CREATE,StandardOpenOption.APPEND);