Appium with ChromeDriver to web view application - c#

I'm new to Appium but I have experience with selenium.
I need to write tests for a web view app.
But when I need to find an element I need to use the UIAutomatorViewer and use it like it's a native app.
Is there a way to use the DOM to navigate like when I'm working with the Chrome browser?
I tried this:
AppiumDriver<IWebElement> driver;
DesiredCapabilities cap = new DesiredCapabilities();
cap.SetCapability("deviceName", "LG - SERVER SERVER's Orange - G3");
cap.SetCapability("apppackage", "com.essence.adlfamily");
driver = new AndroidDriver<IWebElement>(new Uri("http://127.0.0.1:4723/wd/hub"), cap);

Related

How to make selenium open https page, which displayed manually and not displayed while automated run?

Browsing with chrome to web site with htpps connection manually is available and display the site.
Browsing same site by selenium automated test, doesn't display the page, display empty page.
If i load chrome user profile, automation do open the required page.
Other https site (QA) does displayed through automated connection, the problem is with production sites.
Is there any setting can be added to selenium to open the page?
try this if works
HashMap<String, Object> chromePrefs = new HashMap<String, Object>();
chromePrefs.put("profile.default_content_settings.popups", 0);
chromePrefs.put("download.default_directory", downloadFilepath);
ChromeOptions options = new ChromeOptions();
options.setExperimentalOption("prefs", chromePrefs);
options.addArguments("--start-maximized");
options.setExperimentalOption("useAutomationExtension", false);
options.addArguments("disable-infobars");
DesiredCapabilities cap = DesiredCapabilities.chrome();
cap.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
cap.setCapability(CapabilityType.UNEXPECTED_ALERT_BEHAVIOUR,
UnexpectedAlertBehaviour.ACCEPT);
cap.setCapability(ChromeOptions.CAPABILITY, options);
driver.set(new ChromeDriver(cap));
After the issue solved, posting here the solution.
The site wasn't displayed because automation requests were blocked by company WAF (firewall).
The solution on the automation side was to add agent into chrome profile options and on the waf side rule was added for the agent that allows access to the application.
This is example of how the agent added into ChromeOptions class:
ChromeOptions options = new ChromeOptions();
options.AddArgument("--user-agent=automation-client");

Selenium C# integration With Neoload performance testing tool

Could anyone help me to elaborate procedure for integrating selenium C# script with neoload tool.i wanted to integrate selenium C# and Appium C# coding with neoload .So I went though some steps in documentation and unable to run the example code and didn't get the point how we can integrated with selenium/appium C# script with neoload for chrome or any browser and perform load testing for web or mobile application with same tool .Could you please have a look on shared screen shot and help me to share valuable document with any simple example for understanding the concept/getting some confidence.Thanks for giving valuable time
I modified the code found here for the chrome driver: https://www.neotys.com/documents/doc/neoload/latest/en/html/#24364.htm
DesiredCapabilities cap = new DesiredCapabilities();
NLWebDriverFactory.AddProxyCapabilitiesIfNecessary(cap);
object proxyCapability = cap.GetCapability(CapabilityType.Proxy);
ChromeProfile profile = new ChromeProfile();
if (proxyCapability != null) {
profile.SetProxyPreferences(proxyCapability as Proxy);
}
ChromeDriver webDriver = new ChromeDriver(profile);
Your problem is that you need to provide the ChromeDriver with a profile which has the DesiredCapabilities whereas you try to apply them directly to the driver.

Appium : how to test webappication in chrome on windows 10?

I am trying to automate tests for a web application running in chrome on Windows 10 using Appium.
I have code like below that works perfectly fine uses chromedriver. I want to move this to appium based approach.
RemoteWebDriver driver = new ChromeDriver(#"C:\Users\Administrator\Downloads\chromedriver_win32");
driver.Manage().Timeouts().SetPageLoadTimeout(TimeSpan.FromSeconds(60));
driver.Url = "https://www.bing.com/";
RemoteWebElement element = (RemoteWebElement)driver.FindElementById("sb_form_q");
element.SendKeys("webdriver");
element.SendKeys(Keys.Enter);
WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(60));
wait.Until(x => x.Title.Contains("webdriver"));
I searched internet and find a lot of code to test webapplications on chrome on android emulators on windows devices. I did not find any sample that runs chrome browser directly on windows 10.
Based on what i understood, i tried adopting the code by making changes to desired capabilities like below.
DesiredCapabilities caps = DesiredCapabilities.Chrome();
caps.SetCapability(CapabilityType.BrowserName, "chrome");
caps.SetCapability(CapabilityType.Version, "60");
caps.SetCapability(CapabilityType.Platform, "Windows 10");
caps.SetCapability("platformName", "Windows");
//caps.SetCapability("app", #"C:\Users\Administrator\Downloads\chromedriver_win32\Chromedriver.exe");
caps.SetCapability("app", #"Chrome");
caps.SetCapability("deviceName", "WindowsPC");
driver = new RemoteWebDriver(new Uri("http://127.0.0.1:4725/wd/hub"), caps, TimeSpan.FromSeconds(60));
driver.Url = "https://www.bing.com/";
((IWebDriver)driver).Navigate().GoToUrl("https://www.bing.com/");
RemoteWebElement element = (RemoteWebElement)driver.FindElementById("sb_form_q");
element.SendKeys("webdriver");
element.SendKeys(Keys.Enter);
Thread.Sleep(5000);
WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(60));
wait.Until(x => x.Title.Contains("webdriver"));
This however doesn't work.
I think the problem is I am not able to figure out how to set desired capabilities so that appium service running on http://127.0.0.1:4725/wd/hub is able to launch chromedriver and run tests.
Can someone please help point out mistake with the above code?
Appreciate your help.
you need to pass the capabilities of the android phone not the windwos pc as you passes
caps.SetCapability("platformName", "Windows");
Like that and you need to pass the OS version of the emulator or android phone if you are using it..
For reference visit this site you will know everything that you need to know..
http://www.automationtestinghub.com/launch-chrome-browser-on-mobile-device/
Happy to help.. let us know if that solution works for you
As nicely put up here - https://crossbrowsertesting.com/blog/appium/appium-native-web-hybrid-applications/
Appium is an open source test automation frameworktes that drives iOS and Android native, mobile, and hybrid apps using the WebDriver protocol a.k.a. The Selenium API. That’s to say, Appium is like Selenium’s cousin, and used for testing mobile apps instead of web applications in desktop browsers.
Per the discussion here - https://discuss.appium.io/t/can-appium-automate-desktop-web-browsers/746/5 too it seems appium is for testing on mobile devices only.

Selenium Firefox does not open when called from MVC app deployed on IIS

I'm trying to run below code within a controller in Asp.net MVC 5:
var driver = new FirefoxDriver(firefoxOptions);
It works when I'm using IIS Express, but the browser is not opened when I'm using IIS. Do we need to do something in IIS setting to make it work?
Try using RemoteWebDriver rather than FirefoxDriver
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.SetCapability(CapabilityType.BrowserName, "firefox");
string serverURL = "http://localhost:4444/wd/hub";
driver = new RemoteWebDriver(new Uri(serverURL), capabilities);

C# chrome driver only opening as background process on IIS / Windows Server 2016

I am running chromedriver on windows server 2016 with IIS, i have my test project installed and invoking it with an MVC5 API. That all seems fine but chromedriver and chrome.exe only seems to open as a background processes.
The same code opens these fine locally, i am not using any of the driver flags for headless browsing either. if i return the drive page source i can see that chromedriver went to google and returned the correct html in my API.
It just does not work for normal / non headless tests with google or our application.
var driver = x.StartWebDriver();
driver.Manage().Window.Maximize();
driver.Navigate().GoToUrl("http://www.google.com");
return driver.PageSource;
Any ideas?
I have got the same issue and this is how I solve this:
Open a command prompt and navigate to your ChromeDriver location.
Execute chromedriver.exe and you will see the message as below.
image here
In the image above you see chrome driver is listening on port 9515.
Now change your code as below, rebuild and call you api to execute your test.
ChromeOptions options = new ChromeOptions();
//set your chromeoptions here
Uri uri = new Uri("http://localhost:**9515");
_driver = new RemoteWebDriver(uri, options);
Open the chrome driver and note the port number(eg:5353)
In java:
System.setProperty(chromeDriverName, chromeDriverLocation);
ChromeOptions options = new ChromeOptions();
URL uri = new URL(chromeDriverPort);//http://localhost:5353
WebDriver driver = new RemoteWebDriver(uri, options);
your problem gets solved in is server.

Categories