How can I make my browser to go on a site every X seconds? - tampermonkey

So, I simply need a script for Tampermonkey to go to a specific site every x seconds on the same tab no matter what website or addon is open in the browser.
// ==UserScript==
// #name arga
// #description arga
// #include *
// ==/UserScript==
function view() {
setTimeout(function() {
window.location.replace("https://www.google.com/");
}, 250000);
};
I expect that this script goes to google.com every 250 seconds, no matter what extension page or website is opend but it doesn't.

Per Brock Adam's comment:
// ==UserScript==
// #name arga
// #description arga
// ==/UserScript==
setTimeout(function() {
window.location.replace(“https://www.google.com/“);
}, 250000);
Your script defines a function, but doesn't call it.
To call the function you defined, you would do this:
(function view () {
// your code here
})();
Which is effectively the same as:
function view () {
// your code here
}
view();

Related

Use protractor on an non angular page

in my recent test I need to first login and take some actions on an non angular page (https://www.qa.dealertrack.com/default1.aspx)
then switch to an angular page and finish the test.
In conf I have
global.driver = browser.driver;
My page object looks like:
var LogInPage = function() {
this.loginUrl = 'https://www.qa.dealertrack.com/default1.aspx';
this.id = browser.driver.findElement(by.name('username'));
this.password = browser.driver.findElement(by.name('password'));
this.loginButton = browser.driver.findElement(by.name('login'));
this.logIn = function(id, password) {
// maximize window
driver.manage().window().maximize();
// log in
driver.get('https://www.qa.dealertrack.com/default1.aspx');
this.id.sendKeys(id);
this.password.sendKeys(password);
this.loginButton.click();
}
};
My test looks like:
describe('Sample Test - Log In', function() {
var loginPage = require('../pages/LogInPage.js');
/**
* Disable waiting for AngularJS for none Angular page
*/
beforeEach(function() {
isAngularSite(false);
});
it('logging in', function() {
loginPage.logIn('xxx', 'xxx');
})
})
However, even before getting to the site, protractor throws error NoSuchElementError: no such element: Unable to locate element:{'method':'name','selector':'username'}
But when I commented out all the element variables and related lines, only left
driver.get(this/loginUrl);
It worked. Why would browser.driver.get works but browser.driver.findElement does not?
This is my first question on Stackoverflow. Thank everyone!!
Before login you need to set
browser.driver.ignoreSynchronization=true;
So it shold be like
browser.driver.ignoreSynchronization=true;
login();
browser.driver.ignoreSynchronization=false;
I tried to removed all the elements I declared outside my functions in page object. Instead of that, I just hard code the elements in the function. And it worked.

Reload angular-translate-static-loader-files within app, without refresh in Ionic

I'm working on this Ionic app and I'm using angular-translate-loader-static-files with angular-translate to load in a bunch of language .json files.
Everything is working fine, but I'm trying to figure out how to basically "re-run the $translateProvider" so it can reload all the static files all over again as the .json files will get updated from the server periodically. I have yet to figure this out, and even trying to force a "page reload" doesn't cause the static files to reload.
I should note that I'm currently testing this in iOS and I realize that the directory structure will change, based on OS.
Here is my service that utilizes $cordovaFile to overwrite the file with new text. Right now I'm just using a simple json string to make sure I can solve the problem:
(function() {
'use-strict';
angular.module('coursemill.services')
.service('Translations', Translations);
/**
* Service: Check network connection
*/
function Translations($cordovaFile) {
function updateLanguageFile(lang) {
document.addEventListener("deviceready", function() {
$cordovaFile.checkFile(cordova.file.applicationDirectory + "/www/languages/", lang + ".json")
.then(function (success) {
// Update the language file
$cordovaFile.writeFile(cordova.file.applicationDirectory + "/www/languages/", lang + ".json", '{"COURSES_MENU_REQUIRED": "Required"}', true)
.then(function (success) {
// TO-DO: reload translation files
},
function (error) {});
},
function (error) {});
});
}
return {
updateLanguageFile: updateLanguageFile
}
}
})();
Here is a snippet from my .config:
// Setup the language translations
$translateProvider.useStaticFilesLoader({
prefix: 'languages/',
suffix: '.json'
});
Here is a snippet from my controller:
Translations.updateLanguageFile('en_US');
When I open the file up after this function has been run, the contents of the file are replaced and are doing exactly what I want, but I'd like my language variables inside the app to be updated as well, and they aren't.
Any thoughts on what can be done here?
Doink, I needed to use $translate.refresh() in my service function. So now it looks like this:
(function() {
'use-strict';
angular.module('coursemill.services')
.service('Translations', Translations);
function Translations($cordovaFile, $translate) {
function updateLanguageFile(lang) {
document.addEventListener("deviceready", function() {
$cordovaFile.checkFile(cordova.file.applicationDirectory + "/www/languages/", lang + ".json")
.then(function (success) {
// Update the language file
$cordovaFile.writeFile(cordova.file.applicationDirectory + "/www/languages/", lang + ".json", '{"COURSES_MENU_REQUIRED": "Required"}', true)
.then(function (success) {
// Reload translation files
$translate.refresh();
},
function (error) {});
},
function (error) {});
});
}
return {
updateLanguageFile: updateLanguageFile
}
}
})();

Error while waiting for Protractor to sync with the page: "window.angular is undefined

I've just started to use Protractor. I created several page objects and everything is working fine till now. I log in to a page and I'm being redirected to the myaccount page.
On that page, I got the following error:
Error while waiting for Protractor to sync with the page: "window.angular is undefined.
My code is here:
var myaccount = function(){
//some function but everything is commented out
};
module.exports = new myaccount();
Here is my login test as well:
this.loginSuccess = function(){
userName.sendKeys(params.registration.email);
password.sendKeys(params.registration.password);
submitButton.click();
};
After the click, myaccount page appears but the protractor throws the mentioned error.
Could somebody help me with this?
window.angular is undefined means you are trying to make protractor go to a page that is not angular
See the answer from mcalthrop here: https://github.com/angular/protractor/issues/610
Can use like
var newpage = new RegExp('welcome', 'i');
submitButton.click();
waitForUrlToChangeTo(newpage).then(function () {
expect(browser.getTitle()).toEqual('Welcome!');
});
/**
* #name waitForUrlToChangeTo
* #description Wait until the URL changes to match a provided regex
* #param {RegExp} urlRegex wait until the URL changes to match this regex
* #returns {!webdriver.promise.Promise} Promise
*/
function waitForUrlToChangeTo(urlRegex) {
var currentUrl;
return browser.getCurrentUrl().then(function storeCurrentUrl(url) {
currentUrl = url;
}
).then(function waitForUrlToChangeTo() {
return browser.wait(function waitForUrlToChangeTo() {
return browser.getCurrentUrl().then(function compareCurrentUrl(url) {
return urlRegex.test(url);
});
});
}
);
}

How to say protractor to wait till page loads?

My application taking some to page the login page.So protractor trying to enter the user name before page loads.So i need to say protractor to wait till the login page loads.
Could you please help me what command I need to use for this and where I need to use?(Please modify my code to add the wait command)
PFB for my onPrepare and beforeeach function
onPrepare: function() {
browser.driver.manage().window().maximize();
jasmine.getEnv().addReporter(new HtmlReporter({
})
}
beforeEach(function() {
browser.get('https://accounts.google.com/');
//browser.manage().timeouts().pageLoadTimeout(30000);
//browser.manage().timeouts().implicitlyWait(5000);
//browser.sleep( 10000 );
//browser.waitForAngular();
});
I used those commented functions,but it didn't work for me.
Please guide me.thanks in advance.
Assuming you want to click the Get Started button, wait for the button to become clickable:
var EC = protractor.ExpectedConditions;
var getStarted = element(by.css('button[title="Get started"]'));
browser.wait(EC.elementToBeClickable(getStarted), 5000);
getStarted.click();
Use the wait command: browser.driver.wait(condition, timeout);
onPrepare: function() {
browser.driver.manage().window().maximize();
jasmine.getEnv().addReporter(new HtmlReporter({
});
}
beforeEach(function() {
browser.driver.get('https://accounts.google.com/');
return browser.driver.wait(function() {
return browser.driver.getCurrentUrl().then(function (url) {
return url.indexOf('https://accounts.google.com/') > -1;
});
}, 5000);
//whatever you want after
});
you can wait for any condition like that.
Also, google f.e is not an angular page, so you should use:
browser.driver.get instead of protractors browser.get,
or it will wait for angular on the page.

Parse.initialize breaking Angular Cordova app in iOS simulation

So I have an app in angular with cordova, that works as expected when served to a local web host, pushing and pulling the login data from parse.com.
But, when I compile and emulate in an IOS emulator, it appears that the command
parse.initialize("453ioejblahgf3oi5j35p","f30903959fblahblah");
is making $state.go fail to work.
:(
Upon closer inspection, it seems as though Parse.initialize("faerfaerfaerf";"aefaerfeafaer"); is putting a stop to all code that comes after it --
$scope.registerNowClick = function (user) {
//Copy the user to $scope.tmpUser
$scope.tmpUser = angular.copy(user);
// PARSE INITILIZATION CALL Parse.initialize("Zmqvefjaeifai34jofewOvRDxfNdoxH", "HlzTePUSi3fja305f0j341");
alert('Register Now was clicked w/ Email:' + $scope.tmpUser.email);
// PARSE ADD A USER
var user = new Parse.User();
user.se blah blah
If I move the alert above the parse.init, it fires. But when it's after the parse.init, it doesn't.
Javascript is interpreted language. Meaning that, any run-time errors wont halt the program, until that particular line is reached.
Looking at your problem, it looks like Object Parse is not defined. Have you included any parse.js files that it may require? Move Parse.initialize() to the end of the script so that it wont halt the rest of the code from executing.
I have put my Parse initialization in a separate UserService.init() that must be resolved at app startup.
.state('tab', {
url: "/tab",
abstract: true,
templateUrl: "templates/tabs.html",
resolve: {
user: function (UserService) {
var value = UserService.init();
// alert(value); // for debugging
return value;
}
}
})
Here is a snippet of the UserService code
init: function () {
var value = null;
var deferred = $q.defer();
// if initialized, then return the activeUser
if (parseInitialized === false) {
Parse.initialize(ParseConfiguration.applicationId, ParseConfiguration.javascriptKey);
parseInitialized = true;
console.log("parse initialized in init function");
}
setTimeout(function () {
var currentUser = Parse.User.current();
if (currentUser) {
deferred.resolve(currentUser);
} else {
deferred.reject({error: "noUser"});
}
}, 100);
return deferred.promise;
},
The complete solution is here ... https://github.com/aaronksaunders/dcww

Resources