I am using nodejs, Soda with selenium
I am hitting problems trying to get the javascript to fire events like on entry of data. Script can't even get through the creation of client flow on IE. Only worried about IE 9+ btw.
Am I missing anything ? This works fine in latest FF. Below posting sample code using for FF
var soda = require('soda');
var assert = require('assert');
var browser = soda.createClient({
url: 'http://192.168.12.1/', // localhost website
port:5555,
host:'192.168.1.3', //grid ip
browser: 'firefox',
browserTimeout:5
});
var testname = 'Nits' + parseInt(Math.random() * 100000000); //create unique name for new person.
console.log('randome name: ' + testname);
browser
.chain
.session()
.setSpeed(speed)
.setTimeout(20000)
.open('/')
.and(login('dev#dev.com', 'x1212GQtpS'))
.and(killClient(killAtEnd))
.end(function(err){
console.log('done');
if(err){
console.log(err);
}else{
console.log("We're Good");
}
if (closeAtEnd){
browser.testComplete(function() {
console.log('killing browser');
});
}
});
function login(user, pass) {
return function(browser) {
browser
.click('css=a#loginButton')
.type('css=input.input-medium.email',user)
.type('css=input.input.pwd',pass)
.clickAndWait('css=a.btn.login')
.assertTextPresent('Clients',function(){ console.log('logged in ok')})
}
}
Can you be more specific about exactly where the script stops, fails, or throws an error? I suspect that IE can't handle the way you put your css selector together (i.e. the classname combinators such as 'input.input.pwd' ). I would recommend trying a different selector or rewrite/simplify your existing selector until you get it working.
Related
I have implemented deep link in my Android App to share content. The problem is on Android I can't find a way to set a Fallback URL when the user open the short link on his desktop.
With the Firebase DynamicLink.Builder I can set iOS fallback URL because my app doesn't exist on iOS but I can't find a way to set the dfl parameters in my link.
Which lead the user to an error page like this :
Here how I build my short dynamic link:
//link example : https://app.example.com/details/ebLvAV9fi9S7Pab0qR3a
String link = domainUri + "/details/" + object.getUid();
FirebaseDynamicLinks.getInstance().createDynamicLink()
.setLink(Uri.parse(link))
.setDomainUriPrefix(domainUri)
.setAndroidParameters(new DynamicLink.AndroidParameters.Builder().setMinimumVersion(1).build())
// Fallback Url for iOS
.setIosParameters(new DynamicLink.IosParameters.Builder("").setFallbackUrl(Uri.parse(RMP_WEB_BASE_URL)).build())
.setSocialMetaTagParameters(
new DynamicLink.SocialMetaTagParameters.Builder()
.setTitle(title)
.setDescription(description)
.setImageUrl(Uri.parse(imageUrl))
.build())
.buildShortDynamicLink()
.addOnCompleteListener(new OnCompleteListener<ShortDynamicLink>() {
#Override
public void onComplete(#NonNull Task<ShortDynamicLink> task) {
if (task.isSuccessful() && task.getResult() != null) {
shortLink = task.getResult().getShortLink();
//Create Shareable Intent
//...
}
}
});
I have read that I need to specify a Desktop Fallback URL like the iOS one but DynamicLink.Builder doesn't seems to include one.
I would like to redirect my user to the home page https://example.com when they open the link from a non-android device.
I have tried to use setLongLink(longLink) in the DynamicLink.Builder with the parameters ?dfl=https://example.com but it doesn't seems to work and it even break my dynamic link on android.
This is a Swift solution but may be helpful to others-
Unfortunately, there is currently no built-in method to handle this programmatically through the Firebase url editor. You must manually add an 'ofl' parameter to the link. The easiest way to do this:
// Grab link from Firebase builder
guard var longDynamicLink = shareLink.url else { return }
// Parse URL to string
var urlStr = longDynamicLink.absoluteString
// Append the ofl fallback (ofl param specifies a device other than ios or android)
urlStr = urlStr + "&ofl=https://www.google.com/"
// Convert back to a URL
var urlFinal = URL(string: urlStr)!
// Shorten the url & check for errors
DynamicLinkComponents.shortenURL(urlFinal, options: nil, completion:{ [weak self] url,warnings,error in
if let _ = error{
return
}
if let warnings = warnings{
for warning in warnings{
print("Shorten URL warnings: ", warning)
}
}
guard let shortUrl = url else {return}
// prompt the user with UIActivityViewController
self?.showShareSheet(url: shortUrl)
})
The final URL can then be used to present the shareable panel with another function like:
self.showShareSheet(url: finalUrl) which triggers the UIActivityViewController
Credit to http://ostack.cn/?qa=168161/ for the original idea
More about ofl: https://firebase.google.com/docs/dynamic-links/create-manually?authuser=3#general-params
i am creating an internet radio application for android. So far i have successfully streamed and played using the shoutcast url for various stations.This is my code :
String url = "http://185.33.22.13:7704";
mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
try
{
mediaPlayer.setDataSource(url);
mediaPlayer.prepare();
}
catch (IOException e)
{
e.printStackTrace();
}
mediaPlayer.start();
Next i would want to get the information of stream to be shown in my application.
I want to retrieve the information shown in green box:
People have posted about FFmpegMediaMetadataRetriever but github is way out of my league to understand also tried thier apk file which does nothing when given the above http link.Please suggest me a simple and robust solution to retrieve the data from SHOUTcast DNAS status.
Thanks in advance !
Shoutcast V1 has a special page with bitrate and other information.
If your shoutcast is running on
http://185.33.22.13:7704
then this page url will be:
http://185.33.22.13:7704/7.html
The body of that page looks like this:
<HTML><meta http-equiv="Pragma" content="no-cache"></head><body>214,1,312,1000,213,64,Ferry Tayle - The Way Back Home (Edit) (feat. Poppy)</body></html>
Split that text by commas and you will get:
Current listeners
Stream status
Peak listeners
Maximum number of listeners (from server start)
Unique listeners
Bitrate
Song title
Here is an example in javascript (Nodejs) that gets the data from 7.html page and parses it:
var request = require('request'),
options = {
url: 'http://185.33.22.21:7704/7.html',
headers: {
'User-Agent': 'Mozilla/5.0'
}
},
regex = /<body>(.*?)<\/body>/i;
request(options, function (error, response, body) {
var match = regex.exec(body),
data = match[1].split(',');
console.log("7.html: ", body);
console.log("Current listeners: ", data[0]);
console.log("Stream status: ", data[1]);
console.log("Peak listeners: ", data[2]);
console.log("Maximum number of listeners: ", data[3]);
console.log("Unique listeners: ", data[4]);
console.log("Bitrate: ", data[5]);
console.log("Metada: ", data[6]);
});
Please note that setting "User-Agent" header is required.
If you have admin password from that server - then another way is to get XML data directly from shoutcast admin page using the following URL:
http://185.33.22.13:7704/admin.cgi?mode=viewxml
I am trying to develop a record and playback tool using selenium webdriver like the way Selenium IDE does. I started withCchrome browser, tried different approaches. Few of them are here:
Tried creating a JavaScript with event listeners and tried executing it using JavascriptExecutor. In the JS script I have implicit wait to return some value. Sample code:
var flag = 0;
var elementId;
window.addEventListener("click", function (e) {
elementTagName=e.target.id;
alert(elementTagName);
flag++;
});
var timer = setInterval(function () {
myTimer();
}, 1000);
function myTimer() {
if(flag == 0){
document.getElementById("demo").innerHTML=flag;
} else {
clearInterval(timer);
return elementId; //Returning the element ID which was clicked
}
}
But now the problem is, webdriver code written in java(shown below) is not waiting for the return. Same code works fine when I run it individually.
Object response = ((JavascriptExecutor) driver).executeScript(script);
if (null != response) {
System.out.println((String) response);
}
Any other way I can do it?
Instead of returning the JS value, you can store it in a JS variable, by changing this line:
return elementId;
to this:
retVal = elementId;
Then, whenever you would have accessed response in Java, execute JS to access the JS var on the page instead:
// execute JS functions from your question above
((JavascriptExecutor) driver).executeScript(script);
// wait however long needed for those functions to complete
Thread.sleep(1000);
// get result from page
String response = (String)((JavascriptExecutor) driver).executeScript("return retVal");
I am using Edraw Office Viewer component to open & edit the file. I want to save my file to my destination point so I am using JavaScript to save the file. But I am stuck at a point. I am showing my code below to save document using JavaScript.
function f_saveDocument(){
if(document.OA1.IsOpened)
{
var saveAsFileName = document.getElementById('hdnFileName').value;
alert(saveAsFileName);
var fileFormat = saveAsFileName.substring(saveAsFileName.lastIndexOf("."));
if(fileFormat == '.docx') {
var toUnLockFile = 'MergeTest'+fileFormat;
var tempFileLocation = document.OA1.GetTempFilePath(saveAsFileName);
var tempToUnLockFileLocation = document.OA1.GetTempFilePath(toUnLockFile);
document.OA1.SaveAs(tempFileLocation,12);
document.OA1.SaveAs(tempToUnLockFileLocation,12);
document.OA1.HttpInit();
document.OA1.HttpAddPostFile(tempFileLocation);
document.OA1.HttpPost("");
document.OA1.ClearTempFiles();
} else {
alert("asdsa");
document.OA1.HttpInit();
document.OA1.HttpAddPostOpenedFile(saveAsFileName);
**zAu.send(new zk.Event(zk.Widget.$('$btnSave'), "saveFile", {'' : {'data' : {'nodeId': ''}}}, {toServer:true}));**
alert("moved");
}
}
In case of JSP page I can put my JSP URL in HttpPost but in case of ZK how to move from this JavaScript to Java method. So to overcome this problem I am using Widget to call saveFile() method which is in my viewmodel class. But zAu.send is not working fine. Can any body tell other solution to call my Java method from JavaScript in ZK MVVM.
Your code is simply wrong
zAu.send(new zk.Event(zk.Widget.$('$btnSave'), "onSaveFile", {'' : {'data' : {'nodeId': ''}}}, {toServer:true}));
Event names must start with on so this will fire a onSaveFile
event to the Component with id btnSave. Just listen to it.
I need to create an automated process (preferably using Java) that will:
Open browser with specific url.
Login, using the username and password specified.
Follow one of the links on the page.
Refresh the browser.
Log out.
This is basically done to gather some statistics for analysis. Every time a user follows the link a bunch of data is generated for this particular user and saved in database. The thing I need to do is, using around 10 fake users, ping the page every 5-15 min.
Can you tink about simple way of doing that? There has to be an alternative to endless login-refresh-logout manual process...
Try Selenium.
It's not Java, but Javascript. You could do something like:
window.location = "<url>"
document.getElementById("username").value = "<email>";
document.getElementById("password").value = "<password>";
document.getElementById("login_box_button").click();
...
etc
With this kind of structure you can easily cover 1-3. Throw in some for loops for page refreshes and you're done.
Use HtmlUnit if you want
FAST
SIMPLE
java based web interaction/crawling.
For example: here is some simple code showing a bunch of output and an example of accessing all IMG elements of the loaded page.
public class HtmlUnitTest {
public static void main(String[] args) throws FailingHttpStatusCodeException, MalformedURLException, IOException {
final WebClient webClient = new WebClient();
final HtmlPage page = webClient.getPage("http://www.google.com");
System.out.println(page.getTitleText());
for (HtmlElement node : page.getHtmlElementDescendants()) {
if (node.getTagName().toUpperCase().equals("IMG")) {
System.out.println("NAME: " + node.getTagName());
System.out.println("WIDTH:" + node.getAttribute("width"));
System.out.println("HEIGHT:" + node.getAttribute("height"));
System.out.println("TEXT: " + node.asText());
System.out.println("XMl: " + node.asXml());
}
}
}
}
Example #2 Accessing named input fields and entering data/clicking:
final HtmlPage page = webClient.getPage("http://www.google.com");
HtmlElement inputField = page.getElementByName("q");
inputField.type("Example input");
HtmlElement btnG = page.getElementByName("btnG");
Page secondPage = btnG.click();
if (secondPage instanceof HtmlPage) {
System.out.println(page.getTitleText());
System.out.println(((HtmlPage)secondPage).getTitleText());
}
NB: You can use page.refresh() on any Page object.
You could use Jakarta JMeter