IOSDriver can't resolve constructor, wants to cast DesiredCapabilities to Capabilities - java

package AppiumTest;
import java.net.URL;
import java.net.MalformedURLException;
import org.testng.annotations.Test;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.CapabilityType;
import io.appium.java_client.ios.IOSDriver;
public class TestIOSSafariBrowser{
#Test
public void startBrowser() throws MalformedURLException {
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("deviceName","iPhone 8");
capabilities.setCapability("platformName", "iOS");
capabilities.setCapability("platformVersion", "11.4.1");
capabilities.setCapability(CapabilityType.BROWSER_NAME, "safari");
IOSDriver driver = new IOSDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
driver.get("http://www.google.com");
System.out.println("Page title is " + driver.getTitle());
}
}
I'm relatively new to using Selenium and Appium.
I'm trying to open Safari to access Google through Xcode and Appium. When I instantiate IOSDriver as driver down below, IOSDriver does not allow me to pass in a DesiredCapabilities object (capabilities), instead expecting me to pass a Capabilities object. How would I try to open Safari and access the Google homepage if I use the Capabilities object instead of DesiredCapabilities, or is there another way to go about this?

Related

When running appium script to automate chrome the browser is getting stuck at data

I have tried or solutions from Stack Overflow. I am using latest chrome browser with latest chrome browser web driver version
I am new to Appium.
When I am running command in terminal
npm show appium-chromedriver version
I am getting 5.0.1
When I am running npm show chromedriver version (without appium)
I am getting version 98.0.1
P.S I am using latest Chrome browser version in my device which is 98.0.4758
import java.net.MalformedURLException;
import java.net.URL;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.remote.DesiredCapabilities;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.remote.MobileCapabilityType;
import io.appium.java_client.service.local.AppiumDriverLocalService;
import io.appium.java_client.service.local.AppiumServiceBuilder;
import io.github.bonigarcia.wdm.WebDriverManager;
public class browse {
public static void main(String[] args) throws MalformedURLException {
System.getProperty("webdriver.chrome.driver", "C:\\Automation\\chromedriver_win32\\chromedriver.exe");
AndroidDriver<WebElement> driver;
DesiredCapabilities cap = new DesiredCapabilities();
cap.setCapability("deviceName", "RealMe");
cap.setCapability(MobileCapabilityType.AUTOMATION_NAME, "UiAutomator1");
cap.setCapability(MobileCapabilityType.BROWSER_NAME, "Chrome");
cap.setCapability(MobileCapabilityType.NO_RESET, true);
cap.setCapability("udid", "MBEITORSYTQOPBAE");
cap.setCapability("platformName", "Android");
cap.setCapability("platformVersion", "9.0");
// cap.setCapability("appPackage", "com.android.Chrome");
// cap.setCapability("appActivity", "com.android.calculator2.Calculator");
// cap.setCapability(MobileCapabilityType.BROWSER_NAME, "Chrome");
cap.setCapability("skipDeviceInitialization", true);
cap.setCapability("skipServerInstallation", true);
// cap.setCapability("chromedriverExecutable", "\Automation\chromedriver_win32");
ChromeOptions options = new ChromeOptions();
options.setExperimentalOption("androidKeepAppDataDir", true);
cap.setCapability(ChromeOptions.CAPABILITY, options);
driver = new AndroidDriver<>(new URL("http://127.0.0.1:4723/wd/hub"), cap);
// driver.get("https://www.youtube.com/");
}
}```

The method getBinaryPath() is undefined for the type WebDriverManager error shows in eclipse while i am trying to run appium automation project

I am trying to run a mini appium project, I have the emulator and an appium server running and here's my code, it says that .getBinaryPath() is undefined for type WebDriverManager "caps.setCapability("chromedriverExecutable", WebDriverManager.chromedriver().getBinaryPath());"
package appiumBasics;
import java.net.MalformedURLException;
import java.net.URL;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.testng.annotations.Test;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.remote.MobileCapabilityType;
import io.github.bonigarcia.wdm.WebDriverManager;
#Test
public class RubWebApplicationAndroidEmulator {
public void OpenWebApplication() throws MalformedURLException {
DesiredCapabilities caps = new DesiredCapabilities();
caps.setCapability(MobileCapabilityType.BROWSER_NAME, "chrome");
caps.setCapability(MobileCapabilityType.DEVICE_NAME, "HaidyEmulator");
WebDriverManager.chromedriver().setup();
caps.setCapability("chromedriverExecutable", WebDriverManager.chromedriver().getBinaryPath());
AndroidDriver driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"),caps);
}
}
That is because if you actually go to the repository and open the problematic class, you find there is no such method defined for WebDriverManager:
https://github.com/bonigarcia/webdrivermanager/blob/master/src/main/java/io/github/bonigarcia/wdm/WebDriverManager.java
Presumably this was changed at some point. Possibly you need WebDriverManager#getDownloadedDriverPath():
#Test
public class RubWebApplicationAndroidEmulator {
public void OpenWebApplication() throws MalformedURLException {
DesiredCapabilities caps = new DesiredCapabilities();
caps.setCapability(MobileCapabilityType.BROWSER_NAME, "chrome");
caps.setCapability(MobileCapabilityType.DEVICE_NAME, "HaidyEmulator");
WebDriverManager.chromedriver().setup();
caps.setCapability("chromedriverExecutable", WebDriverManager.chromedriver().getDownloadedDriverPath());
AndroidDriver driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"),caps);
}
}

I can't open anything with Selenium WebBrowser Java

I am trying to open local files with Selenium. With the code below, Firefox is opening, but I have the error org.openqa.selenium.WebDriverException: Timed out waiting 45 seconds for Firefox to start..
File gecko = new File("resources/geckodriver64.exe");
System.setProperty("webdriver.gecko.driver", gecko.getAbsolutePath());
FirefoxOptions capabilities = new FirefoxOptions();
capabilities.setCapability("marionette", false);
WebDriver driver = new FirefoxDriver(capabilities);
driver.get("file:///C:/example/myfile.pdf");
Can someone help me ? I couldn't find anything on the internet.
We have now come to the part where you will see how you can use GeckoDriver to launch Firefox. You will first need to download GeckoDriver and then set its path. There are three different ways to use GeckoDriver with Selenium 3:
With setting system properties in the test
With setting system properties by Environment Variable
With setting up Browser Desired Capabilities
Download Gecko Driver:-
1- Gecko Driver different versions can be downloaded from Github. I suggest you to use the latest version.
Set System Properties for Gecko Driver:-
Code to set the System properties is System.setProperty(“webdriver.gecko.driver”,”Path to geckodriver.exe”);
The complete program to launch the GeckoDriver will be like this:
package seleniumPrograms;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class Gecko_Driver {
public static void main(String[] args) throws InterruptedException {
System.setProperty("webdriver.gecko.driver", "D:\\\\XXXX\\trunk\\Library\\drivers\\geckodriver.exe");
WebDriver driver = new FirefoxDriver();
driver.get("http://www.toolsqa.com");
Thread.sleep(5000);
driver.quit();
}
}
Check Below answer. This is working solution on my machine. Please check your firefox version too.
import org.openqa.selenium.Platform;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
public class geckodriver {
public static void main(String[] args) throws InterruptedException {
System.setProperty("webdriver.gecko.driver", "C:\\Users\\username\\Downloads\\geckodriver-v0.20.1-win64\\geckodriver.exe");
Thread.sleep(5000);
// DesiredCapabilities capabilities = DesiredCapabilities.firefox();
// capabilities.setCapability("marionette", true);
//
// WebDriver driver = new FirefoxDriver(capabilities);
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities = DesiredCapabilities.firefox();
capabilities.setBrowserName("firefox");
capabilities.setVersion("your firefox version");
capabilities.setPlatform(Platform.WINDOWS);
capabilities.setCapability("marionette", false);
WebDriver driver = new FireFoxDriver(capabilities);
driver.get("http://www.google.com");
Thread.sleep(5000);
driver.quit();
}}
Can you try below code ?
package seleniumPrograms;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
public class Gecko_Driver {
public static void main(String[] args) throws InterruptedException {
DesiredCapabilities capabilities = DesiredCapabilities.firefox();
capabilities.setCapability("marionette", true);
WebDriver driver = new FirefoxDriver(capabilities);
driver.get("http://www.google.com");
Thread.sleep(5000);
driver.quit();
}

Browser-mob Proxy is not capturing the network traffic with chrome driver

I am using this code to integrate the browser mob proxy with maven dependency
net.lightbody.bmp browsermob-core 2.1.5
its not capturing the network requests at all, I am getting this kind of har file:
{
"log":{
"version":"1.2",
"creator":{
"name":"BrowserMob Proxy",
"version":"2.1.0-beta-6-littleproxy",
"comment":""
},
"pages":[
{
"id":"11",
"startedDateTime":"2017-10-26T17:28:42.501+05:30",
"title":"11",
"pageTimings":{
"comment":""
},
"comment":""
}
],
"entries":[],
"comment":""
}
}
package lenskart.tests;
import java.io.File;
import java.net.UnknownHostException;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.Proxy;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.testng.annotations.Test;
import net.lightbody.bmp.BrowserMobProxyServer;
import net.lightbody.bmp.client.ClientUtil;
import net.lightbody.bmp.mitm.manager.ImpersonatingMitmManager;
import net.lightbody.bmp.proxy.CaptureType;
public class ProxyTestClass {
#Test
public static void main() throws Exception {
// TODO Auto-generated method stub
BrowserMobProxyServer browserMobProxy = new BrowserMobProxyServer();
browserMobProxy.setTrustAllServers(true);
browserMobProxy.setMitmManager(ImpersonatingMitmManager.builder().trustAllServers(true).build());
browserMobProxy.start(0);
System.out.println("Port Started On: " + browserMobProxy.getPort());
System.setProperty("webdriver.chrome.driver", "/Users/pankaj.katiyar/Desktop/Automation/Lenskart_Automation/tpt/drivers/chromedriver");
browserMobProxy.enableHarCaptureTypes(CaptureType.REQUEST_CONTENT, CaptureType.RESPONSE_CONTENT, CaptureType.RESPONSE_HEADERS);
WebDriver driver = getDriver_CapProxy(browserMobProxy);
driver.get("http://www.lenskart.com");
driver.navigate().to("http://www.google.com");
driver.quit();
browserMobProxy.stop();
browserMobProxy.newHar("11");
browserMobProxy.getHar().writeTo(new File("/Users/pankaj.katiyar/Desktop/Automation/Lenskart_Automation/har"));
;
System.out.println("Loaded browser ");
}
public static WebDriver getDriver_CapProxy(BrowserMobProxyServer browserMobProxy) throws UnknownHostException {
Proxy proxy = ClientUtil.createSeleniumProxy(browserMobProxy);
proxy.setHttpProxy("localhost:" + browserMobProxy.getPort());
DesiredCapabilities cap = new DesiredCapabilities();
ChromeOptions options = new ChromeOptions();
options.addArguments("--ignore-certificate-errors");
cap.setCapability(ChromeOptions.CAPABILITY, options);
cap.setCapability(CapabilityType.PROXY, proxy);
WebDriver driver = new ChromeDriver(options);
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
return driver;
}
}
There's two issues with your code.
First the selenium proxy is assigned to the capabilities, but the instance is never used. So either assign the options to the capabilities, or directly assign the selenium proxy to the options:
Proxy seleniumProxy = ClientUtil.createSeleniumProxy(browserMobProxy);
ChromeOptions options = new ChromeOptions();
options.addArguments("--ignore-certificate-errors");
options.setCapability(CapabilityType.PROXY, seleniumProxy);
WebDriver driver = new ChromeDriver(options);
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
Second, you are calling browserMobProxy.newHar at the end of the recording when it should be at the beginning:
browserMobProxy.newHar("11");
driver.get("http://www.lenskart.com");
driver.navigate().to("http://www.google.com");
browserMobProxy.getHar().writeTo(new File("/Users/pankaj.katiyar/Desktop/Automation/Lenskart_Automation/har"));
driver.quit();
browserMobProxy.stop();
I ran your code and only two changes you need are, change
WebDriver driver = new ChromeDriver(options);
to
WebDriver driver = new ChromeDriver(cap);
And move browserMobProxy.newHar("11"); before the navigate
browserMobProxy.newHar("11");
driver.get("http://www.lenskart.com");
Rest all is fine in your code. Once you do that Har is generated fine as shown in below screenshot

Automating android emulator and browser using Appium script

Performing automation test on android emulator using appium. Browser in emulator is not opening when it is automated via code. I have copied my code below kindly look into it and help me out. Thanks in advance
package report;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.List;
import java.util.concurrent.TimeUnit;
import javax.swing.JOptionPane;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxProfile;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
public class emulator {
WebDriver driver;
public void setUp() throws MalformedURLException
{
DesiredCapabilities capabilities= new DesiredCapabilities();
capabilities.setCapability(CapabilityType.BROWSER_NAME,"browser");
capabilities.setCapability(CapabilityType.VERSION,"4.4");
capabilities.setCapability(CapabilityType.PLATFORM,"windows");
capabilities.setCapability("platformName","Android");
capabilities.setCapability("devices","Android");
capabilities.setCapability("avd","nexus");
capabilities.setCapability("deviceName","");
capabilities.setCapability("appPackage", "com.android.browser");
capabilities.setCapability("appActivity", "com.android.browser.BrowserActivity");
driver=new RemoteWebDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
}
public void cal(){
driver.get("http://www.google.com");
}
public static void main(String[] args) throws MalformedURLException
{
emulator a=new emulator();
a.setUp();
a.cal();
}
}
The lock screen will deactivate the other script of our program. So I tried open the emulator manually and disable the lock screen (Settings -> Security -> None). Then close the emulator. Now open the emulator automatically and run the script.
public void setUp(int p) throws MalformedURLException {
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(CapabilityType.BROWSER_NAME, "browser");
capabilities.setCapability(CapabilityType.VERSION, "");
capabilities.setCapability(CapabilityType.PLATFORM, "windows");
capabilities.setCapability("platformName", "Android");
capabilities.setCapability("udid", "emulator-" + p);
capabilities.setCapability("devices", "Android");
capabilities.setCapability("avd", "Nexus7");
capabilities.setCapability("deviceName", "");
capabilities.setCapability("appPackage", "com.android.browser");
capabilities.setCapability("appActivity", "com.android.browser.BrowserActivity");
driver = new RemoteWebDriver(new URL("http://127.0.0.1:" + this.port + "/wd/hub"),
capabilities);
}
When working on mobile browser we need not to pass all the above desiredcapabilities like apppackage and appactivitiy. You can check the details of required capabilities # http://qaautomationcafe.blogspot.in/2015/09/mobile-web-automation-using-appium.html

Categories