AppiumDriverLocalService auto download chrome - java

I have been trying to get started with appium by integrating it into a bdd framework so i can test a hybrid web app.
However I run into problems when switching the context to "WEBVIEW_chrome" because the correct chromedriver is not installed.
http://appium.io/docs/en/writing-running-appium/web/chromedriver/ states that i should run my local appium instance with the argument "chromedriver_autodownload" so it will always get the correct driver. However when i try to run the AppiumDriverLocalService as
AppiumDriverLocalService service = AppiumDriverLocalService.buildService(new AppiumServiceBuilder().usingAnyFreePort().withArgument(() -> "chromedriver_autodownload"));
service.start
the argument is refused.
All help to get this working is very much appreciated,
Other solutions or pointers to appium services that can help me download the correct chromedrivers automatically are also much appreciated.
I'm running appium 7.3.0 pulled from Maven Central

A friend pointed out i was missing part of the argument.
correct usage:
AppiumDriverLocalService service = AppiumDriverLocalService.buildService(new AppiumServiceBuilder().usingAnyFreePort().withArgument(() -> "--allow-insecure","chromedriver_autodownload"));

I had to use the specified default port to get this to work.
AppiumDriverLocalService service = AppiumDriverLocalService.buildService(new AppiumServiceBuilder().usingPort(4723).withArgument(() -> "--allow-insecure", "chromedriver_autodownload"));

For context switching in Selenium, I have to start as shown below.
appium --chromedriver-executable /Users/$User/Documents/chromeDrivers/103/chromedriver
Is it possible to run the above command by using 'AppiumDriverLocalService' class and 'AppiumServiceBuilder'
? Or Runtime class is the only option?

Related

Appium IOS tests running when server started manually but not when server is started via AppiumDriverLocalService

Attempting to run Appium automation scripts on iOS (simulator) on a Mac Mini (M1 chip, if that's relevant). When I run the tests, they work just fine when the Appium server is started manually (typing "appium" into the terminal and starting it that way). However, when I attempt to start the appium server programmatically, the application under test fails to launch, with the following error:
2021-02-17 03:41:27:256 [W3C] WebDriverAgentRunner-Runner.app (19077) encountered an error (Failed to load the test bundle. If you believe this error represents a bug, please attach the result bundle at /Users/sagolGoru20/Library/Developer/Xcode/DerivedData/WebDriverAgent-gkbkvswlszzhhbevpokpwtrjdxxq/Logs/Test/Test-WebDriverAgentRunner-2021.02.16_22-41-22--0500.xcresult. (Underlying Error: **The bundle “WebDriverAgentRunner” couldn’t be loaded because it doesn’t contain a version for the current architecture. The bundle doesn’t contain a version for the current architecture. Try installing a universal version of the bundle.** dlopen_preflight(/Users/sagolGoru20/Library/Developer/Xcode/DerivedData/WebDriverAgent-gkbkvswlszzhhbevpokpwtrjdxxq/Build/Products/Debug-iphonesimulator/WebDriverAgentRunner-Runner.app/PlugIns/WebDriverAgentRunner.xctest/WebDriverAgentRunner): no suitable image found. Did find:
2021-02-17 03:41:27:256 [W3C] /Users/sagolGoru20/Library/Developer/Xcode/DerivedData/WebDriverAgent-gkbkvswlszzhhbevpokpwtrjdxxq/Build/Products/Debug-iphonesimulator/WebDriverAgentRunner-Runner.app/PlugIns/WebDriverAgentRunner.xctest/WebDriverAgentRunner: mach-o, but wrong architecture))
Here's the full appium log: https://gist.githubusercontent.com/fida10/44344b223874310cf296d38a95d4268f/raw/316855b619129680eeaa6519a446a436d0699cd6/failedLog.txt
I originally thought that this was an issue with xcode or WDA, but if that were the case, the tests would fail no matter how Appium was started, and as mentioned previously, the tests pass perfectly fine when Appium is started manually (via terminal), so it might be an issue with the PATH or environment variables upon execution from Java, not sure though.
Here is the code I am using to start the server programmatically:
HashMap<String, String> environment = new HashMap();
environment.put("PATH", "/usr/local/bin:" + System.getenv("PATH"));
AppiumDriverLocalService server = AppiumDriverLocalService
.buildService(new AppiumServiceBuilder()
.withEnvironment(environment)
.usingDriverExecutable(new File("//opt/homebrew/Cellar/node/15.8.0/bin/node"))
.withAppiumJS(new File("//Users/sagolGoru20/.npm-packages/lib/node_modules/appium/build/lib/main.js"))
.usingAnyFreePort()
.withArgument(GeneralServerFlag.SESSION_OVERRIDE)
.withLogFile(new File("//Users/sagolGoru20/Programming/JavaProjects/MavenProjects/MobileAutomationProjects/firstAppiumProject/appiumLog.txt"))
);
server.start();
As the appium log shows, the server seems to be started fine but then throws the above error, so I think the issue may be with how I'm building the AppiumDriverLocalService object.
I followed this tutorial in building AppiumDriverLocalService: https://appiumpro.com/editions/71-starting-an-appium-server-programmatically-using-appiumservicebuilder
Here is the project code. It's a simple project, I'm just clicking on an "Allow" button (line 26): https://gist.github.com/fida10/bec187a516fc32f907f97725263a7206
When I comment out the AppiumDriverLocalService server object (lines 46 to 58) and instead launch by uncommenting line 60, the test runs properly.
Any help would be greatly appreciated.
Was able to solve it by setting all options under "Build Active Architecture only" to "no", in XCode build settings. Details: https://github.com/appium/java-client/issues/1444#issuecomment-781078298
Hopefully this helps someone trying to run XCUITests on Mac devices with the new M1 chip.

Appium driver is fetching different url than current page url when i switched from native to webview context in iOS appium

When i switched to webview context from native context, some times its
fetching different url than current url, but some times its fetching
correct url
i have put waits, but still same issue is coming
When appium driver fetched different url tests will fail
In iOS app, for webview is developed using WKWEBVIEW
Note: Same webview in android app working properly
I'm unable to identify the problem, Is it a problem of Appium driver or WKWEBVIEW , If any one knows the reason why this problem coming, help me to solve the issue
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("platformVersion", "11.2");
capabilities.setCapability("platformName", "iOS");
capabilities.setCapability("deviceName", "iPhone 7");
capabilities.setCapability("app", ""); // app path
capabilities.setCapability("automationName", "XCUITest");
capabilities.setCapability("instrumentApp", true);//added now
capabilities.setCapability(MobileCapabilityType.UDID, "75C77542-36B8-4E6F-86C7-904237C8CB82");
capabilities.setCapability(IOSMobileCapabilityType.BUNDLE_ID, ""); //a.b.com
capabilities.setCapability("showXcodeLog", true);
capabilities.setCapability("cssSelectorsEnabled", true);
capabilities.setCapability("nativeEvents", true);
capabilities.setCapability("nativeWebTap", true);
return capabilities;
Appium Version: 1.9.1
Appium logs when appium driver switch to different url
appium logs
iOS logs appium
#amit, hi.
I'd recommend here couple options:
1) Could You please share the capabilities you use to initialize a session?
Do you instrument your application?
dc.setCapability("instrumentApp",true)
2) Similar issues have been arised here . Please check the version You're currently using.
There is a new beta out. Please try that (npm uninstall -g appium &&
npm install -g appium#beta).
#imurchie I have confirmed 1.8.2-beta does install v3.12.0 of
appium-remote-debugger and I can successfully switch to webviews! I
will run a full regression on my app and see if I encounter any
issues.
Hope this helps,
please let me know if the issue still persists for You.
3) 2019/03/07 UPDATE
#amit, need to see how You're switching from native to webview in code implementation . In my past project I were using the following approach (based on AppiumDriver):
Set<String> contextNamez = driver.getContextHandles();
for (String singleContext : contextNamez) {
log.info(singleContext); //smth like NATIVE_APP, WEBVIEW_com.example.android etc..
}
String newContext = contextNamez.toArray()[1].toString();
driver.context(newContext);// sets context to WEBVIEW_com.example.android
//Switch back to Native context using
driver.context(NATIVE_APP);
I did a review of You logs. What seems a bit strange for me- is that logs of INFO and DEBUG level . I dont see any errors or exceptions. Could You please double check whether You have any exceptions in adb logcat ?
Thanks in advance,
Eugene

Selenium, Java, Maven, PhantomJS + TeamCity

I've got a project in Selenium/Java with tests that normally run on chromedriver.exe (I work on Windows) - no problems at all.
I have recently decided to add the project to our TeamCity that runs on Linux and since it cannot run tests on a browser, I want to switch to PhantomJS driver.
I've tried multiple variations of all the solutions I've found online and still can't get it working.
Currently I've got the phantomjs binary file in my resources, and I get the driver like this in an enum class:
PHANTOMJS {
#Override
public WebDriver initNewDriver() {
System.setProperty("phantomjs.binary.path", ClassLoader.getSystemResource(RELATIVE_PATH_TO_FILE_IN_RESOURCES).getFile());
return new PhantomJSDriver();
}
Then in the test class I start with driver.get(SOME_URL) - which is the furthest it ever got.
No matter what I do, when I tried to run it on TeamCity through 'clean test', I get something like this:
[userLoginTest] java.lang.IllegalStateException: The driver executable does not exist: /opt/buildAgent1/work/c4641c7cfd3331f7/web/drivers/phantomjslinux/phantomjs
[14:41:41]
[userLoginTest] java.lang.IllegalStateException: The driver executable does not exist: /opt/buildAgent1/work/c4641c7cfd3331f7/web/drivers/phantomjslinux/phantomjs
at com.google.common.base.Preconditions.checkState(Preconditions.java:518)
at org.openqa.selenium.remote.service.DriverService.checkExecutable(DriverService.java:123)
at org.openqa.selenium.phantomjs.PhantomJSDriverService.findPhantomJS(PhantomJSDriverService.java:254)
at org.openqa.selenium.phantomjs.PhantomJSDriverService.createDefaultService(PhantomJSDriverService.java:190)
at org.openqa.selenium.phantomjs.PhantomJSDriver.(PhantomJSDriver.java:104)
at org.openqa.selenium.phantomjs.PhantomJSDriver.(PhantomJSDriver.java:94)
at test.core.base.SeleniumDriver$3.initNewDriver(SeleniumDriver.java:47)
at test.core.base.TestBase.(TestBase.java:25)
I don't really understand TeamCity well and it's difficult to find solutions that are applicable to my project and that I actually understand. So any help is welcome. Thanks :)
Solved by running npm install phantomjs on the server and using PhantomJS from there.

Selenium Tests hang when attempting to be run with Bamboo

I'm attempting to use Bamboo's build and deployment capabilities to run Selenium Automated tests with my project.
We're currently using a Maven task to build and run regular JUNIT tests, and the plan is to use another Maven task to run the Selenium tests after the code has been successfully deployed to the server. At the moment, everything seems to run just fine locally, but when bamboo attempts to run the Selenium tests it seems to hang indefinitely. Unfortunately I don't have remote access to the server to watch it first hand, but I do know that it's a Microsoft server running with OS version: Windows 2012 R2 64-bit. I also know that the server is using java version "1.8.0_101", which is the same as my local setup. I've included a sample of the code I'm running below.
import java.util.concurrent.TimeUnit;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
public class SeleniumTestExample {
WebDriver driver;
#Before
public void setup(){
System.setProperty("webdriver.ie.driver", "src/test/resources/IEDriverServer32bit.exe");
DesiredCapabilities ieCapabilities = DesiredCapabilities.internetExplorer();
ieCapabilities.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, true);
driver = new InternetExplorerDriver(null, ieCapabilities);
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
driver.get("https://google.com");
}
#Test
public void printPageTitle(){
System.out.println("Title of Page is: " + driver.getTitle());
driver.quit();
}
}
When run through Bamboo, the only output in the logs are the lines...
Started InternetExplorerDriver server (32-bit)
2.53.1.0
Listening on port 8080
Only local connections are allowed
CI or Bamboo server should be used for controlling your tests. You should not try to run your tests on a CI server. The issue you are having is probably because of that. Your are trying to use CI server as you local machine, which it will not respond the same way as your local. Instead you should use selenium grid in your setup to remotely connect to a machine by making use of hub and node. You may also have to use remote webdriver. Also have a look at this post
I've seen this using TeamCity, in this case the IE tells you that its executable will only accept connections from the local machine. According to Selenium org
The HTTP server started by the IEDriverServer.exe sets an access control list to only accept connections from the local machine, and disallows incoming connections from remote machines. At present, this cannot be changed without modifying the source code to the IEDriverServer.exe. To run the Internet Explorer driver on a remote machine, use the Java standalone remote server in connection with your language binding's equivalent of RemoteWebDriver.
So first run a chromedriver via passing through a param like so :
chromedriver --whitelisted-ips=""
This will basically whitelist all IP's, not always an ideal solution of course. But will show you that your tests can run on this CI configuration. Next thing to look for is your users privileges. Ask your admin to grant you more permissions in order to do your job. Keep in mind that IE's Protected mode may require some additional changes from your user. If none of this helps, consider Selenium grid with IE nodes.
Try to get rid of the line in the code:
System.setProperty("webdriver.ie.driver", "src/test/resources/IEDriverServer32bit.exe");
First of all, it tells where selenium should look for the webdriver for IE. Since the Bamboo server is a windows machine, you have to set it up with the absolute path of the file, like "C:\test\webdriver\IEDriverServer32bit.exe".
Secondly, the property could be set using environment variables of the Bamboo task.
Thirdly, if you want to define it on the fly, you can define the property in pom.xml as:
<webdriver.ie.driver.path>
C:\test\webdriver\IEDriverServer32bit.exe
</webdriver.ie.driver.path>
and use it in a system property with help of maven-surefire-plugin.
then you can run test with the command
mvn test -Dwebdriver.ie.driver.path=C:\test\webdriver\IEDriverServer32bit.exe
with whatever path you want.

Proxy for selenium rc driver in java

How can i do proxy configuration for selenium in Java?
I am connecting to selenium with:
Process p = Runtime.getRuntime().exec("java -jar lib/selenium-server.jar");
selenium = new DefaultSelenium("localhost", 4444, "*safari", "www.example.com");
I want to configure free proxy without username and password credentials for the same which would be running the selenium application in the safari browser.
I have tried the code below to set proxy for the tests
System.setProperty("http:proxyHost","207.229.122.162");
System.setProperty("http:proxyPort","3128");
but the above code is not working fine !! its even accepting null as arguments ,
Please suggest me some way to resolve the issue !!
Thanks in Advance !!
You can customize run configuration under netbeans. Project Properties -> Run. Regards.
You could add the desired ip to the proxy bypass field in global network settings.
I prefer to define properties from console(using maven) then read it in java:
Define property:
mvn clean verify -Dserver_ip="127.0.0.1" -Dport="4444"
Read in java:
System.getProperty("server_ip");
It's more flexible than hardcoded values in code

Categories