Selecting web element with id in appium test started using AndroidDriver - c#

I'm new to Appium and testing as a whole. I used Android driver to test an app in android.
I can handle all clicks and typing in the app. But the issue arises while using the OAuth service to log in the app.
I use the following Driver client. appium dotnet driver
The login service opens in a separate chrome browser. I have to type text in an input element inside the web page.
I use the following code. On debugging page resource only has the android elements of the chrome browser and nothing of the web content.
var appiumDriver = new AndroidDriver<AndroidElement>(driverUri, appiumOptions);
[Test()]
[Order(1)]
public async Task TestLogin()
{
try
{
appiumDriver.FindElementByAccessibilityId("Login").Click();
await Task.Delay(3000);
var source = appiumDriver.PageSource;
var element = appiumDriver.FindElementById("login-email");
}
catch (NoSuchElementException ex)
{
}
}
Can anyone suggest how to proceed with this problem? This also has to be done in iOS, I guess both can be handled the same way.. Thanks in advance.

The issue was not changing to web context for searching in web page. The test flow had to be
Perform action to open the web page from the app. (In my case clicking login button)
Wait till the web page appears. (This is important as the web context will be available only after the web page appears) For this, I used a FindElementByClassName for a unique control visible in the web page but not on the previous App page. There sure can be a better way.
Get available contexts and switch to web context.
I used FindByCssSelector for finding the element with id.
Changing to web context
public static void ChangeToWebContext()
{
if (driver.Context != "NATIVE_APP")
return;
var elements = driver.FindElementByClassName("android.widget.EditText");
var availableContext = driver.Contexts;
if (availableContext.Count >= 2)
{
driver.Context = availableContext[1];
return;
}
}
Usgae:
this.ChangeToWebContext();
driver.FindElementByCssSelector("#login-password");

Related

Set User Agent in Playwright is not working

I am trying to set the user agent of playwright browser while initializing the browser context but it seems that it ignores the param I am giving and starts it with the default agent
could anyone point out what is the problem here?
version : playwrightSharp v0.180.0
private static Task<IPage> InitializePlayWrightPage()
{
var page = MarketsHelper.browser.NewPageAsync(userAgent:Guid.NewGuid().ToString());
return page;
}

C# web browser tab text

Hello i have been creating a web browser for college. The problem that i have that is driving me insane is trying to get current web browser page i am ons text in the tab like if i am on Google i would like to say it in the tab.
i tried
private void addTextImageTab()
{
try
{
mainBrowserTC.SelectedTab.Text = getCurrentWB().Document.Url.ToString();
}
catch
{
MessageBox.Show("Error");
}
}
and my getCurrentWB() method is
private WebBrowser getCurrentWB()
{
return (WebBrowser)mainBrowserTC.SelectedTab.Controls[0];
}
Every time i try to run it it crashes i tried every thing that i know and search the web the last few days and could find a solution please help.

Telerik Reporting Loading of ExternalStyleSheet xml from an Action Url not Authenticated

I created a Telerik report from a separate project.
I have report viewer from my ASP.NET MVC project to load the report.
Here is the code:
private ViewResult ReportViewer(Report report)
{
report.ExternalStyleSheets.Clear();
var serverUrl = UrlExtension.BaseUrl();
var relativeUrl = Url.Action("ReportStyleSheet", "Theme");
var url = string.Format("{0}{1}", serverUrl, relativeUrl);
var styleSheet = new ExternalStyleSheet(url);
report.ExternalStyleSheets.Add(styleSheet);
return View("ReportViewer", report);
}
The action ReportStyleSheet from the Theme controller requires authentication
After successful login and try to view the report, The report can't access the /Theme/ReportStyleSheet. But when I run the Url from the browser its authenticated. How can I resolve this issue?
Its using Form Authentication.
When trying to pass MemoryStream to ExternalStyleSheet constructor, an error occurred that says An error has occurred while processing Report 'MyReport': Buffer cannot be null. Parameter name: buffer . I am sure that the stream was passed. Here is the screenshot:
Make sure you have configured Authentication in web.config file to avoid application ambiguity. Types of Authentications will be found here. Just note that you have not another enabled authentication.
Please take a look at ExternalStyleSheet documentation. It is not well written but to me it seems that the stylesheet is loaded immediately after you call
var styleSheet = new ExternalStyleSheet(url);
Therefore it is called by web server (app pool user that your web pages runs under). This user is not authenticated and that is the cause of your problems.
I would suggest you take the stylesheet to a location that does not require authentication or that you use another overload of ExternalStyleSheet constructor that does not load from Uri.
Based on your screenshot and the following conversation in comments I have created similar class
public class MyReport : Telerik.Reporting.Report
{
public MyReport(string stylesheet)
{
this.ExternalStyleSheets.Clear();
using (System.IO.Stream s = new System.IO.MemoryStream(File.ReadAllBytes(stylesheet)))
this.ExternalStyleSheets.Add(new ExternalStyleSheet(s));
}
}
It works. Maybe you should use System.Text.Encoding.UTF8.GetBytes(styles) or load the stylesheet from file. Maybe it has something to do with your stylesheet encoding. Mine was utf-8.

AjaxMethods in Windows Azure not working

We are showing reports in our Azure web application using ReportViewer (rdlc) control in VS2010 which is working perfectly. Recently my client asked me to capture the the Print event for ReportViewer and log an entry on the server. I've hooked the with the print button.. This works perfectly when I run the web application on a local environment. However, on Azure, the Ajax method never gets called from client side. Please suggest what to do? Is there a limitation for Ajax in Azure Environment?
I'm registering the Page on Page_Load in code behind
protected void Page_Load(object sender, EventArgs e)
{
Ajax.Utility.RegisterTypeForAjax(typeof(Pages.Report));
ImageButton btnPrint = new ImageButton();
btnPrint = ((ImageButton)(this.FindControl("ctl00$" + ReportViewer1.ClientID.Replace("_","$") + "$ctl06$ctl06$ctl00$ctl00$ctl00")));
btnPrint.Attributes["onclick"] += "attachEventForPrint();";
}
[AjaxMethod(Ajax.HttpSessionStateRequirement.ReadWrite)]
public static void LogEvent(int pLoggingEvent)
{
// Addded logic to log event
}
And in ASPX file following function was added in JS
function attachEventForPrint() {
if (typeof (Report) != "undefined") {
Report.LogEvent(4);
}
}
The good news is that I don't think there's any limitation with using ajax controls - I've used a few and they just worked.
Some things to check might be:
can you use Fiddler to view the HTTP trace - is a request being sent to the server when you click on the the print button?
can you use a javascript debugger to check that there are no errors being reported when attachEventForPrint occurs?
are there any issues here with "State" - especially with Session storage?
One other thing to check is whether there is a more maintainable way to access the print button - the "$ctl06$ctl06$ctl00$ctl00$ctl00" just looks like it is asking for trouble either now or at some point in the future

Enable DOM Access for Silverlight Web Part in Sharepoint 2010

I am hosting a silverlight 3.0 control on my Sharepoint 2010 page. I am using the built-in SilverlightWebPart web part, where I have provided the path for .xap file.
Its displaying properly, but when I try to access the System.Windows.Browser, its throwing an error. My code is:
public static string GetQueryString(string key)
{
try
{
var documentQueryString = (Dictionary<string, string>)System.Windows.Browser.HtmlPage.Document.QueryString;
if (documentQueryString.ContainsKey(key))
{
return documentQueryString[key].ToString();
}
}
catch (Exception ex)
{
return ex.Message;
}
return string.Empty;
}
The error I am getting is: The DOM/scripting bridge is disabled. How do I enable this? I know if I host this in a ASP.NET page, I can add the param - <param name="enablehtmlaccess" value="true"/>. I have tried putting this webpart in a "content editor web part", and I have embedded the object tag to call the .xap file and its working totally fine. I need to make it work using the built-in Silverlight web part.

Categories

Resources