I am getting this exception
org.openqa.selenium.WebDriverException: org.openqa.selenium.WebDriverException: An unknown server-side error occurred while processing the command. Original error: 'POST /element' cannot be proxied to UiAutomator2 server because the instrumentation process is not running (probably crashed)
while launching another app after working on an app. The first app, which was launched is working fine with #Android Find by(Xpath ="").but when the second app is launched, it is not clicking the element given in #android find by mobile element format, but working in driver.findElement by format.
How to resolve this?
The method used for launching the second app.
public void supplier() throws Exception { PageFactory.initElements(new AppiumFieldDecorator(driver), this);
props = new Properties();
String propFileName = "config.properties";
String xmlfileName = "strings/strings.xml";
inputStream = getClass().getClassLoader().getResourceAsStream(propFileName);
props.load(inputStream);
stringis = getClass().getClassLoader().getResourceAsStream(xmlfileName);
utils = new TestUtils();
strings = utils.parseStringXML(stringis);
DesiredCapabilities caps = new DesiredCapabilities();
caps.setCapability("platformName","Android");
URL url = new URL(props.getProperty("appiumURL"));
caps.setCapability("deviceName","0dac3ec7");
caps.setCapability("appPackage", "appPackage");
caps.setCapability("appActivity",props.getProperty("appActivity"));
driver = new AndroidDriver<MobileElement>(url, caps);
}
Related
I'm trying to run tests on GRID3 using appium, but every run i receive this error
public static AndroidDriver<WebElement> initAndroidDriver() throws Exception {
try {
String apkLink = SettingsProvider.getPropertyValue("front.android.apk.link") +
"/" + SettingsProvider.getPropertyValue("front.android.version");
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(MobileCapabilityType.PLATFORM_NAME, Platform.ANDROID);
capabilities.setCapability(MobileCapabilityType.APP, apkLink);
capabilities.setCapability(MobileCapabilityType.FULL_RESET, true);
capabilities.setCapability(MobileCapabilityType.NO_RESET, false);
capabilities.setCapability("appium:androidInstallTimeout ", 100000);
return new AppiumBuilder().createAndroidApkDriver(new URL(getSeleniumMobileGridHost()), capabilities);
} catch (MalformedURLException e) {
throw new Exception("Creating ANDROID driver exception " + e.getMessage());
}
}
Error:
java.lang.AssertionError: Initialization Android driver Unable to create a new remote session. Please check the server log for more details. Original error: Unable to parse remote response: <!DOCTYPE html>
Any ideas how ti fix it?
Somebody changed link to grid in property config, added /wd/hub to link and everything started to work
I am trying to create a variable that I can open a new tab with by using the code below in my Test:
getWebDriver().get("first website");
WebDriver newTab = getWebDriver().switchTo().newWindow(WindowType.TAB);
newTab.get("second website");
Each test extends my GoogleChromeDriver class located in my test folder for which I have used ChromeOptions. The newTab variable works as expected and opens a new tab when using setWebDriver(new ChromeDriver());, but gives an error when passing options variable from ChromeOptions to it like setWebDriver(new ChromeDriver(options));
This is the #BeforeTest from my GoogleChromeDriver class
public void init() {
List<String> driverArguments = List.of("disable-extensions", "profile-directory=Default", "incognito", "disable-plugins-discovery", "start-maximized");
String currentUserDirectory = System.getProperty("user.home");
System.setProperty("webdriver.chrome.driver", currentUserDirectory + "\\Documents\\webDrivers\\chromedriver.exe");
ChromeOptions options = new ChromeOptions();
options.setExperimentalOption("excludeSwitches", new String[]{"enable-automation"});
options.addArguments(driverArguments);
setWebDriver(new ChromeDriver());
}
This is the error I receive
org.openqa.selenium.WebDriverException: unknown error: unhandled inspector error: {"code":-32000,"message":"Failed to open new tab - no browser is open"}
UPDATE:
I have removed the incognito parameter from the list of options and it works now. Any ideas on how to open a new tab by using incognito tabs?
I'm trying to set up my webdriver so that it can execute tests in parallel from the xml sheet, this it does, but I find sometimes it opens up blank chrome windows of "data;"
I've researched around other questions and all the answers seem to say things about putting the webdriver as a new threadlocal<RemoteWebDriver>, which I am already doing.
This is the WebDriverSetup.java file I am using:
public class WebDriverSetup {
private static ThreadLocal<RemoteWebDriver> threadDriver = null;
public WebDriver driver(){
return threadDriver.get();
}
#BeforeMethod
public void setUp() throws MalformedURLException {
//Set up the path to the chromedriver so that the user will not have problems if they don't have the system path variable set up.
System.setProperty("webdriver.chrome.driver", TestExecutor.projectDirectory + "/chromedriver.exe");
//Set the hub URL
String seleniumUrl = "http://" + TestExecutor.hubUrl + "/wd/hub";
//Turn off logging because as of selenium-standalone-server-3.0.1, there
//is an "INFO" message that appears in console that could be mistaken for
//an error message.
Logger.getLogger("org.openqa.selenium.remote").setLevel(Level.OFF);
//threadDriver needs to be on its own local thread
threadDriver = new ThreadLocal<RemoteWebDriver>();
//Set chromeoptions so they open headless on the VM, but the VM imagines the
//tests as if chrome was running full screen on a desktop session.
ChromeOptions options = new ChromeOptions();
options.addArguments("--headless");
options.addArguments("--window-size=1920,1080");
//Apply the options to the chromedriver session.
URL seleniumHubURL = new URL(seleniumUrl);
threadDriver.set(new RemoteWebDriver(seleniumHubURL, options));
}
}
and this is how I am calling it from my test:
public class Demo_1_Filter_Users_By_Firstname extends TestBase.ClassGlobals
{
private WebDriverSetup webDriverSetup;
private EventFiringWebDriver driver;
private File logFile;
#Test
public void main(){
//The main method
driver.get("web_application_url");
}
#BeforeMethod
public void testSetup() throws IOException {
//Setup the webdriver
webDriverSetup = new WebDriverSetup();
driver = new EventFiringWebDriver( webDriverSetup.driver() );
//Set up an eventhandler on the event so that all the logging functions work
EventHandler handler = new EventHandler();
driver.register( handler );
//Setup the logfile
logFile = commonMethods.newLogFile();
//Log
commonMethods.log(logFile, "------TEST STARTED------");
}
#AfterMethod
public void testClosure(){
//Close webdriver session, log test done etc
}
}
The error that I am experiencing doesn't happen every time, and I don't understand why the window is hanging on data; even though the first line of my main method is to create a new webdriver session, and then using that session, open the web application through driver.get()
I am using chromedriver version 2.41
The latest stable version of ChromeDriver (88.0.4324.96) appears to have fixed this:
Resolved issue 3641: Page not getting loaded/rendered when browser window is not in focus with Chrome Beta v87 and chromedriver v(87/86)
I've been having this issue for a while and updating my chromedriver.exe file finally solved it.
When I run my automated tests on jenkins, sometimes some tests are being skipped. I'm getting the following error: org.openqa.selenium.WebDriverException: chrome not reachable.
For what if've read on google this happens when there is and error initializing the webdriver instance. And this makes the tests skip and leaves the chromedriver.exe process still running.
Is there a way to handle the exception so when this happens I can kill the process?. Or a way on how to fix the issue so that test aren't skipped. Below is the code on how I initialize chromedriver.
private void chromeDriverSetUp(){
System.setProperty(DRIVER_PATH_PROPERTY_NAME, DRIVER_PATH);
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
capabilities.setCapability("nativeEvents", true);
ChromeOptions options = new ChromeOptions();
options.addArguments("--lang=es");
options.addArguments("--disable-extensions");
options.addArguments("start-maximized");
capabilities.setCapability(ChromeOptions.CAPABILITY, options);
driver = new ChromeDriver(capabilities);
}
And this is the method that fails when the exception is thrown:
#Parameters({"subModel", "moduleName", "testName", "testLinkName"})
#BeforeMethod
public void handleTestMethodName(Method method, String subModel, String moduleName, String testName, String testLinkName) throws Exception
{
this.subModel=subModel;
this.moduleName = moduleName;
this.testName = testName;
this.testLinkName = testLinkName;
this.testMethod = method.getName();
this.testClass = method.getDeclaringClass().getSimpleName();
initializeSelenium();
String modulo = "";
if(subModel.equalsIgnoreCase("ISSUER")){
modulo = PropertiesManager.getInstance().getProperty(EPropertiesNames.MOD_ISSUER);
}else{
modulo = PropertiesManager.getInstance().getProperty(EPropertiesNames.MOD_ACQUIRER);
}
setCMSModulo(modulo);
startAccess();
}
I want to run my selenium tests on different browsers based on the browser name set in the Properties file.
I have a method named as initiateDriver() in which I get the browser name as set in the Properties file(valid values being ff, chrome or ie) and do the necessary settings for each of the web driver type. This method will return a WebDriver object to my methods.
public WebDriver initiateDriver()
{
// Created webdriver instance
WebDriver _drv = null;
String IEDriverPath, ChromeDriverPath;
try
{
//Get the Browser Name set in the properties file
String browserType = loadPropertiesFile("BrowserName");
Log4j.logger.warn("Browser name-----------"+browserType);
//Test if the browser is IE
if (browserType.equalsIgnoreCase("ie"))
{
//Currently, IEDriverServer.exe is copied on to Drivers folder of framework
IEDriverPath= "\\Drivers\\IEDriverServer.exe";
//Set the required properties to instantiate IE driver. Place any latest IEDriverServer.exe files under Drivers folder
System.setProperty("webdriver.ie.driver", IEDriverPath);
DesiredCapabilities cap= new DesiredCapabilities();
cap.setCapability("ignoreProtectedModeSettings", true);
_drv = new InternetExplorerDriver(cap);
}
//Check if BrowserType is set to Firefox
else if (browserType.equalsIgnoreCase("ff") || browserType.equalsIgnoreCase("firefox"))
{
//Getting the default Firefox with some settings
FirefoxProfile fp = new FirefoxProfile();
fp.setAcceptUntrustedCertificates(false);
//setting the Firefox preference "auto upgrade browser" to false and to prevent compatibility issues
fp.setPreference("app.update.enabled", false);
_drv = new FirefoxDriver();
}
//Check if BrowserType is set to Chrome
else if (browserType.equalsIgnoreCase("chrome"))
{
//Currently, chromedriver.exe is copied on to Drivers folder of framework
ChromeDriverPath= "\\Drivers\\chromedriver.exe";
//Set the required properties to instantiate Chrome driver. Place any latest Chromedriver.exe files under Drivers folder
System.setProperty("webdriver.chrome.driver", ChromeDriverPath);
ChromeOptions options = new ChromeOptions();
options.addArguments("--start-maximized");
_drv= new ChromeDriver(options);
}
else
{
Reporter.log("Invalid browser name. Please check the Resources/PropertiesLocation.properties file.");
System.out.println("Invalid browser name. Please check the Resources/PropertiesLocation.properties file.");
System.exit(0);
}
}
catch(Exception e)
{
System.out.println(e.getMessage());
Reporter.log("Enter valid browser name---");
System.exit(0);
}
return _drv;
}`
I am calling this method in the following class.
public class SmokeTest1
{
WebDriver d;
#BeforeClass
public void setUp() throws Exception
{
d = gm.initiateDriver();
d.manage().window().maximize();
d.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
}
#Test
public void firstSmokeTest() throws Exception
{
loginTest(d);
}
}
I am running my tests via ant build.xml file. However I am getting error as -
Could not start a new session. Possible causes are invalid address of the remote server or browser start-up failure."
Can somebody suggest what is going wrong or am I missing anything?