FACELETS_REFRESH_PERIOD Not Working - facelets

I'm using jetty and JSF 2.2 in my webapp.
Normally when I make a change to a page it refreshes fine in my webapp.
After load testing the page (I load a page 500 times), the page stops refreshing.
However, if I change the FACELETS_REFRESH_PERIOD from 2->0 it starts refreshing again.
Is this a bug?
<context-param>
<param-name>javax.faces.FACELETS_REFRESH_PERIOD</param-name>
<param-value>0</param-value>
</context-param>
Load Test:
public static void main(String[] args) throws Exception {
for (int i = 0; i < 500; i++) {
URL myURL = new URL("http://localhost:8080/test");
URLConnection myURLConnection = myURL.openConnection();
myURLConnection.connect();
myURLConnection.getContent();
((HttpURLConnection)myURLConnection).disconnect();
}
}

Related

org.openqa.selenium.interactions.MoveTargetOutOfBoundsException: Cannot click on element

Getting below exception error while running the code in IE browser. However same works fine Firefox and Chrome browser. Can someone help?
I am trying to run the below code in IE browser and trying to click on link "create button" on page https://en.wikipedia.org/wiki/Selenium_%28software%29. But link never gets clicked , same code works fine in Firefox.
can you please advise if I need to make any changes
public class ClickIE {
public static void main(String[] args) throws InterruptedException {
DesiredCapabilities caps = new DesiredCapabilities();
caps.setCapability("requireWindowFocus", true);
System.setProperty("webdriver.ie.driver", "C:\\Users\\Nitin\\IEDriverServer_x64_3.14.0\\IEDriverServer.exe");
WebDriver driver = new InternetExplorerDriver(caps);
driver.get("https://en.wikipedia.org/wiki/Selenium_%28software%29");]
Thread.sleep(5000);
driver.manage().window().maximize();
driver.findElement(By.xpath("/html/body/div[4]/div[1]/div[1]/ul/li[4]/a")).click();
String url = driver.getCurrentUrl();
if(url.contains("wikipedia")) {
System.out.println(url+" its a internal link - Passed");
}
else {
System.out.println(url+" its a external link - Failed");
}

Accessing document elements when using Windows.Forms.WebBrowser

I'm new to automating webpage access, so forgive what is probably a remedial question. I'm using C#/Windows.Forms in a console app. I need to programmatically enter the value of an input on a webpage that I cannot modify and that is running javascript. I have successfully opened the page (triggering WebBrowser.DocumentCompleted). I set browser emulation mode to IE11 (in registry), so scripts run without errors. When DocumentCompleted() triggers, I am unable to access the document elements without first viewing the document content via MessageBox.Show(), which is clearly not acceptable for my unattended app.
What do I need to do so that my document elements are accessbile in an unattended session (so I can remove MessageBox.Show() from the code below)? Details below. Thank you.
The input HTML is:
<input class="input-class" on-keyup="handleKeyPress($key)" type="password">
My DocumentCompleted event handler is:
private static void LoginPageCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
WebBrowser wb = ((WebBrowser)sender);
var document = wb.Document;
// I'm trying to eliminate these 3 lines
var documentAsIHtmlDocument = (mshtml.IHTMLDocument)document.DomDocument;
var content = documentAsIHtmlDocument.documentElement.innerHTML;
MessageBox.Show(content);
String classname = null;
foreach (HtmlElement input in document.GetElementsByTagName("input"))
{
classname = input.GetAttribute("className");
if (classname == "input-class")
{
input.SetAttribute("value", password);
break;
}
}
}
The problem for me was that the page I'm accessing is being created by javascript. Even though documentComplete event was firing, the page was still not completely rendered. I have successfully processed the first page by waiting for the document elements to be available and if not available, doing Application.DoEvents(); in a loop until they are, so I know now that I'm on the right track.
This SO Question helped me: c# WebBrowser- How can I wait for javascript to finish running that runs when the document has finished loading?
Note that checking for DocumentComplete does not accurately indicate the availability of the document elements on a page generated by javascript. I needed to keep checking for the elements and running Application.DoEvents() until they became available (after the javascript generated them).
If the problem comes from the creation of a STAThread, necessary to instantiate the underlying Activex component of WebBrowser control, this is
a modified version of Hans Passant's code as shown in the SO Question you linked.
Tested in a Console project.
class Program
{
static void Main(string[] args)
{
NavigateURI(new Uri("[SomeUri]", UriKind.Absolute), "SomePassword");
Console.ReadLine();
}
private static string SomePassword = "SomePassword";
private static void NavigateURI(Uri url)
{
Thread thread = new Thread(() => {
WebBrowser browser = new WebBrowser();
browser.DocumentCompleted += browser_DocumentCompleted;
browser.Navigate(url);
Application.Run();
});
thread.SetApartmentState(ApartmentState.STA);
thread.Start();
}
protected static void browser_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
WebBrowser browser = ((WebBrowser)sender);
if (browser.Url == e.Url)
{
while (browser.ReadyState != WebBrowserReadyState.Complete)
{ Application.DoEvents(); }
HtmlDocument Doc = browser.Document;
if (Doc != null)
{
foreach (HtmlElement input in Doc.GetElementsByTagName("input"))
{
if (input.GetAttribute("type") == "password")
{
input.InnerText = SomePassword;
//Or
//input.SetAttribute("value", SomePassword);
break;
}
}
}
Application.ExitThread();
}
}
}

Facebook login acting up in Windows Phone 7

I'm trying out a "login with facebook" feature for a Windows Phone app. I have a very small prototype with a button and a webbrowser on a page. Clicking on the button directs the browser to a URL specified by the Facebook API in order to authorize an app with the details of the currently logged in user.
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition></RowDefinition>
</Grid.RowDefinitions>
<Button Click="ButtonBase_OnClick">Clic</Button>
<phone:WebBrowser Grid.Row="1" x:Name="webBrowser" Navigated="WebBrowser_OnNavigated"/>
</Grid>
The code behind looks like so :
private const string AppId = "123456"; // In my code I've put the correct App ID.
private void ButtonBase_OnClick(object sender, RoutedEventArgs e)
{
webBrowser.Navigate(new Uri("https://www.facebook.com/dialog/oauth?client_id=" + AppId + "&redirect_uri=" + Uri.EscapeUriString(#"https://www.facebook.com/connect/login_success.html")));
}
private void WebBrowser_OnNavigated(object sender, NavigationEventArgs e)
{
var x = e.Uri.ToString();
} // BreakPoint set here to inspect 'x'
This exact piece of code placed in a WPF application works as expected. That is, if I haven't authorized the app yet, the first hit on the 'OnNavigated' event handler reflects the URL above and then, after authorization, has a URL containing an authorization token. Here's the URLs and steps when I run it as a WPF app :
A. Start the app, clic the button :
https://www.facebook.com/dialog/oauth?client_id=123456&redirect_uri=https://www.facebook.com/connect/login_success.html
Now I get presented with the "[your_app_name] will receive the following information about you : public profile and friends list". I click OK.
B. I am getting redirected to :
=">https://www.facebook.com/connect/login_success.html?code=AQAOJ7H6lK7dsRCJPRjVRVPZmxQrZ7ksWyqb87MfagEc1eatw_1n4ijY0IpDmbVQEg6Un3nmrvzhiiynM4S_l5S_ChgD7ZOVSf-JvxyD8S5sCHFUtBZ9H8lCrT0Lh7aRDgKW1u1XbWuUfcbXl2i6FndWG9Svk9bssRq7F4O-XrPsnK--b31qrFLptzrA0saC1stWoMhyR9vXkiLevxADQ7GHpeGQeu29mOhIaXWBtJy1Wlvins346kNR8Pi77wwpwAt5BzYsTRXdbYxbFdAPDJI2RJyqv4IMKGR0BucmtX9lrmBWcfJeMLzMag-GNDJ5I4U#=
(I've changed a few characters in the token above in order to protect my privacy)
Now this is great and it's what I need. I'll take the very same code and place it in a Windows Phone 7.1 app and the behavior changes like so :
First the URL differs, probably because it detects a mobile (touch) device :
A. Click the button :
https://m.facebook.com/login.php?skip_api_login=1&api_key=123456&signed_next=1&next=https://m.facebook.com/dialog/oauth?redirect_uri=https%253A%252F%252Fwww.facebook.com%252Fconnect%252Flogin_success.html&client_id=123456&ret=login&cancel_uri=https://www.facebook.com/connect/login_success.html?error=access_denied&error_code=200&error_description=Permissions+error&error_reason=user_denied%23_=_&display=touch&_rdr
Now I'm getting to the login page so I first login into facebook. I hit login.
B. I am getting to :
rdr#=_">https://m.facebook.com/dialog/oauth?redirect_uri=https://www.facebook.com/connect/login_success.html&client_id=123456&ret=login&ext=1391596741&hash=AeYEMbLJMwI3QhOE&refsrc=https://m.facebook.com/login.php&refid=9&m_sess=c2VzczoxMDAwMDAwOTg1MjE5NzM6MzM6Ti13TjN3eUERd3ZrR1E6MjoxMzkxNTkzMTQxOjMwODE&rdr#=_
At this page I am getting asked if I want to authorize the app. I click OK.
C. I get redirected to https://m.facebook.com/dialog/oauth/read (no other querystring).
This is my issue
At this point I'm stumped since I have no auth token. A workaround is to try redirecting the browser again to the first URL (see ButtonBase_OnClick) and that will work.
That means changing the OnNavigated event handler to :
private void WebBrowser_OnNavigated(object sender, NavigationEventArgs e)
{
var x = e.Uri.ToString();
if (x == #"https://m.facebook.com/dialog/oauth/read")
{
ButtonBase_OnClick(sender, new RoutedEventArgs());
}
}
But that requires ANOTHER request and it definetely feels like a hack.
Am I doing something wrong? Is the app not configured properly?
I had these working for my WP7.5 app which worked in WP8 too. It was using graph api before this Facebook SDk for .Net was born.
string strLoginURL = "https://graph.facebook.com/oauth/authorize?client_id={0}&redirect_uri=http://www.facebook.com/connect/login_success.html&type=user_agent&display=touch&scope=publish_stream,user_hometown";
string strAppID = "123456789101112";
string strPostMessageURL = "https://graph.facebook.com/yourpageid/feed";
string strAccessToken = String.Empty;
private void PhoneApplicationPage_Loaded(object sender, RoutedEventArgs e)
{
webBrowser.Navigate(new Uri(string.Format(strLoginURL, strAppID), UriKind.Absolute));
}
private void webBrowser_LoadCompleted(object sender, NavigationEventArgs e)
{
string strSourceString = objAuthorizeBrowserControl.Source.ToString();
//string strSourceString = e.Uri.OriginalString.ToLower();
if (strSourceString.Contains("access_token"))
{
int index1 = strSourceString.IndexOf("access_token");
int index2 = strSourceString.IndexOf("expires_in");
strAccessToken = strSourceString.Substring(index1 + 13, index2 - (index1 + 14));
}
/*...
else
logging in and authorize app will get redirected automatically untill access token is generated.
...*/
if(strAccessToken != String.Empty)
{
WebClient wc = new WebClient();
string strParametersToPost = "access_token=" + strAccessToken + "&message=" + HttpUtility.UrlEncode(yourcontenttopost);
wc.UploadStringAsync(strPostMessageURL, "POST", strParametersToPost);
// you can use wc.UploadStringCompleted Event to capture the result.
}
}
private void webBrowser_Navigating(object sender, NavigatingEventArgs e)
{
string strSourceString = objAuthorizeBrowserControl.Source.ToString();
//string strSourceString = e.Uri.OriginalString.ToLower();
if (strSourceString.Contains("access_token"))
{
int index1 = strSourceString.IndexOf("access_token");
int index2 = strSourceString.IndexOf("expires_in");
strAccessToken = strSourceString.Substring(index1 + 13, index2 - (index1 + 14));
}
}
Why are you using the old method Use this:
http://facebooksdk.net/docs/phone/tutorial/, And this is also a very simple method it will take you around 1-2 hours to setup.
And I am using it in my app and it is working great for me I am registering the user through this in my app and storing all the details.

In Selenium Webdriver how we can skip the data download?

I want to skip the loading of whole web page and just want to check status of URL in selenium webdriver so that the execution can be much faster.
If you just want to check status of a page and don't need to bother about content inside that, you can just get response code and check if it is 200(HTTP_OK). I would suggest you use simple java to verify instead of trying to get it done with selenium webdriver. I just wrote a small program that does just that. See it this works fine for you. This tests if the web page can be successfully reached and didn't send back any 404 or 500 or any other error.
import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.URL;
public class HttpTest
{
public static void main(String[] args) throws IOException
{
URL url = new URL ( "http://www.google.com/");
HttpURLConnection conn = ( HttpURLConnection )url.openConnection ();
conn.setRequestMethod ("HEAD"); // GET will fetch the content of the page, which is not needed for your case.
conn.connect () ;
if(conn.getResponseCode() == HttpURLConnection.HTTP_OK)
System.out.println("Success");
}
}
What do you want to do? Do you want to click some links on a page and check whether they are redirecting to right URL? In this case you can try checking for change in URL. See the example below:
int i=0;
do{
try {
Thread.sleep(20);
} catch (InterruptedException e) {
}
i++;
} while(driver.getCurrentUrl().equals("The URL on which the page is originally.")&&i<10); //After URL changes, verify it.

Why is Google App Engine servlet getting old no more exist data from file?

I have a Google App Engine servlet, it's supposed to go to my site and get a file, then display the content of that file on the servlet served page, the code looks like this :
public class My_Servlet extends HttpServlet
{
public void init(ServletConfig config) throws ServletException
{
super.init(config);
System.gc();
}
public void doGet(HttpServletRequest request,HttpServletResponse response) throws IOException
{
PrintWriter out=response.getWriter();
response.setContentType("text/html");
out.println(getTextFile());
}
String getTextFile()
{
String Text="";
try
{
URL url=new URL("http://example.com/A_Dir/Test.txt");
BufferedReader reader=new BufferedReader(new InputStreamReader(url.openStream()));
String line;
while ((line=reader.readLine())!=null) { Text+=line+"<Br>"; }
reader.close();
}
catch (Exception e) { }
return Text;
}
It worked, but the problem is, after I changed the content in the file "Test.txt" on my site, the Google App is still displaying old data, I checked and double checked the file on my site, the old data is no longer there, and I thought every time I clicked the link served by the GAE, it will call getTextFile(), create the URL, go get the file and parse the lines, but it seems GAE is remembering old data from 3 days ago, and no matter how many times I refreshed the page or updated the GAE app and reloaded it on to the App Engine [and I can see the change made to the updated servlet], it's still serving the more then 3 day old data, why? How to force it dynamically load that file?
GAE is caching the file. Try:
URL url=new URL("http://mysite.com/A_Dir/Test.txt?r="+System.currentTimeMillis());

Resources