Watir webdriver attaching windows and waiting - facebook

I am trying to detect when a Facebook pop-up is displayed to then fill out the Facebook login form. I have tried the attach method, also the wait method, and the sleep method but it seems that as soon as I launch the new page all connection is lost:
#this output is displayed
puts "lets the game begingsx"
$b.goto("javascript:gigya.services.socialize.plugins.login.providerClick('loginPluginDiv','facebook')")
#this output is never displayed
puts "lets start sleep"
$b.window(:title,/Log In | Facebook/i).use do
$b.text_field(:id => 'email').when_present.set("xyz#gmail.com")
end

Here is how you can use newly opened/pop-up window
#my_browser = Watir::Browser.new
#my_browser.goto "your first url"
When you get facebook pop-up then do the following to perform actions on the pop-up window. I am assuming that you now the title on the facebook popup
#my_browser.window(:title => "facebook login popup title").use do
#my_browser.button(:id => "yout buttone id").click
end
I hope it will help

The problem is that you are using wrong title for Facebook login page. Page title is in html element.
So use this construct
#browser.window(:title => 'Facebook').wait_until_present
#browser.window(:title => 'Facebook').use do
end
Regards, Karlo.

Related

Serenity-JS, step function timed out

I'm in my first steps with Serenity and I've been stuck for 2 days with this problem.
I've got:
navigate to the login page
write the username
write the password
click the login button
and then, in the Step where the web change from login page to welcome page I want to validate if one of the buttons of the welcome page is present.
In the transition from login page to welcome appears a Loading Splash and then after a few seconds appears the Welcome page.
This is my scenario
Given that Sarah navigates to the access page
When she enters email as xxxx#yyyyy.com
And she enters password as zzzzzz
And she clicks the button Login
Then she should navigates to the Empresa JMM Enterprise welcome page
I got the error in the last step (Then).
This is my code for the step where clicks the button Login:
this.When(/^prueba pulsar boton (.*?)$/, function (buttonText: string) {
return this.stage.theActorInTheSpotlight().attemptsTo(
ClickIniciarSesion.click(buttonText)
)
});
And this is the code where I validate if the button is present
this.Then(/^s?he should navigates to (.*?) Enterprise welcome page$/, function (enterpriseName: string) {
return this.stage.theActorInTheSpotlight().attemptsTo(
See.if(WebElement.of(Header.WelcomeButton), el => expect(el).to.eventually.be.displayed)
)
I see the execution and seconds before of the timeout I see the welcome page loaded and the button. I don't know why the error is timeout and not that the driver can't find the element.
I think that I have the solution. In the transition from the login page to the welcome page appears one page of loading. I think that serenity is "looking" in this loading page.
The test passed OK disabling the Angular synchronisation, doing the wait manually and enabling the synchronisation.
this.Then(/^s?he waits the enterpise data load$/, function () {
return this.stage.theActorInTheSpotlight().attemptsTo(
UseAngular.disableSynchronisation()
);
});
this.Then(/^s?he should navigates to the (.*?) Enterprise welcome page$/, function (enterpriseName: string) {
return this.stage.theActorInTheSpotlight().attemptsTo(
Wait.until(Header.EnterpriseName, Is.visible()),
See.if(Header.EnterpriseName_Text, el => expect(el).to.eventually.be.equal(enterpriseName)),
UseAngular.enableSynchronisation()
)
});
I don't know if is the better solution.

How do I force the Facebook Like Button to re-scrape my page?

I created a like button on a page (http://www.usna.edu/BillAF/game.php) that sends the URL/data for it's parent page. Unfortunately, when I first put it in, an older version of the page was at the location of the parent page that did not have the open graph meta-tags on it.
So when someone "likes" the page, it sends the wrong title and a "garbage" image of half of the letter "e" on a white and gray square.
I checked: http://developers.facebook.com/tools/debug and it has the updated info. I also tried changing the associated AP ID to a new one, and neither seems to have refreshed what it sends when I "like" it. I also tried adding index.php to the end of the URL it is supposed to be posting (http://www.usna.edu/BillAF) but to no avail.
Is there anything I can do to force it to re-scrape the page? If not, does anyone know how long it will take for facebook to re-scrape it on their own?
A good way to clear the facebook cached image and text is by running the tool Debugger:
http://developers.facebook.com/tools/debug
By putting the url that you are sharing there, it will refresh facebook cache from your website.
Facebook has an API for re-scraping page data, I use the following function:
function purgeFacebookCache($url, $debug=false) {
// Set the variables for Facebook
$fields = array(
'id' => urlencode($url),
'scrape' => true
);
foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
rtrim($fields_string,'&');
// Connect
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL,'https://graph.facebook.com');
curl_setopt($ch,CURLOPT_POST,count($fields));
curl_setopt($ch,CURLOPT_POSTFIELDS,$fields_string);
$result = curl_exec($ch);
// Debug
if ($debug) {
var_dump($result);
}
}

Get Facebook Page Tab ID of current Tab?

I am trying to figure out how to get the tab ID of the current tab of a Facebook Page the user is visiting.
I have made an app for installation on Facebook Pages, that I need to save settings for, per instance. I have figured out that you can get an array of tabs for the page the app is installed on, but I can't figure out how to get the tab ID for the actual tab you're on.
The point is for an admin to be able to save settings for each tab that they've added the app to, using a single backend. I'm not sure if you can have multiple instances of one app on the same page, but if not, we'd have 2-3 duplicate apps with the same backend in the iframe. Because of that, I need to be able to identify app installations as unique - the best way I can figure out is through using the page id and tab id, for the app.
How do I do that?
UPDATE: Found out that you can only have one instance per app on a page.
With that, I went with using this solution (with '/tabs/' to get the tab info):
try {
$tab = $facebook->api('/'.$fb_page_id.'/tabs/'.$fb_app_id);
$fb_tab_link = $tab['data'][0]['link'];
} catch (FacebookApiException $e) {
echo '<!-- '.htmlspecialchars(print_r($e, true)).' -->';
}
In the above code, $fb_tab_link or a combination of $fb_page_id and $fb_app_id can be used as unique identifier. I decided to use the concatenation $fb_page_id . '-' . $fb_app_id as the instance ID.
After some research, I found the call to get the tab information via the API.
try {
$tab = $facebook->api('/'.$fb_page_id.'/tabs/'.$fb_app_id);
$fb_tab_link = $tab['data'][0]['link'];
} catch (FacebookApiException $e) {
echo '<!-- '.htmlspecialchars(print_r($e, true)).' -->';
}
Apparently, the tab ID is the combination of Page ID and App ID, which means that you cannot install the same app to more than one tab on a page.
I hope this can be helpful to someone who needs to find the unique ID for a tab on a Facebook Page.
In facebook api, when you want to change the tabname, you need to pass the tab id. see the example below.
To change your tab name using Javascript SDK.
your application tab_id will be app_[AppId].
FB.api([PageId]/tabs/[tab_id]', 'post',
{access_token: [page access token], custom_name:[custom tab name]},
function(response){
if(respose == true)
console.info("Successfully done");
}
);
Ok Calle thanks for the confirmation!
I was trying to figure out this too... and it makes sense... That's why when you create a tab programmatically for a page the only parameters are app_id & access_token.
If you try to create an app tab twice on the same page you'll get "true" which in my opinion means that you overwrite last tab you have created.
Facebook adds a signed_request parameter to the request URL of your app. You can decode this parameter to obtain the page ID, among other useful information:
http://developers.facebook.com/docs/authentication/signed_request/

Facebook fan page tab and user id

As per the documentation in the following link, we can get the user id if the uer will interact with the form..
http://wiki.developers.facebook.com/ind … d_Policies
"If a viewing user interacts with the tab (like submits a form, takes an action that causes an AJAX load of new content, or follows a relative URL that loads on the tab), that user's UID is sent to the application as the fb_sig_user parameter, the profile owner's user ID is sent as the fb_sig_profile_user parameter. The viewing user's session key is key is sent only if the user authorized the application. "
In my fan page tab am I have an AJAX form which the user can submit with some value.. now I need the users id also.. how can I get this..
I tried to get the value in my AJAX submit page using $_POST['fb_sig_user'] with no success.. can anyone help me with this please..
You won't be able to get the id of the user using $_POST['fb_sig_user'] unless you authenticate the user by having this in the facebook's ajax function:
ajax.requireLogin = true;
For example, I'm retrieving it fine with this:
function do_ajax(url, div_id)
{
document.getElementById('poller_waitMessage').setStyle('display', 'block');
var ajax = new Ajax();
ajax.responseType = Ajax.FBML;
ajax.onerror = function(error)
{
new Dialog().showMessage("Error:", "Some communication error occured, Please reload the page.","Ok");
};
ajax.ondone = function(data)
{
document.getElementById('poller_waitMessage').setStyle('display', 'none');
document.getElementById(div_id).setInnerFBML(data);
}
ajax.requireLogin = true; // <----- this is important
ajax.post(url);
}
I've been happily using the form variable fb_sig_profile_user for previous apps, and when developing a new app last week, the variable was no where to be found.
Searched for several days, I was about to give up, and then the found answer:
ajax.requireLogin = true;
I understand FB cares about privacy and all, but they really need to announce these kinds of changes before just taking it away.
Million Thanks!

How to Add facebook "Install App Button" on a Fanpage Tab (Based on working example)

For some time now I try to figure out how these guys were able to add "Sign online here" button which is "install App" button on their fan-page tab:
http://www.facebook.com/GuinnessIreland?v=app_165491161181
I've read around the web and couldn't come up with any solid solution. The FBML and FBJS documentation left me with nothing.
So please, if anyone can help me with this.
NOTE: To make multiple tests on the Ajax request that are sent, do not accept the App install. It behaves differently after that.
I had some problems with finding out about it as well. There is no info about this kind of behavior in wiki or anywhere. I got it working after trying some possible solutions and the simplest one is to make user interact with content embedded in fan page tab such as click on something etc. Then you need to post an ajax request with requirelogin parameter to pop up to come out. The simple example would be:
user_ajax = function() {
var ajax = new Ajax();
ajax.responseType = Ajax.RAW;
ajax.requireLogin = true;
ajax.ondone = function(data) {
new Dialog(Dialog.DIALOG_POP).showMessage('Status', data, button_confirm = 'Okay');
}
var url = "http://yourappurl.com/request_handler"
ajax.post(url);
}
And the trigger for it:
Interaction
Then if user is known to be using your application (fan page tab) you can prompt him for additional permission like publish stream or email communication by calling:
Facebook.showPermissionDialog('publish_stream,email');
Hope this solves the problem.