appium issue, not able to launch two apps - selenium

I am not able to launch two apps in single script using APPIUM, it shows error as
An unknown server-side error occurred while processing the command.
The desired should not include both of an 'appPackage' and a
'browserName'
public class SalesLeadProg {
public AndroidDriver<MobileElement> driver;
private WebElement element; public WebDriverWait wait;
#BeforeMethod
public void setup() throws MalformedURLException, InterruptedException {
DOMConfigurator.configure("log4j.xml");
DesiredCapabilities caps = new DesiredCapabilities();
caps.setCapability("automationName", "UiAutomator2");
caps.setCapability("deviceName", "sunil");
caps.setCapability("udid", "422b21e7");
caps.setCapability("platformName", "Android");
caps.setCapability("platformVersion", "8.1.0");
caps.setCapability("appPackage", "com.mfcwl.mfc_dealer");
caps.setCapability("appActivity", "com.mfcwl.mfc_dealer.Activity.SplashActivity");
caps.setCapability("autoAcceptAlerts", true);
caps.setCapability("noReset", true);
caps.setCapability("browserName", "Chrome");
//it will launch the chrome browser in mobile
caps.setCapability(ChromeOptions.CAPABILITY, true);
ChromeOptions options=new ChromeOptions();
options.setExperimentalOption("androidPackage", "com.android.chrome");
caps.setCapability("autoGrantPermissions", true);
// to allow the permission of contacts camara, which comes in the begining when we install the app*/
caps.setCapability("unicodeKeyboard", true);
// to make the keyboard working
caps.setCapability("resetKeyboard", false);
// it
try {
driver = new AndroidDriver<MobileElement> (new URL("0.0.0.0:4723/wd/hub"),caps);
}
catch(MalformedURLException e) {
System.out.println(e);
}
driver.manage().timeouts().implicitlyWait(16, TimeUnit.SECONDS);
}
#Test
public void Dashboard() throws MalformedURLException, InterruptedException {
MobileElement email = driver.findElement(By.id("com.mfcwl.mfc_dealer:id/email"));
Thread.sleep(4000);
WebDriverWait wait = new WebDriverWait(driver, 10);
wait.until(ExpectedConditions.visibilityOf(email));
boolean isElementPresent = email.isDisplayed();
System.out.println(isElementPresent);
Thread.sleep(4000);
driver.findElementById("com.mfcwl.mfc_dealer:id/email").clear();
driver.findElementById("com.mfcwl.mfc_dealer:id/email").sendKeys("prestige");
System.out.println("Entered ID");
driver.findElement(By.id("com.mfcwl.mfc_dealer:id/password")).clear();
driver.findElement(By.id("com.mfcwl.mfc_dealer:id/password")).sendKeys("Mahindra");
System.out.println("Entered Password");
driver.findElement(By.id("com.mfcwl.mfc_dealer:id/email_sign_in_button")).click();
//to login
System.out.println("Signed IN");
Thread.sleep(4000);
driver.findElement(By.id("com.mfcwl.mfc_dealer:id/homeTab")).click();
//to click on home button
System.out.println("Clicked on Home button");
Thread.sleep(3000); //Set ChromeDriver location
System.setProperty("webdriver.chrome.driver", "./ChromeDriver/chromedriver.exe");
driver.get("google.com/"); driver.findElement(By.id("com.mfcwl.mfc_dealer:id/click_lead")).click();
System.out.println("Clicked on Today's follow up leads section");
driver.findElement(By.id("com.mfcwl.mfc_dealer:id/lead_filter")).click();
Please assist with a solution on how to use two apps in APPIUM with a single script.

Related

Drag and drop in Selenium

In https://www.globalsqa.com/demo-site/draganddrop/ I need to drag and drop picture with the text "High Tatras" into Trash section.
#Test
void task1() {
System.setProperty("webdriver.chrome.driver", "C:\\Users\\DELL\\Desktop\\New folder\\chromedriver.exe");
WebDriver webDriver = new ChromeDriver();
try {
webDriver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);
webDriver.get("https://www.globalsqa.com/demo-site/draganddrop/");
WebElement from = webDriver.findElement(By.xpath("//*[#id=\"gallery\"]/li[1]"));
WebElement to = webDriver.findElement(By.xpath("//*[#id=\"trash\"]"));
Actions actions = new Actions(webDriver);
actions.dragAndDrop(from, to).build().perform();
} finally {
webDriver.close();
}
}
Both the from and to elements are inside the iframe.
So, to access these elements you need to switch into that iframe first.
Your code will look as following:
#Test
void task1() {
System.setProperty("webdriver.chrome.driver", "C:\\Users\\DELL\\Desktop\\New folder\\chromedriver.exe");
WebDriver webDriver = new ChromeDriver();
try {
webDriver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);
webDriver.get("https://www.globalsqa.com/demo-site/draganddrop/");
driver.switchTo().frame(driver.findElement(By.xpath("//div[#rel-title='Photo Manager']//iframe")));
WebElement from = webDriver.findElement(By.xpath("//*[#id='gallery']/li[1]"));
WebElement to = webDriver.findElement(By.xpath("//*[#id='trash']"));
Actions actions = new Actions(webDriver);
actions.dragAndDrop(from, to).build().perform();
} finally {
webDriver.close();
}
}

How to Launch and Switch between two browsers(not tabs) chrome and firefox drivers in Selenium Java

#Test
public void openWeb() throws IOException, InterruptedException {
fis = new FileInputStream(System.getProperty("user.dir")+"\\resources\\config.properties");
property = new Properties();
property.load(fis);
WebElement UsernameField = driver.findElement(By.name(property.getProperty("username_fieldName")));
WebElement PasswordField = driver.findElement(By.name(property.getProperty("password_fieldName")));
WebElement SubmitButton = driver.findElement(By.xpath(property.getProperty("submit_ButtonXpath")));
UsernameField.click();
UsernameField.sendKeys("test");
PasswordField.click();
PasswordField.sendKeys("!TEST");
SubmitButton.click();
//Testcase TC_1.01 Verify the login of "Berater" with valid credentials
WebElement Einladen = driver.findElement(By.className(property.getProperty("HomeScreen_EinladenClass")));
boolean Homescreen = Einladen.isDisplayed();
extentTest = extent.startTest("TC_1.01 - Verify the login of \"Berater\" with valid credentials");
if(Homescreen == true) {
extentTest.log(LogStatus.PASS, "Login successful for the Berater");
}
else {
extentTest.log(LogStatus.FAIL, "Login Failed for the Berater, Please refer the Screenshot");
}
Thread.sleep(1000);
Einladen.click();
driver.findElement(By.xpath(property.getProperty("Einladung_LinkXpath"))).click();
Thread.sleep(1000);
driver.findElement(By.cssSelector("body")).sendKeys(Keys.CONTROL + "t");
Thread.sleep(2000);
Actions actions = new Actions(driver);
actions.sendKeys(Keys.chord(Keys.LEFT_CONTROL, "v")).build().perform();
Thread.sleep(2000);
actions.sendKeys(Keys.ENTER);
Thread.sleep(2000);
}
First of all i call here chrome driver and open a link in chrome, now after performing some actions in chrome driver, i need to open firefox and open a separate link, and check the syncronization between the two. But i dont know how to open two different browsers and switch between them.
Please help.

Unable to find the element on emulator screen of Android app

The element appears within the appium view but unfortunately the element does not seems visible while automating it.
private AndroidDriver driver;
String idOfCNIC = "com.tez.androidapp:id/imageViewNICDetails";
this.driver.findElement(By.id(idOfCNIC))`
Following is the driver initialization code :
private static AndroidDriver driver;
public static AndroidDriver getDriver() {
if (driver == null) {
DesiredCapabilities caps = new DesiredCapabilities();
caps.setCapability("deviceName", "920121cb3c7fc34a");
caps.setCapability("platformName", "Android");
caps.setCapability(CapabilityType.VERSION, "6.0.1");
caps.setCapability(CapabilityType.BROWSER_NAME, "Android");
caps.setCapability("app", "path_of_app");
(InternetExplorerDriver.IE_ENSURE_CLEAN_SESSION, true);
try {
driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), caps);
} catch (MalformedURLException e) {
e.printStackTrace();
}
}
return driver;
}
Hi could you please use following versions of Appium java client and Selenium:
Appium Java-Client : 6.0.0-BETA5
Selenium-server : 3.9.1 Appium
Desktop as Appium Inspector : 1.6.1
Also please try with the following code for driver initialization :
private static AndroidDriver<?> driver;
public static AndroidDriver getDriver() {
if (driver == null) {
DesiredCapabilities caps = new DesiredCapabilities();
caps.setCapability(MobileCapabilityType.DEVICE_NAME, "920121cb3c7fc34a");
caps.setCapability(MobileCapabilityType.PLATFORM_NAME, "Android");
caps.setCapability(MobileCapabilityType.AUTOMATION_NAME,"Appium ");
caps.setCapability(MobileCapabilityType.VERSION, "6.0.1");
caps.setCapability(MobileCapabilityType.APP, "path_of_app");
caps.setCapability("appWaitActivity", "*");
try {
driver = new AndroidDriver<MobileElement>(new URL("http://127.0.0.1:4723/wd/hub"), caps);
} catch (MalformedURLException e) {
e.printStackTrace();
}
}
return driver;
}
I hope this solves your problem. Thanks!

UnReachableBrowserException in Chome with Selenium Webdriver

i am getting UnhandledBrowserException when trying the below code in chrome:
public class myClass {
public static void main(String[] args) {
// declaration and instantiation of objects/variables
System.setProperty("webdriver.chrome.driver", "C://Program Files (x86)//Google//Chrome//Application//chrome.exe");
WebDriver driver= new ChromeDriver();
String baseURL = "http://newtours.demoaut.com";
String expectedTitle = "Welcome: Mercury Tours";
String actualTitle = "";
// launch Firefox and direct it to the Base URL
driver.get(baseURL);
// get the actual value of the title
actualTitle = driver.getTitle();
/*
* compare the actual title of the page witht the expected one and print
* the result as "Passed" or "Failed"
*/
if (actualTitle.contentEquals(expectedTitle)){
System.out.println("Test Passed!");
} else {
System.out.println("Test Failed");
}
//close Firefox
driver.close();
// exit the program explicitly
System.exit(0);
}
It is launching a new session in chrome but then throwing the exception. Any help would be highly appreciated.
I think you are hitting program executable instead of driver.
System.setProperty("webdriver.chrome.driver", "/path/to/chromedriver");
WebDriver driver = new ChromeDriver();
It should be path to chrome driver not the chrome browser executable.
You can take a look at https://sites.google.com/a/chromium.org/chromedriver/getting-started

To perform Autosuggestion using Selenium

Having some problem in selecting the option from the dropdown using autosuggestion. Please give a solution to select the option.
The related code is posted below :-
#Test(priority = 4)
public void ReportType() throws InterruptedException {
WebElement reporttype = driver.findElement(By.xpath("html/body/form/div[3]/table[2]/tbody/tr[3]/td/table/tbody/tr[1]/td/table/tbody/tr[2]/td/div/span/table/tbody/tr[3]/td[2]/span/table/tbody/tr/td[2]/input[1]"));
reporttype.clear();
reporttype.sendKeys("NMQ De");
WebDriverWait wait = new WebDriverWait(driver, 10);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("html/body/form/div[3]/table[2]/tbody/tr[3]/td/table/tbody/tr[1]/td/table/tbody/tr[2]/td/div/span/table/tbody/tr[3]/td[2]/span/div/ul/li[4]")));
Thread.sleep(5000);
driver.findElement(By.xpath("html/body/form/div[3]/table[2]/tbody/tr[3]/td/table/tbody/tr[1]/td/table/tbody/tr[2]/td/div/span/table/tbody/tr[3]/td[2]/span/div/ul/li[4]")).click();
}
Think your question as google search when u do some google search google provides u auto suggestion
public static void main(String[] args) throws InterruptedException {
// TODO Auto-generated method stub
String textToSelect = "headlines today";
WebDriver driver = new FirefoxDriver();
driver.get("https://www.google.co.in/");
Thread.sleep(2000);
WebElement autoOptions= driver.findElement(By.id("lst-ib"));
autoOptions.sendKeys("he");
List<WebElement> optionsToSelect = driver.findElements(By.xpath("//div[#class='sbqs_c']"));
for(WebElement option : optionsToSelect){
System.out.println(option);
if(option.getText().equals(textToSelect)) {
System.out.println("Trying to select: "+textToSelect);
option.click();
break;
}
}