Testing UIWebView with Xcode UI Testing - uiwebview

I'm using new Xcode UI Testing from XCTest Framework with the Xcode 7 GM. I've got an app with simple UIWebView (it's just a navigation controller + view controller with web view and button) and I want to check following scenario:
Web View loads page www.example.com
User taps on button
Web View loads some page with URL: www.example2.com
I want to check which page is loaded in UIWebView after pressing button. Is this possible with UI Testing right now?
Actually I'm getting web view like this:
let app:XCUIApplication = XCUIApplication()
let webViewQury:XCUIElementQuery = app.descendantsMatchingType(.WebView)
let webView = webViewQury.elementAtIndex(0)

You won't be able to tell which page is loaded, as in the actual URL that is being displayed. You can, however, check assert content is on the screen. UI Testing provides a XCUIElementQuery for links that works great with both UIWebView and WKWebView.
Keep in mind that a page doesn't load synchronously, so you will have to wait for the actual elements to appear.
let app = XCUIApplication()
app.launch()
app.buttons["Go to Google.com"].tap()
let about = self.app.staticTexts["About"]
let exists = NSPredicate(format: "exists == 1")
expectationForPredicate(exists, evaluatedWithObject: about, handler: nil)
waitForExpectationsWithTimeout(5, handler: nil)
XCTAssert(about.exists)
XCTAssert(app.staticTexts["Google Search"].exists)
app.links["I'm Feeling Lukcy"].tap()
There is also a working test host that goes along with the two links if you want to dig into the code.

If the title of the pages are different, you can check for the title of the web page.
let app = XCUIApplication()
app.launch()
//Load www.example.com
//Tap on some button
app.links["Your button"].tap()
//Wait for www.example2.com to load
let webPageTitle = app.otherElements["Example2"]
let exists = NSPredicate(format: "exists == 1")
expectationForPredicate(exists, evaluatedWithObject: webPageTitle, handler: nil)
waitForExpectationsWithTimeout(5, handler: nil)

Related

Browser Back Button - Breaking onClick event

I have a repeat control setup which contains a table. The table row(s) contain information from an entry in a view. When the user clicks on the entry, it will redirect them to another xPage which contains the information pertaining to the item they clicked.
I noticed that if you click the browser back button (in this case mobile iPhone Safari), it will redirect you to the previous page, but the onClick events do not fire if you click a row in the repeat control.
I'm not exactly sure what is causing this to break, but has anyone run into this in the past or have any idea no what may fix this issue?
var entry:NotesViewEntry = data;
var docId = entry.getDocument().getUniversalID();
var url = context.getUrl().getAddress().replace(view.getPageName(), '');
context.redirectToPage(url + "/xCall.xsp?documentId=" + docId + "&action=openDocument");
Edit:
The issue appears to only occur when using mobile Safari (for iPhone). It works fine in Chrome/Internet Explorer.
Another interesting detail, if you click on an item and it redirects you to a page, then you click the browser back button, you can click on the repeat control and nothing happens. However if you way 15-20 seconds and then click, it works like expected. If you click anytime before 15-20 seconds, nothing happens
Second Edit:
I ended up coming across this link: https://github.com/christophery/pushy/issues/51 which described a problem where the browser back button was creating weird behavior. I ended up using the following code which seems to have fixed the issue.
// for jQuery
$(window).bind("pageshow", function(event) {
if (event.originalEvent.persisted) {window.location.reload();}
});
// for regular JS
window.onpageshow = function(event) {
if (event.persisted) {
window.location.reload()
}
};
This might be caused by the browser caching the previous page. Add this to the beforePageLoad event of your XPage in order to tell the browser not to cache the page:
<xp:this.beforePageLoad><![CDATA[#{javascript:
// Do not cache the HTML pages in the browser
var exCon = facesContext.getExternalContext();
var response=exCon.getResponse();
response.setHeader("Cache-Control", "no-cache");
response.setHeader("Cache-Control", "no-store");
}]]></xp:this.beforePageLoad>

Prevent loading popup in mobile

I have override the CustomerID's Field Updated event in Sales Order page that displays a popup with the custom field UsrCustomerNote for update purpose. It is working fine on web. But, the thing is I want to prevent popup in acumatica mobile app. How do I do this? Here is the code that loads the popup.
BAccountEnq bAccountEnq = PXGraph.CreateInstance<BAccountEnq>();
BAccount bAccount = PXSelect<BAccount, Where<BAccount.bAccountID, Equal<Required<BAccount.bAccountID>>>>.Select(bAccountEnq, row.CustomerID);
var customerNote = (string)bAccount.GetExtension<PX.Objects.CR.BAccountExt>().UsrCustomerNote;
if (!string.IsNullOrEmpty(customerNote))
{
if (CustomerSelector.AskExt(
delegate
{
CustomerSelector.Current.GetExtension<PX.Objects.CR.BAccountExt>().UsrCustomerNote = customerNote;
CustomerSelector.Cache.Update(CustomerSelector.Current);
}) == WebDialogResult.OK)
{
IsOKToUpdate = true;
}
}
Here is how it looks on web:
And, here is the error that is caused by popup.
I want this customization on web but not on mobile keeping the Base method for Field Updated event. I mean like not completely disabling the event but only preventing popup to load if it's in mobile.
Thanks!
In your graph extension, check for the flag Base.IsMobile. You could use that to branch your logic

How to hide the application bar in a Windows Phone 8.1 (WinJS) app?

I have a single AppBar declared in default.html for use throughout my application.
On some of the pages I need to show the App Bar and in some of the I need to hide the AppBar.
So far, my efforts to find the methods to hide and show the AppBar have met a dead end.
The documentation on MSDN says:
AppBar.hide method :
Hides the app bar on Windows and the secondary command menu on Windows Phone.
So, that method only hides the AppBar for Windows and not for a Windows Phone project.
I have also tried giving display:none as a CSS style, to no effect.
Any help will be appreciated :)
AppBar.Hide hides the secondary command bar on Windows Phone, not the main AppBar. If you want the entire AppBar to go away then this isn't the right property.
The easiest way is to declare the AppBar on pages that you want to show it and to leave it out on pages that you don't want it, but you should be able to hide it by disabling the AppBar on pages that you don't want it on.
I just modified the appbar-commands.js file in the HTML AppBar control sample as follows and the appbar hides and shows as I click the hide and show buttons:
// These functions are used by the scenario to show and hide elements
function doShowItems() {
document.getElementById('commandsAppBar').winControl.disabled = false;
//document.getElementById('commandsAppBar').winControl.showCommands([cmdFavorite, cmdCamera]);
document.getElementById('scenarioShowButtons').disabled = true;
document.getElementById('scenarioHideButtons').disabled = false;
}
function doHideItems() {
document.getElementById('commandsAppBar').winControl.disabled = true;
//document.getElementById('commandsAppBar').winControl.hideCommands([cmdFavorite, cmdCamera]);
document.getElementById('scenarioHideButtons').disabled = true;
document.getElementById('scenarioShowButtons').disabled = false;
}
I also confirmed with the single-page navigation model navigating between two pages. If you aren't seeing the appbar hide and show when disabled and enabled then make sure you are calling the code to disable / enable the appbar. The PageControl's ready function may not be called when returning to a cached page.
You'll have to do it with C#, You can simply just type.. (If your appbar is called ApplicationBar)
ApplicationBar.Visibility = Visibility.Collapsed;
This will instantly hide the AppBar! If you want your HTML Page to perform this action, it will be much complicated.
Cheers
I think you can try below step in your code.
Add a event listener for appbar beforeshow
In code of before show Check a condition with specific page name
Like : if (WinJS.Navigation.location.match("test.html"))
According to you condition you can Disable your appbar.
All the best..!!

UIWebView and UIPageViewController

I have html content which is displayed using UIWebView. User navigate pages using UIPageViewController. The problem is that the web view completes rending the content after the page is displayed. There is noticeable delay makes the performance sluggish.
- (ContentViewController *)viewControllerAtIndex:(NSUInteger)index andPageIndex: (NSUInteger)pageIndex{
if (([self.pageData count] == 0) || (index >= [self.pageData count])) {
return nil;
}
Topic * topic = (Topic *)[pageData objectAtIndex:index];
ContentViewController * contentViewController = [[ContentViewController alloc] init];
[contentViewController setCurrentTopic:topic];
[contentViewController setCurrentPageIndex:pageIndex];
return hadeethViewController;
}
The Content View Controller will not render the content unless it is really loaded by the PageViewContoller. Is there any way to enforce the view to load before the viewControllerAtIndex returns? Or is there any solution for such situation?
UIWebView can load content while not on screen. I'm guessing your issue is that your webview gets initialized only after your ContentViewController has been initialized. If you already know which HTML files will be loaded as your user pages through the content you can preload them as necessary in off-screen UIWebViews before creating the ContentViewController and add the corresponding, pre-loaded UIWebView to the content view controller.

Animated Icon During Web page loading

I am creating an iOS app that displays a web view. How can I show an animated busy icon that shows a webpage is still loading. The icon should of course disappear when the webpage is fully loaded. An example code would be nice to have.Thanks
OK, I figured out my own problem. For those of you who might want to know how to do this... UIWebView has a protocol called UIWebViewDelegate Protocol naming some methods that can be implemented optionally. To show an animated icon in the status bar while a web page is loading, simply implement the webViewDidStartLoad method. Something like this...
- (void)webViewDidStartLoad:(UIWebView *)webView {
// starting the load, show the activity indicator in the status bar
[UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
}

Resources