How to assert that a link to another application in a new browseris is correct? - watir

The AUT has links along the top navigation bar. During normal use, each link opens a related application in a different browser.
Is it possible to do a simple page title assertion on the new application, then return to the AUT and click the next link? And so on for each link?
For testing, I don't think it matters whether the link target opens in a new browser, or a new tab, or the same tab. As long as I can jump back and forward between the AUT and the "other" application.

Without sample HTML, this is a bit of a shot in the dark. But--assuming there's a distinct attribute to hook onto--you can collect the links from the navigation div and iterate over each link. This is a simple, contrived example (where the links do not spawn new browsers/tabs):
b = Watir::Browser.new
b.goto("http://www.iana.org/domains")
nav_link_hrefs = b.div(:class, "navigation").links.collect { |link| link.href}
nav_link_hrefs.each do |href|
next if href == "http://www.iana.org/domains" # skip self-referential link
b.link(:href => href).click
b.back
end
In terms of doing a "simple page title assertion", I'm not sure how you'd know the page title in advance. But I'd suggest looking into MiniTest or rspec for an assertion library.
Lastly--if window-switching is required for your use case--check out the watir-webdriver window-switching documentation.

I found the answer. Here's the partial code:
#browser.goto URL
current_url = #browser.url
new_window_url = #browser.link(:text, "Other site").href
#browser.goto(new_window_url)
# test the other site
assert(#browser.text.include?("This is the other site"))
#browser.goto(current_url) # back to the first site
# repeat for all the other navigation links

Related

Display pagination number on page title

Currently, I have an issue about display pagination title in Shopware, template use Twig, load pagination pages by ajax, multi languages use snippet.
Detail:
The pagination title that need to be displayed: Page "X". X is page number.
The site used multi languages site, ex: english (Page "X"), german (Seite "X") ...
For default url (ex: abc.com/category-name) or page = 1 (ex: abc.com/category-name/?p=1): Not display pagination title.
For other pages (page 2, 3, 4): Display Page 2 ...
Page items will be loaded by use ajax when click the page number.
So, I don't know what to do display the pagination title on page title with multi languages.
Can everyone help me to resolve this issue?
Thank everyone.
You can hook into this method:
ListingPaginationPlugin.onChangePage (see the source code in vendor/shopware/storefront/Resources/app/storefront/src/plugin/listing/listing-pagination.plugin.js)
And after calling the parent method, insert - for a proof of concept - code like this:
document.title = event.target.value;
This would simply show the page number in the title (but losing the original title)
I suggest you back-up the original title and just append the "Page X" / "Seite X" information to it according to your necessary logic.
Now you need the translated word for "Page" available in the Javascript code.
You could attach this as a data-attribute to the title tag in the according twig template and use the normal `|trans' filter. I am not sure if there is a better way to have translations available in Javascript code in Shopware, so I asked.

Kentico custom page url with URL "Path or Pattern" feature

Updated: As I put in the comment under Brenden's response. I think the issue is not related to multilingual site, but it's with using Properties/ URLs / Path or Pattern feature. After adding value to the field Path of Pattern, the whole navigation stops working properly.
I have a multilingual site (English, French). Currently the URLs are like below:
English: www.domain.com/en-us/contact-us
French: www.domain.com/fr-fr/contact-us
What I want for French is a custom (translated) url www.domain.com/fr-fr/contactez-nous
I followed this Kentico instruction - the bottom part of the page with using Path or Pattern by adding /contactez-nous in the box. Things seem ok, but upon clicking on the page with the new URL on the French site, the whole main navigation (done with Hierarchical Viewer) seems to stuck with that URL; clicking anywhere on the nav doesn't do anything.
Links outside the nav works fine. How to make the nav work again. Thanks for your help!
I think I got it. The GetDocumentURL() is using NodeAliasPath to determine the URL. However, if you have not specified the NodeAliasPath column in the Columns property of the hierarchical viewer, then the current page's NodeAliasPath is used - and thus all items have the same URL. Adding the NodeAliasPath to the Columns property should fix the issue, so the hierarchical viewer has access to the data of each individual item.
EDIT: it looks like that in some cases the DocumentURLPath column must be specified too.
Make sure you're testing this in another browser or even another browser in a private window. If you are testing in a new tab in the same window, the CMS caches the selected language in the Kentico UI and shows that in the browser window.
For instance, if you have selected "French" on the pages app in the bottom left under the content tree, then navigate to your site in a new tab, it will display French no matter how many times you change the language selector on your public site to a new language.
Secondly, check the URL aliases for the given pages in each language. Make sure you don't have an alias that is the same in each language. For instance /contact-us with French and /contact-us in English.

node-phantom handle hyperlink of iframe fail

Recently, i integrate node and phantomjs by phantomjs-node. I opened page that has iframe element, i can get the hyperlink element of iframe, but failed when i execute click on it.
Do you have a way? Anyone can help me?
example:
page.open(url);
...
page.evaluate(function(res){
var childDoc = $(window.frames["iframe"].document),
submit = childDoc.find("[id='btnSave']"),
cf = submit.text();//succeed return text
submit.click()//failed
return cf;
},function(res){
console.log("result="+res);//result=submit
spage.render("test.png");//no submit the form
ph.exit();
});
You can't execute stuff in an iframe. You can only read from it. You even created a new document from the iframe, which will only contain the textual representation of the iframe, but it is in no way linked to the original iframe.
You would need to use page.switchToFrame to switch to the frame to execute stuff on the frame without copying it first.
It looks like switchToFrame is not implemented in phantomjs-node. You could try node-phantom.
If the iframe is on the same domain you can try the following from here:
submit = $("iframe").contents().find("[id='btnSave']")
cf = submit.text();
submit.click()
If the iframe is not from the same domain, you will need to create the page with web security turned off:
phantom.create('--web-security=false', function(page){...});

Using Watir How can i visit all the links of a web page and then sub links of the visited link

strong textI have a web page that is containing several links on it, and when we click on any link it redirect to another page that is also containing several links, like wise all links have several pages.
I want to click on all the links and when i click on first link script should click on all the links of redirected page and so on.. when it done the clicking on the links, again second links link of the first page should get clicked like wise for links.
Please any one can help me on this, I have developed the script by which I am able to click on all the links of main(first) page but not getting idea how to do that for sub pages of the application.
Please revert ASAP, its very urgent.
You just have to implement some recursive function like this:
def crawl(link)
browser.goto link
# gather all links before navigating to next link
all_links = browser.links.reduce([]) do |memo, link|
memo << link if link.href =~ /appdomain/ # do not visit external links
memo
end
all_links.each do |link|
crawl link
end
end
crawl "http://appdomain.com/"
This is untested code, but it might work :)
Also this code does not avoid clicking link to same path twice from different places - there's room for optimization.
It might be that you're using wrong tool for your job - at least it seems so when reading your question. What is the original problem?

Change Edit Control Block (ECB) Link URL in SharePoint

Is there a way to dynamically change the hyperlink associated with an ECB menu in WSS 3.0? For instance, I have a list with 2 fields. One field is hidden and is a link, the other is the title field which has the ECB menu. The title field currently links to the item's view page - but we want it to link to the link-field's url. Is that possible?
UPDATE - 5/29/09 9AM
I have this so far. See this TechNet post.
<script type="text/javascript">
var url = 'GoTo.aspx?ListTitle='+ctx.ListTitle;
url += '&ListName='+ctx.listName;
url += '&ListTemplate='+ctx.listTemplate;
url += '&listBaseType='+ctx.listBaseType;
url += '&view='+ctx.view;
url += '&';
var a = document.getElementsByTagName('a');
for(i=0;i<=a.length -1;i++)
{
a[i].href=a[i].href.replace('DispForm.aspx?',url);
}
</script>
This gives me a link like so (formatted so it's easier to see):
GoTo.aspx
?ListTitle=MyList
&ListName={082BB11C-1941-4906-AAE9-5F2EBFBF052B}
&ListTemplate=100
&listBaseType=0
&view={9ABE2B07-2B47-4390-9969-258F00E0812C}
&ID=1
My issue now is that the row in the grid gives each item the ID property above but if I change the view or do any filtering you can see that the ID is really just the row number. Can I get the actual item's GUID here?
If I can get the item's ID I can send it with the list ID to an application page that will get the right URL from field in the list and forward the user on to the right site.
I think the easiest solution and one I use regularly to modify default sharepoint functionality without having to install server side code is to inject some javascript onto the page to make the necessary modifications.
The Content Editor webpart is ideal for this if you don't want to edit the page source itself. Together with the IE Developer Toolbar or Firebug to inspect the elements you want to edit you should be able to achieve what you need with just a couple of lines of javascript.
Let me know if you need any further detail on getting this work.
The title/link to edit menu is a computed field - basically a combination of the title and item id. If you look at the definition of the field (off the top of my head I think it's in fields.xml) you should be able to create a modified version in your schema.xml that uses the url field in its RenderPattern.
Following up on Tom's answer, you can use the SharePoint Solution Generator in VseWss 1.3 to generate a Visual Studio solution that can re-create your list. You will faint when you see the huge amount of XML that the views use in the schema.xml file but you will see the render pattern that Tom referred to and you should be able to get a general idea of how to modify it to suit your needs.
Gotta love SharePoint. Where small customizations means "take what I give you or rewrite it from scratch"

Resources