Appium TouchAction/ MultiTouchAction don't work when testing Mobile Web - selenium

I'm trying to set up an automated test for a mobile website using Appium 1.2.4, Java-client 2.0.0, Selenium 2.42.2 and a real device (Samsung Galaxy Tab-3).
The problem is that, whenever I'm trying to use Touch Actions (e.g. driver.swipe() or driver.pinch()) I'm getting a Not Yet Implemented … error.
I've tried to improvise by switching the driver context to NATIVE_APP before executing the TouchAction and yet it still didn't work (I get a different error: An unknown server-side error occurred while processing the command).
Would appreciate your kind advice.
Configuration:
Selenium 2.42.2 Java-client 2.0.0 Appium 1.2.4
Device:Galaxy Tab3
OS: Android 4.4.2
Browser: Chrome 38
Thanks and Best Regards,
Daniel.
DesiredCapabilities capability = new DesiredCapabilities();
capability.setCapability("device","ANDROID");
capability.setCapability("app", getValidBrowserName(browser));
capability.setCapability("newCommandTimeout",150);
capability.setCapability("platformName", "Android");
capability.setCapability("deviceName", "GalaxyTab3");
capability.setCapability("platformVersion", "4.4.2");
RemoteWebDriver driver = null;
Platform currentPlatform = desiredCapabilities.getPlatform();
boolean isMobilePlatform = currentPlatform.equals(Platform.ANDROID) || currentPlatform.equals(Platform.MAC);
URL hubURL = new URL(hubHost + "/wd/hub");
try {
driver = isMobilePlatform ? new AndroidDriver(hubURL, desiredCapabilities) : new RemoteWebDriver(hubURL, desiredCapabilities);
driver.manage().timeouts().implicitlyWait(waitTimeout, TimeUnit.SECONDS);
driver.manage().timeouts().setScriptTimeout(scriptTimeout, TimeUnit.SECONDS);
driver.setFileDetector(new LocalFileDetector());
}
catch (Exception e) {
throw new Exception("Failed to create Selenium WebDriver instance on hub: "
+ hubURL.toString() + " with capabilities: "
+ desiredCapabilities.toString() + "\n"
+ e.getMessage());
}
WebElement buttonTest = driver.findElement(By.id("configBtn"));
int buttonX = buttonTest.getLocation().getX();
int buttonY = buttonTest.getLocation().getY();
((AppiumDriver)driver).swipe(buttonX, buttonY, buttonX + 70, buttonY + 70, 1000);

Related

How to test Electron app using selenium and java

Hi Im having an issue with testing an electron app. Up until last week our product was ran on chrome. But now the product has been changed to an electron desktop app and when launched the window isnt picked up.
The flow is basically I open the product on chrome and it appears as a pop up. Previously this was just a chrome pop up but now its an electron app. And now i cnat seem to switch to this window. Im wondering is it possible to switch between the two or do i need a different driver and just test he electron app by itself?
My driver factory is shown here
public class DriverFactory {
private static WebDriver driver;
public static WebDriver startDriver() {
String projectLocation = System.getProperty("user.dir");
// add in elements for logging into the mobile application also - Android and
// iOS.
if (OSValidator.isMac()) {
System.setProperty("webdriver.chrome.driver", projectLocation + "/chromedriver_mac");
} else if (OSValidator.isWindows()) {
System.setProperty("webdriver.chrome.driver", projectLocation + "/chromedriver.exe");
} else {
System.setProperty("webdriver.chrome.driver", projectLocation + "/chromedriver_linux");
}
if (System.getProperty("app.env") != null) { // If coming from Jenkins/Maven goal..
// This is for logging results. Added when investigating crashes on chrome driver. Can be disabled when not needed. 26/03/2020
System.setProperty("webdriver.chrome.verboseLogging", "true");
}
unknown-error-devtoolsactiveport-file-doesnt-exist-while-t
ChromeOptions options = new ChromeOptions();
options.addArguments("start-maximized");
options.addArguments("disable-infobars");
options.addArguments("--disable-extensions");
options.addArguments("--window-size=1920x1080");
options.addArguments("--disable-cache");
//options.addArguments("--headless");
options.addArguments("--disable-application-cache");
options.addArguments("--disk-cache-size=0");
options.addArguments("--disable-gpu"); // applicable to windows os only
options.addArguments("--disable-dev-shm-usage"); // overcome limited resource problems
options.addArguments("--dns-prefetch-disable");
//options.addArguments("--no-sandbox"); // Bypass OS security model
options.setPageLoadStrategy(PageLoadStrategy.NORMAL);
driver = new ChromeDriver(options);
//--------------------
return driver;
}
}
It is described here.
https://applitools.com/blog/automating-electron-applications-using-selenium/
You just need to set appropriate options and use same code for the chrome and electron.
#Before
public void setup() {
ChromeOptions opt = new ChromeOptions();
opt.setBinary("/Users/yanir/Downloads/Electron API Demos.app/Contents/MacOS/Electron API Demos");
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("chromeOptions", opt);
capabilities.setBrowserName("chrome");
driver = new ChromeDriver(capabilities);
if (driver.findElements(By.id("button-about")).size() > 0)
driver.findElement(By.id("button-about")).click();
}

Selenium (chromedriver) in MAC

I have the following problem/question:
I was with notebook automation. Now I bought an ultrabook MAC.
I did all the project import with automation, all right. However, when I run it, I get the following error:
java.lang.IllegalStateException: The driver executable does not exist: /Users/estevaomarcos/Documents/Projetos/DBServer/\Users\chromedriver
In my code is the following:
System.setProperty("webdriver.chrome.driver", "\\Users\\chromedriver");
WebDriver browser = new ChromeDriver(); .....
Set Driver Path: To avoid manual checking for the operating system we can get the file separator symbol from the system property using the file.separator key.
System.setProperty("webdriver.chrome.driver", "Users" + System.getProperty("file.separator") + "chromedriver");
WebDriver browser = new ChromeDriver();
browser.get("test.com");
Setting driver path based on which Operating System(OS) we are running on.
String os = System.getProperty("os.name").toLowerCase();
WebDriver driver = new ChromeDriver();
if(os.contains("mac")) {
System.setProperty("webdriver.chrome.driver", System.getProperty("usr.home") + System.getProperty("file.separator") + "chromedriver");
}else {
System.setProperty("webdriver.chrome.driver", System.getProperty("usr.home") + System.getProperty("file.separator") + "chromedriver.exe");
}
In a code based on operating system you should initialise new ChromeDriver after System.setProperty setup only.
user.home is correct option - NOT "usr"
Finally it works(java) great when looks like this:
String os = System.getProperty("os.name").toLowerCase();
if (os.contains("mac")) {
System.setProperty("webdriver.chrome.driver", System.getProperty("user.home") + System.getProperty("file.separator") + "chromedriver");
} else {
System.setProperty("webdriver.chrome.driver", System.getProperty("user.home") + System.getProperty("file.separator") + "chromedriver.exe");
}
WebDriver driver = new ChromeDriver();

Keep file with Chromedriver in chrome://downloads

I'm trying to automate the download of an XML file with Google Chrome.
I'm using:
Google Chrome v73.0.3683.75 (64 bits)
Chromedriver v73
Selenium WebDriver v3.14.0
C#
The problem comes up when a message of harmful file appears:
As I'm using Chromedriver, I can not interact with this message, so I tried to accept the download from the chrome://downloads page.
Once I open the chrome://downloads page, I click on the Keep button, but an Alert comes up again to confirm the download.
This popup is not a popup Selenium and Chromedriver can Handle with the Dismiss()/Accept()/SendKeys()/... methods. When I try to SwitchTo() it, Chromedriver crashes.
I tried to directly send the keystrokes of {TAB} and {SPACE}/{RIGHT} and {ENTER}, but Chrome seems not to catch them...
The full code is:
String currentWindow = this.Drivers[Navegador].CurrentWindowHandle;
String popupHandle = "";
((IJavaScriptExecutor)this.Drivers[Navegador]).ExecuteScript("window.open('about:blank','_blank')");
ReadOnlyCollection<String> tabs = this.Drivers[Navegador].WindowHandles;
foreach (string handle in tabs){
if (handle != currentWindow){
popupHandle = handle;
break;
}
}
this.Drivers[Navegador].SwitchTo().Window(popupHandle);
this.Drivers[Navegador].Navigate().GoToUrl("chrome://downloads");
String script = "return document.querySelector('body > downloads-manager').shadowRoot.querySelector('#downloadsList > downloads-item').shadowRoot.querySelector('#dangerous > paper-button:nth-child(2)');";
//String script = "return document.querySelector('body > downloads-manager').shadowRoot.querySelector('#downloadsList > downloads-item:nth-child(2)').shadowRoot.querySelector('#url').textContent;";
IWebElement boton = (IWebElement) ((IJavaScriptExecutor) this.Drivers[Navegador]).ExecuteScript(script);
boton.Click();
Thread.Sleep(2000);
SendKeys.Send("{TAB}{SPACE}");
Thread.Sleep(1000);
this.Drivers[Navegador].Close();
this.Drivers[Navegador].SwitchTo().Window(currentWindow);
this.Drivers[Navegador].SwitchTo().DefaultContent();
result = true;
IMPORTANT NOTE:
I tried to launch Chrome with all the flags/options/experimental_options/user_preferences/... possible and it doesn't work. These options/arguments seem to be deprecated in the latest versions of Chrome or Chromedriver.
As discussed with OP, answering the question in Java.
Encountered the same problem few months back, so this is how it worked for me, might work for you as well.
Map<String, Object> chromePreferences = new Hashtable<String, Object>();
// Below preferences will disable popup dialog while downloading the file
chromePreferences.put("profile.default_content_settings.popups", 0);
chromePreferences.put("download.prompt_for_download", "false");
// Set the customised path for downloading the file, if required
chromePreferences.put("download.default_directory", "path");
ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.setExperimentalOption("prefs", chromePreferences);
DesiredCapabilities cap = DesiredCapabilities.chrome();
cap.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
cap.setCapability(ChromeOptions.CAPABILITY, chromeOptions);
//Now initiate ChromeDriver with the capabilities set above and continue with your automation
ChromeDriver chromeDriver = new ChromeDriver(cap);
I recently ran into this issue, and due to the deprecation of some of the methods in the ChromeDriver, the above solution didn't work.
After a lot of research I decided to switch to IE and explore an alternate option with the inspiration from this article - https://sqa.stackexchange.com/questions/3169/downloading-a-file-in-internet-explorer-through-selenium/3520 I came up with this solution in JAVA.
It is not as 'clean' but it worked for me.
public static void main(String[] args) throws NoAlertPresentException,InterruptedException {
System.setProperty("webdriver.ie.driver","C:\\selenium-java-3.141.59\\IEDriverServer.exe");
String url ="myfileurl";
WebDriver driver = new InternetExplorerDriver();
driver.get(url);
try {
Robot robot = new Robot();
Thread.sleep(2000);
//press alt+s key to save
robot.keyPress(KeyEvent.VK_ALT);
robot.keyPress(KeyEvent.VK_S);
robot.keyRelease(KeyEvent.VK_S);
robot.keyRelease(KeyEvent.VK_ALT);
Thread.sleep(2000);
}
catch (AWTException e) {
e.printStackTrace();
}
driver.close();
}

Which is the compatible version of IEDriverServer for IE11 and Selenium 3.13?

I am automating tests with IE11 and Selenium 3.13 and I was testing different version of IEDriverServer but every version has a bug. I want a stable version to combine IEDriverServer with IE11 and Selenium 3.13
I'm using this code to launch the application:
private static WebDriver setRemoteDriver(Map<String, Object> selConfig) {
String browser = System.getProperty("browser", selConfig.get("browser").toString());
capabilities = new DesiredCapabilities();
capabilities.setJavascriptEnabled(true);
if (browser.equalsIgnoreCase("firefox")) {
capabilities = DesiredCapabilities.firefox();
capabilities.setCapability(FirefoxDriver.PROFILE, getFirefoxProfile());
capabilities.setCapability("pageLoadStrategy", "normal");
} else if (browser.equalsIgnoreCase("chrome")) {
capabilities = DesiredCapabilities.chrome();
} else if (browser.equalsIgnoreCase("Safari")) {
capabilities = DesiredCapabilities.safari();
} else if ((browser.equalsIgnoreCase("ie")) || (browser.equalsIgnoreCase("internetexplorer"))
|| (browser.equalsIgnoreCase("internet explorer"))) {
capabilities = DesiredCapabilities.internetExplorer();
} else {
System.out.println("Please correct Browser specify in YAML file : " + browser);
capabilities = DesiredCapabilities.firefox();
}
try {
url = new URL(System.getProperty("ipaddress", getYamlValue("selenium.remote.host")));
} catch (MalformedURLException e) {
e.printStackTrace();
}
return new RemoteWebDriver(url, capabilities);
}
IEDriverServer for IE11 and Selenium should always be identical.
As per best practices you should always use the recent GA version while some organizations tends to prefer the major GA releases only.
As an example:
For Selenium v3.14.0 you should always use IEDriverServer v3.14.0
In some exceptional cases there may be minor Selenium releases where you need to use the IEDriverServer from the major release. As an example:
For Selenium v3.141.0, Selenium v3.141.5 and Selenium v3.141.59 you should always use IEDriverServer v3.141.0 only.
This Usecase
For Selenium v3.13.0 you should always use IEDriverServer v3.13.0

Running safari from webdriver

I'm trying to run Safari from WebDriver. When i start the project it cant build beacouse it cannot find safari. Safari is installed on the machine, i am registered as an developer.
Does anyone have a solution?
Code:
if(browser.equalsIgnoreCase("firefox")) {
capability = DesiredCapabilities.firefox();
capability.setBrowserName("firefox");
capability.setPlatform(org.openqa.selenium.Platform.ANY);
}
if(browser.equalsIgnoreCase("iexplore")) {
capability = DesiredCapabilities.internetExplorer();
capability.setBrowserName("iexplore");
capability.setPlatform(org.openqa.selenium.Platform.WINDOWS);
}
if(browser.equalsIgnoreCase("chrome")) {
capability = DesiredCapabilities.chrome();
capability.setBrowserName("chrome");
capability.setPlatform(org.openqa.selenium.Platform.ANY);
}
if(browser.equalsIgnoreCase("safari")) {
capability = DesiredCapabilities.safari();
capability.setBrowserName("safari");
capability.setPlatform(org.openqa.selenium.Platform.ANY);
}
driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), capability);
driver.navigate().to(test_data.BASE_URL);
Stacktrace:
FAILED CONFIGURATION: #BeforeClass setup("safari")
org.openqa.selenium.WebDriverException: Error forwarding the new session cannot find : {platform=ANY, browserName=safari, version=}
Command duration or timeout: 203 milliseconds
The new version of selenium i.e. selenium 2.30.0 is released.Grab it as it has built in support for safari driver...Enjoy!!!