Button could not be tapped - UIAutomation - javascript

I am attempting to create script that will automate sign in process (to login). However, when I run script it says that 'could not be tapped'. Below is what I have written so far:
var target = UIATarget.localTarget();
var app = target.frontMostApp();
var appWindow = app.mainWindow();
var settingsButton = appWindow.buttons()["CloseVector"];
var settingsView = app.mainWindow().staticTexts()["Settings"]
UIALogger.logStart("Sign in test")
settingsButton.tap();
target.delay(1);
if (settingsView.isValid())
{
UIALogger.logPass("Correct View");
}
else
{
UIALogger.logFail("Wrong View");
}

Related

How to inject content script from background

I am trying to inject my content script (stored in localhost) instead of having to use the manifest.
background.js:
chrome.browserAction.onClicked.addListener(function (event) {
show_floater = !show_floater;
// so that there is no need of adding it in the manifest
chrome.tabs.executeScript(null, {
// file: 'js/content_t.js', /* my content script */ }, () => {
file: 'https://127.0.0.1/js/test1.js', /* my content script */}, () => {
connect(show_floater) //this is where I call my function to establish a connection
});
});
});
As you can see above there is a part of code commented out. That is how I used to do it. I used to inject a js file and from there inject the file in the localhost in the DOM.
But thinking about it there should be a way to decrease the file number to 2 instead of 3 right?
I tried simply changing the file that I was injecting from the background script but it does not seem to work... (I put a console.log in the file to be injected and I see nothing).
The reason for the need of the file to be stored on a server is so that I can change the code of the extension without having to push for updates on the user side. I just change it in the server and next time a user uses it it has the most current version injected.
The function connect sends a message to the active tab
function connect(sf) {
chrome.tabs.query({ active: true, currentWindow: true }, (tabs) => {
const port = chrome.tabs.connect(tabs[0].id);
let msg = {show_floater: sf};
port.postMessage(JSON.stringify(msg));
});
}
I'm new to all of this
this is what i have in my contents script:
content.js:
console.log('hello');
chrome.runtime.onConnect.addListener(function (port) {
port.onMessage.addListener(function (msg) {
msg = JSON.parse(msg);
if (!injected) {
injected = true;
let link = document.createElement('link');
document.querySelector('head').appendChild(link);
link.className = 'beebole_css';
link.href = 'https://127.0.0.1/css/test.css';
link.type = 'text/css';
link.rel = 'stylesheet';
$$beebole_button$.insert_DOM_button();
$$beebole_button$.add_button_functionality();
// let s = document.createElement('script');
// document.querySelector('body').appendChild(s);
// s.className = 'beebole_js';
// s.src = 'https://127.0.0.1/js/test.js';
// s.type = 'text/javascript';
}
});
});
Again, the commented out part is what I used to do. I simply used to inject the file from localhost as a script.
Now what I do is simply calling functions to add to the DOM what I need.
this might be overkill but here are the functions:
$$beebole_button$.insert_DOM_button = function () {
// Main divs
let div_container = document.createElement('div');
let div_button = document.createElement('div');
let div_form = document.createElement('div');
// User input
let txt_field = document.createElement('textarea');
let submuit_comment_button = document.createElement('button');
let select_project = document.createElement('input');
// SVGs
let beebole_svg = document.createElement('div');
let mag_glass_svg = document.createElement('div');
div_button.className = 'beebole_menu1';
beebole_svg.className = 'beebole_logo';
div_button.append(beebole_svg);
select_project.className = 'beebole_select_project beebole_text_input';
select_project.placeholder = 'Select project...';
mag_glass_svg.className = 'beebole_mag_glass';
select_project.appendChild(mag_glass_svg);
div_form.appendChild(select_project);
// txt_field.type = 'text';
txt_field.className = 'beebole_comment beebole_text_input';
// txt_field.rows = '5';
txt_field.placeholder = window.$$beebole_button$.autoComment() || 'Enter comment here...';
div_form.appendChild(txt_field);
submuit_comment_button.type = 'button';
submuit_comment_button.className = 'beebole_submuit_comment beebole_button';
submuit_comment_button.innerHTML = 'submuit';
div_form.appendChild(submuit_comment_button);
div_form.className = 'beebole_form hidden';
div_container.className = 'beebole beebole_default_position';
div_container.setAttribute('tabIndex', '1');
div_container.appendChild(div_button);
div_container.appendChild(div_form);
document.body.appendChild(div_container);
};
$$beebole_button$.add_button_functionality() is just what it says -> logic for the button drag, move, etc.

Protractor can't find gmail input with id of password

I'm trying to set up Protractor for testing my application but it requires auth through gmail, and I'm stuck on trying to login:
describe('Vivace Home page', function() {
var hasClass = function (element, cls) {
return element.getAttribute('class').then(function (classes) {
return classes.split(' ').indexOf(cls) !== -1;
});
};
beforeEach(function() {
browser.ignoreSynchronization = true;
browser.get('/');
var emailInput = browser.driver.findElement(by.id('Email'));
emailInput.sendKeys('paulG#gmail.com')
var nextButton = browser.driver.findElement(by.id('next'));
nextButton.click().then(function() {
browser.pause();
var passwordInput = browser.driver.findElement(by.id('Passwd'));
console.log(passwordInput);
passwordInput.sendKeys('11111');
// var signInButton = browser.driver.findElement(by.id('signIn'));
})
});
it('should have the correct title', function() {
expect(browser.getTitle()).toEqual('InRhythm - Vivace');
});
});
I can see Protractor opening up the gmail page, inputting the email and clicking the next button, and when I do browser.pause I can actually see the password input with an id of "Passwd" right there on the page with inspector and yet I can't access it to complete my log in.
I get this error when I remove the browser.pause
Failed: no such element: Unable to locate element: {"method":"id","selector":"Passwd"}
Wait for it to become visible:
var EC = protractor.ExpectedConditions;
var passwordInput = element(by.id('Passwd'));
browser.wait(EC.visibilityOf(passwordInput), 5000);
passwordInput.sendKeys('11111');

Windows Store Javascript background audio tassk close() method?

I have created a simple Windows 8.1 store app for just playing internet streaming radio. It looks and works good, but I can't upload my app to Windows Store! After validation a get the message like:
WinJS background task
Error Found:
The WinJS background tasks test encountered the
following errors:
App Radio Skovoroda did not call close() in the
background task JavaScript code found in file default.html.
Impact if not fixed: Apps with background tasks that do not call close() can result in draining the battery.
How to fix: Update the background
task to call close().
The point is I do not need to call close(), because it is a radio player, so, it must play in background for a long time! Any ideas? How to do my app pass the validator?
My script code:
(function () {
"use strict";
var app = WinJS.Application;
var activation = Windows.ApplicationModel.Activation;
app.onactivated = function (args) {
if (args.detail.kind === activation.ActivationKind.launch) {
if (args.detail.previousExecutionState !== activation.ApplicationExecutionState.terminated) {
// TODO: This application has been newly launched. Initialize
// your application here.
} else {
// TODO: This application was suspended and then terminated.
// To create a smooth user experience, restore application state here so that it looks like the app never stopped running.
}
args.setPromise(WinJS.UI.processAll());
var buttonMediaControl = document.getElementById("mediaControlButton");
buttonMediaControl.addEventListener("click", playAndStop, false);
//add variables for social buttons
//Facebook
var fbButton = document.getElementById("fbButton");
fbButton.addEventListener("click", goToFbPage, false);
//VKotakte
var vkButton = document.getElementById("vkButton");
vkButton.addEventListener("click", goToVkPage, false);
//Twitter
var twButton = document.getElementById("twButton");
twButton.addEventListener("click", goToTwPage, false);
//Instagram
var igButton = document.getElementById("igButton");
igButton.addEventListener("click", goToIgPage, false);
//YouTube
var ytButton = document.getElementById("ytButton");
ytButton.addEventListener("click", goToYtPage, false);
//TuneIn
var tiButton = document.getElementById("tiButton");
tiButton.addEventListener("click", goToTiPage, false)
// Assign the button object to MediaControls
var systemMediaControls = Windows.Media.SystemMediaTransportControls.getForCurrentView();
systemMediaControls.addEventListener("buttonpressed", systemMediaControlsButtonPressed, false);
systemMediaControls.isPlayEnabled = true;
systemMediaControls.isPauseEnabled = true;
systemMediaControls.isStopEnabled = true;
systemMediaControls.playbackStatus = Windows.Media.MediaPlaybackStatus.closed;
}
};
app.oncheckpoint = function (args) {
};
// Plays the media.
function playMedia() {
var media = document.getElementById("skovorodaStreamingAudio");
media.play();
var statusIcon = document.getElementById("playStopImage");
statusIcon.src = "images/skovoroda_stop_button.png";
var systemMediaControls = Windows.Media.SystemMediaTransportControls.getForCurrentView();
systemMediaControls.playbackStatus = Windows.Media.MediaPlaybackStatus.playing;
}
// Pauses the media.
function pauseMedia() {
var media = document.getElementById("skovorodaStreamingAudio");
media.pause();
var statusIcon = document.getElementById("playStopImage");
statusIcon.src = "images/skovoroda_play_button.png";
var systemMediaControls = Windows.Media.SystemMediaTransportControls.getForCurrentView();
systemMediaControls.playbackStatus = Windows.Media.MediaPlaybackStatus.paused;
}
// Stops the media.
function stopMedia() {
var media = document.getElementById("skovorodaStreamingAudio");
media.pause();
media.currentTime = 0;
}
function playAndStop() {
var myAudio = document.getElementById("skovorodaStreamingAudio");
var statusIcon = document.getElementById("playStopImage");
if (myAudio.paused) {
var systemMediaControls = Windows.Media.SystemMediaTransportControls.getForCurrentView();
systemMediaControls.playbackStatus = Windows.Media.MediaPlaybackStatus.playing;
myAudio.play();
statusIcon.src = "images/skovoroda_stop_button.png";
} else {
var systemMediaControls = Windows.Media.SystemMediaTransportControls.getForCurrentView();
systemMediaControls.playbackStatus = Windows.Media.MediaPlaybackStatus.paused;
myAudio.pause();
statusIcon.src = "images/skovoroda_play_button.png";
}
}
// The media Play event handler.
function mediaPlaying() {
// Update the SystemMediaTransportControl state.
systemMediaControls.playbackStatus = Windows.Media.MediaPlaybackStatus.playing;
}
// The media Pause event handler.
function mediaPaused() {
// Update the SystemMediaTransportControl state.
systemMediaControls.playbackStatus = Windows.Media.MediaPlaybackStatus.paused;
}
// The media Ended event handler.
function mediaEnded() {
// Update the SystemMediaTransportControl state.
systemMediaControls.playbackStatus = Windows.Media.MediaPlaybackStatus.stopped;
}
function goToFbPage() {
window.open("https://www.facebook.com/radioskovoroda?__mref=message_bubble");
}
function goToVkPage() {
window.open("https://vk.com/radioskovoroda");
}
function goToTwPage() {
window.open("https://twitter.com/RadioSkovoroda");
}
function goToIgPage() {
window.open("https://instagram.com/radioskovoroda");
}
function goToYtPage() {
window.open("https://www.youtube.com/channel/UCSgkIdg5MztN_2z9q_8u3Nw")
}
function goToTiPage() {
window.open("http://tunein.com/radio/radio-skovoroda-s248591/")
}
// Event handler for SystemMediaTransportControls' buttonpressed event
function systemMediaControlsButtonPressed() {
if (Windows.Media.MediaControl.isPlaying === true) {
pauseMedia();
} else {
playMedia();
}
}
app.start();
})();

Selenium WebdriverJS, how to use PageFactory?

I am currently trying to start writing my tests using TypeScript(solution in JavaScript is also fine) and I am having a hard time understanding how to use the PageFactory from C#.
In C# I used to write separate classes for every page/form of the website that I am testing, for example:
public class RegisterForm
{
public RegisterForm()
{
PageFactory.InitElements(Driver.Chrome, this);
}
[FindsBy(How = How.CssSelector, Using = #"........")]
public IWebElement EmailField { get; set; }
}
And whenever I needed to use elements from the RegisterForm I was initializing this class and using them from here. How can I do something like this in TypeScript or in JavaScript?
An example of how I created my page objects using protractor on a non-angular page is below
'use strict';
var DocumentationPage = function () {
var documentationLink = element(by.css(".nav-global a[href*='Docs'"));
var documentationURL = "https://docs.docker.com/"
var installButton = element(by.buttonText("Install"));
var dockerEngineButton = element(by.buttonText("Docker Engine"));
var dockerLinuxButton = element(by.buttonText("Linux"));
var dockerCloudButton = element(by.buttonText("Cloud"));
var dockerFundamentalsButton = element(by.buttonText("Docker Fundamentals"));
var useDockerButton = element(by.buttonText("Use Docker"));
var amazonInstallLink = element(by.partialLinkText("Amazon EC2 Installation"));
this.go = function(){
browser.get(documentationURL);
browser.sleep(100);
};
this.drillDownToAmazonInstallDocumentation = function(){
installButton.click();
browser.sleep(100);
dockerEngineButton.click();
browser.sleep(100);
dockerCloudButton.click();
browser.sleep(100);
};
this.clickInstallOnAmazonLink = function(){
amazonInstallLink.click();
browser.sleep(100);
};
this.drillUpToAmazonInstallDocumentation = function(){
dockerCloudButton.click();
browser.sleep(100);
dockerEngineButton.click();
browser.sleep(100);
installButton.click();
browser.sleep(2000);
};
};
module.exports = DocumentationPage;
I used the page objects in tests as demonstrated below.
var HomePage = require("./pages/HomePage.js");
var DocumentationPage = require('./pages/DocumentationPage.js');
describe("Testing the Docker Documentation UI", function(){
var hp = new HomePage();
var dp = new DocumentationPage();
beforeEach(function(){
browser.ignoreSynchronization = true;
dp.go();
});
it("Validate accordion navigation drills down", function(){
dp.drillDownToAmazonInstallDocumentation();
dp.clickInstallOnAmazonLink();
expect(browser.getTitle()).toContain("Amazon EC2 Installation");
});
it("Validate accordion navigation drills up", function(){
dp.drillDownToAmazonInstallDocumentation();
dp.drillUpToAmazonInstallDocumentation();
});
});

InDesign CS6 javascript: importXML and remove empty pages

I use InDesign CS6. I wrote a javascript to add an option into menu: it first imports an XML in a document, then removes empty pages.
As run, before it actually imports an XML file, it removes empty pages. So there aren't enough pages for the XML.
How to excute these 2 functions as wanted? Here is my program:
var menuItem = "XML";
var smaTitle1 = "Import XML";
var sma1 = app.scriptMenuActions.add(smaTitle1);
// Add an Event Listener
sma1.addEventListener(
/*event type*/ 'onInvoke',
/*event handler*/ function(){
importXML(xmlPath);
}
);
sma1.addEventListener(
/*event type*/ 'afterInvoke',
/*event handler*/ function(){
// Remove empty pages
alert("remove pages");
removeEmptyPages();
}
);
function importXML(xmlPath){
if (app.documents.length != 0){
var myDocument = app.documents.item(0);
//import the entire XML structure in the document.
var myXMLImportPreferences = myDocument.xmlImportPreferences;
myXMLImportPreferences.allowTransform = false;
myXMLImportPreferences.ignoreWhitespace = true;
myXMLImportPreferences.removeUnmatchedExisting = false;
myXMLImportPreferences.importStyle = XMLImportStyles.MERGE_IMPORT;
myXMLImportPreferences.repeatTextElements = true;
var path = new File(xmlPath);
var file = path.openDlg("Importer XML", "XML:*.xml", false);
if (file != null) {
myDocument.importXML(file);
}
}
}
function removeEmptyPages(){
...
// a loop to remove empty pages
pages[i].remove();
...
}
Why don't you just call your removeEmptyPages function at the end of your importXML function ?
function importXML(xmlPath) {
…
removeEmptyPages();
}

Categories