How to target mobile devices to a project - asp.net-mvc

I got solution now in Visual Studio with 2 web projects. One default, and one i would like to target if the user is using a mobile device.
I would like to check if the user is on a mobile device when entering the default site, www.site.com, then redirect to the m.site.com.
How can this be done?

[1]
In ASP.NET, you can easily detect the mobile device request using Request.Browser.IsMobileDevice property and Request.UserAgent.
The following code checks the IsMobileDevice property and redirects to the mobile specific page:
protected void Page_Load(object sender, EventArgs e)
{
if (Request.Browser.IsMobileDevice)
{
Response.Redirec("~/default_mobile.aspx");
}
}
[2]
Another better method is to use open source project called 51Degrees. Here is an article about how to use it in your application.

Related

how to interact with elements embedded in android.webkit.WebView using uiautomator

am working on android automation using appium & robot framework. for this am using robot's appiumlibrary. so i want to automate facebook login secenario in my application, but the problem is the fb login page on app is embedded to an webview. however in uiautomatorviewer able to focusand and find elements, but while running the scripts it throws an error element not found.
what do i need to do in this scenario. i tried to fetch and then switch to context but there was no new or related context available. NATIVE_APP was the only one available.
To see the webview context using driver.context() method WebView debugging should be enabled; developer must enable ‘setWebContentsDebuggingEnabled’ flag in the WebView class. This flag enables debugging of web contents (HTML / CSS / JavaScript) loaded into any WebViews of app. Once this is done driver.context() method will return native and webview both contexts.
Set<String> availableContexts = driver.getContextHandles();
System.out.println("Total No of Context Found = "+ availableContexts.size());
for(String context : availableContexts) {
if(context.contains("WEBVIEW")){
System.out.println("Context Name is " + context);
driver.context(context);
break;
}
}
Note - You cannot do this for third party app like facebook because you may not rebuild that app with webview debugger enabled.

Authentication challenge in Webview component of React Native

I am trying to load a URL in react native webview which needs credentials. Normally when we open this URL in a browser like Safari and Chrome, it give us a popup to enter the credentials. Not sure how to handle it in React-Native?
We require LinkedIn authentication for our React Native application, we couldn't find a way to work with the WebView component.
This may very well be possible, however, I will highlight what solution we came up with. These steps are for an iOS React Native app, steps will differ for Android but the concept is the same. This also does require some server configuration.
We created a URL Type. In XCode, select your project and click on the Info tab. Scroll to the bottom to see URL Types. Fill in the identifier and URL Schemes. Remember what you've set for the URL Schemes. For this example, we will use myscheme.
When the app opens, we use Linking to open up the URL in Safari.
Linking.openURL('https://foo.bar');
The User could then log in via the website, once logged in, you can redirect your User back to.
myscheme://name=Dan
The myscheme matching the URL Scheme you entered within Xcode. As long as you have your application installed and the scheme matches then your app will open.
You can add any payload of information after ://.
In your React application, you can register
componentWillMount() {
Linking.addEventListener('url', this.handleOpenURL);
}
componentWillUnmount() {
Linking.removeEventListener('url', this.handleOpenURL);
}
handleOpenURL = (event) => {
const { url } = event;
if (url.startsWith('myscheme://')) {
// do something with your data.
}
};

How to automate mobile version pages in android app using appium driver

I am testing an android app using appium.
In that few links of app redirect to mobile version pages.
I googled but didn't get proper solution, I wish to know how to locate the elements and perform actions on mobile version pages.
Thanks in Advance....!
It seems you're looking to find information about automating tests for a Hybrid app (Native app that includes WebViews with mobile web content).
The Appium API Reference is a great resource to get basic info about hybrid app automation: http://appium.io/slate/en/master/?java#automating-hybrid-apps
The main difference when working with WebViews is that you'll need to change the context of the webdriver to match with the WebView you wish to inspect or automate. Also note that once going back to inspecting and automating the actual native app, the context should be set back to NATIVE_APP.
// java
// assuming we have a set of capabilities
driver = new AppiumDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
Set<String> contextNames = driver.getContextHandles();
for (String contextName : contextNames) {
System.out.println(contextNames); //prints out something like NATIVE_APP \n WEBVIEW_1
}
driver.context(contextNames.toArray()[1]); // set context to WEBVIEW_1
//do some web testing
String myText = driver.findElement(By.cssSelector(".green_button")).click();
driver.context("NATIVE_APP");
// do more native testing if we want
driver.quit();

Xamarin.Auth with CustomRenderer does not open on Android

I successfully got Oauth2 to work with my localhost implementation using iOS and this Xamarin example: https://github.com/rasmuschristensen/SimpleOAuth
However, using Android, only a blank grey page is displayed. No error messages. I cannot figure out why the:
protected override void OnElementChanged (ElementChangedEventArgs<Xamarin.Forms.Page> e)
event does not get fired in the LoginpageRenderer.cs for Android.
This is the best and most recent Xamarin.Auth sample I found so far. Any ideas?
This issue is now fixed in the new Xamarin.Auth 1.3.

How to define url schemes starting with http ios7

I can define custom schemes like myapp so that third applications can redirect links like: myapp://mypage.com to my app(if user installed it). but I want that third applications open my app if user try to open links like http://mysite/mypage.com too.
Right now we can see that safari open yourtube when we type links like:
http://www.youtube.com/watch?v=WZH30T99MaM
Or map application opens if we type links like:
http://maps.google.com/maps.....
So how can I define a custom scheme that third applications open my apps if user type:
http://a.myapp.com
Short answer: You can't without server support. Apple does tricks that are not available to third party apps to redirect HTTP URLs like Maps and Youtube.
The only way you could do this would be to set up a web server at http://a.myapp.com that redirected to myapp://
Possible workaround, you register your custom URL Scheme and then in your HTML/JS code of the start page of your site you check if the the browser agent is Mobile Safari and forward it to the URL with custom scheme.
You can also check if app is not installed and redirect to AppStore, simply by opening AppStore link with the timeout, so if the redirection attempt to custom URL Scheme link fails you go to to App Store.
<script type="text/javascript">
var app = {
isSafariMobile: function () {
return navigator.userAgent.match(/(iPod|iPhone|iPad)/) && navigator.userAgent.match(/AppleWebKit/)
},
launchApp: function() {
window.location.replace("myapp://");
this.timer = setTimeout(this.openAppStore, 1000);
},
openAppStore: function() {
window.location.replace("https://itunes.apple.com/app/Myapp");
}
};
if (app.isSafariMobile()){
app.launchApp();
}
</script>
UPDATE: The Safari detection method may be slightly adjusted, the ios chrome app could also be detected as Safari by this code as it has WebKit in its UserAgent string on iPhone.

Resources