I have a windows phone app that connects to a local IIS Server. It downloads some json data and displays it in a list box. I also have a refresh button on the page. When the page loads everything is correct but pressing the refresh button only returns the same data that was available when the page is loaded. I have checked my web browser with the uri and the updated data shows there correctly. Also If I exit the windows phone app and reload it the data is there. Here is some dumbed down code I am testing with.
On page load:
WebClient download = new WebClient();
download.DownloadStringCompleted += new DownloadStringCompletedEventHandler(download_DownloadStringCompleted);
download.DownloadStringAsync(new Uri("http://sampledata/data"));
void download_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
{
MessageBox.Show(e.Result);
}
This works fine and displays a message box with my json string.
On Refresh:
private void Button_Click(object sender, RoutedEventArgs e)
{
WebClient refresh = new WebClient();
refresh.DownloadStringCompleted += new DownloadStringCompletedEventHandler(refresh_DownloadStringCompleted);
refresh.DownloadStringAsync(new Uri("http://sampledata/data"));
}
void refresh_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
{
MessageBox.Show(e.Result);
}
This displays the same json string that was displayed on page load even though the data has changed. Does anyone have any ideas? Thanks.
try adding a time stamp to the end of the URL. like refresh.DownloadStringAsync(new URI("http://sampledata/data" + DateTime.Now.ToString()));
How much data do You pulling out from server? Try with HttpWebRequest if you need heavy lifting. I also had some issuses with webclient loading and refreshing data. Every change on server comes with big delay...
Related
I am testing a Chrome extension which requires the user to be logged in to use, but I cannot figure out how to login with my test account. I have tried logging in to accounts.google.com but this is apparently insufficient; as far as the chrome APIs are concerned there is no authenticated user.
Chrome keeps prompting for login at chrome://chrome-signin but because I can't view the html of the page I can't determine what elements to interact with in Selenium to use it.
You may need to login manually once and then use that for automation.
Try below code , may be it help you:
System.setProperty("webdriver.chrome.driver","<chrome exe path>");
ChromeOptions options = new ChromeOptions();
options.addArguments("user-data-dir= <full local path Google Chrome user data default folder>);
WebDriver driver = new ChromeDriver(options);
driver.get("https://mail.google.com");
Login once manually when browser launched.
Then re-run script now it should use previous login.
Hope it will help you.
I think you can still login automatically. The reason is, when opening the page chrome://chrome-signin, the account textbox is automatically focused, so you just need to use keyboards to login without knowing how the html of the page looks like.
Try the code below (you might need to put some sleep in some places to make sure that everything is loaded properly.
public void loginToChrome(username, password) {
driver.get("chrome://chrome-signin");
var action = new Actions(driver);
action.sendKeys(username).perform();
action.sendKeys(keys.ENTER).perform();
action.sendKeys(password).perform();
action.sendKeys(keys.ENTER).perform();
}
First login to gmail on regular chrome browser (NOT the one triggered by selenium driver). Once you login, install the EditTheCookie extension. And on the gmail tab, click this extension icon. It will give option to copy the cookies in json format to clipboard. Paste that into Gmail.data which will be used in below programme.
Once you past, place that Gmail.data file in a avilable location for below programme (you can place anywhere and update the path of that file in below code accordingly).
I've developed this and is a working solution for me since long.
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.Date;
import org.openqa.selenium.Cookie;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import com.google.gson.Gson;
public class LoginUtils {
private static final String GMAIL_LOGIN_URL =
"https://accounts.google.com/signin/v2/identifier";
public static void main(String[] args) {
WebDriver driver = new ChromeDriver();
driver = LoginUtils.login(driver, GMAIL_LOGIN_URL, "Gmail.data");
}
public static final WebDriver login(WebDriver driver, String url, String pathOfJsonFileName) {
Cookies[] data = readJson(pathOfJsonFileName);
driver.navigate().to(url);
// Set the expire time of each cookie.
Date expiryTime = new Date(System.currentTimeMillis() + 1000000000);
for (Cookies cookie : data) {
Cookie ck = new Cookie(cookie.getName(), cookie.getValue(), cookie.getDomain(), cookie.getPath(),
expiryTime, Boolean.parseBoolean(cookie.getSecure()), Boolean.parseBoolean(cookie.getHttpOnly()));
driver.manage().addCookie(ck);
}
return driver;
}
private static final Cookies[] readJson(String jsonFileName) {
String json = null;
try {
byte[] encoded = Files.readAllBytes(Paths.get(jsonFileName));
json = new String(encoded);
} catch (Exception e) {
e.printStackTrace();
}
return new Gson().fromJson(json, Cookies[].class);
}
}
I am using below code to download my target web site source and extract my required information .
protected void Button1_Click(object sender, EventArgs e)
{
WebClient Client = new WebClient ();
Client.DownloadFile("target page url", " D:/myTextFile.txt");
}
But in some cases in my target web site i need to press a key to load my required information.
For example in this page I should press "More" Button to see full data.
How can i reach this object?
I have followed all the steps given in the documentation to register for a push notification from the Parse website. (All the steps in the sense I downloaded the default project and added event handler to handle the incoming toast notification).
ParseClient.Initialize("x0uNa3Q164SVGKbH4mxZJaxWxsuYtslB5tVPj893",
"cXFv9RQAoray9xFdwdcZCHXrrkrM6KNd0WyN194H");
this.Startup += async (sender, args) =>
{
// This optional line tracks statistics around app opens, including push effectiveness:
ParseAnalytics.TrackAppOpens(RootFrame);
// By convention, the empty string is considered a "Broadcast" channel
// Note that we had to add "async" to the definition to use the await keyword
await ParsePush.SubscribeAsync("");
};
ParsePush.ToastNotificationReceived += ParsePushOnToastNotificationReceived;
and the handler
private void ParsePushOnToastNotificationReceived(object sender,
NotificationEventArgs notificationEventArgs)
{
var s = new ShellToast();
s.Content = notificationEventArgs.Collection.Values.First();
s.Title = "My Toast";
s.Show();
}
private async void Application_Launching(object sender, LaunchingEventArgs e)
{
await ParseAnalytics.TrackAppOpenedAsync();
}
When I run the app in the emulator it registers the app and I can verify it in my dashboard. But as soon as I send push notification from the website number of registered devices will be shown as 0 and the app doesnt receive the notification.
One thing to mention is this behavior is not consistent. Sometimes the app does receive the notification. Can anyone mention the reason for this or any other point I am missing?
One thing to note is that ShellToast.Show() should only be used from background task. If you call it when an app is in the foreground, toast won't be shown. http://msdn.microsoft.com/en-US/library/windowsphone/develop/microsoft.phone.shell.shelltoast.show(v=vs.105).aspx
So, be sure your app is not in the foreground when you expect to see toast notification.
Firstly you will be shown toast notification only if the foreground app is not running. If your app is running when you receive push notification you have to do like:
void ParsePushOnToastNotificationReceived(object sender,
NotificationEventArgs notificationEventArgs)
{
Deployment.Current.Dispatcher.BeginInvoke(()=>{
// do anything
MessageBox.Show("got notification");
});
}
If your app is not running the os will handle the notification properly, you dont have to do anything.
I want in app purchasing in my Windows Phone 8 app. I published my app as beta and also 3 products for this app that u can buy. I copied my ID from Dev Center in Visual Studio 2013. Now I want to test it.
The Problem is when I click on this button:
private async void buttonInfo_Click(object sender, RoutedEventArgs e)
{
StringBuilder sb = new StringBuilder();
var listing = await CurrentApp.LoadListingInformationAsync();
foreach (var product in listing.ProductListings)
{
sb.AppendLine(string.Format("{0}, {1}, {2},{3}, {4}",
product.Key,
product.Value.Name,
product.Value.FormattedPrice,
product.Value.ProductType,
product.Value.Description));
}
MessageBox.Show(sb.ToString(), "List all products", MessageBoxButton.OK);
}
Then the messageBox appears but has no Content. Why not?
You can just debug on it.. make sure
await CurrentApp.LoadListingInformationAsync()
returns the result you expected
It was fixed after a day. no changes in code. xD maybe Servers were not ready
Hi I'm trying to save a file from a Java Webstart Application.
public class Main {
public static void main(String[] args) {
try {
FileSaveService fos = (FileSaveService) ServiceManager.lookup("javax.jnlp.FileSaveService");
//open Dialog
FileContents fc = fos.saveFileDialog("c:/data", null, new ByteArrayInputStream("Hallo Welt".getBytes()), "name.txt");
System.out.println("FileContents: " + fc);
} catch (UnavailableServiceException e) {
System.err.println("***" + e + "***");
} catch (IOException e) {
System.err.println("***" + e + "***");
}
//wait a minute
try {
Thread.sleep(10000);
} catch (InterruptedException e) {
}
System.exit(0);
}
}
Everything works except that the dialog that comes up looks like a "open" file dialog, not like a "save" file dialog:
Any help would be appreciated.
The File-Open-dialog is necessary. You first need to let the user choose where to save the data. Thus a previous call to openFileDialog is absolute necessary for a jnlp-application. You are not allowed to directly save to a specific location like c:
If you follow the mentioned link (http://docs.oracle.com/javase/6/docs/technotes/guides/javaws/developersguide/examples.html#FileSaveService) you should be successful.
EDIT:
for clarification.
Saving via javax.jnlp.FileSaveService does exactly need one call. For instance calling saveFileDialog() like this should be sufficient:
fss.saveFileDialog(null, null, new ByteArrayInputStream("Hallo Welt".getBytes() ), "newFileName.txt");
The necessity of one User-Dialogue is due to the anonymizing nature of jnlp, where your application should not get any hint about the user-filesystem.
However, I have to admit, that this was not your question.
Your main trouble comes from the java app everytime presenting the "open-dialogue" instead of the "save-dialogue".
This should not happen! If I may humbly assume from your snippet where you call fos.saveFileDialog: did you just initialize fos by the FileOpenService instead of the FileSaveService?
More details on the FileSaveService can be found here: http://docs.oracle.com/javase/7/docs/jre/api/javaws/jnlp/javax/jnlp/FileSaveService.html
This seems to be fixed in JRE bersion 1.7.0_21-b11 Java HotSpot(TM) 64-Bit Server VM
And there it is: http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=2227257