I have 2 desktop machines in which Appium script is saved in machine 1 and Appium got installed in machine 2 and android devices also connected in machine 2. now i want to take the script from the machine 1 and execute it in the devices connected in the machine 2. how to achieve this. please suggest me.
The below code i am able to run same machine.i want to run on android device which is connected in another machine.Both machine ip segment is same segment.
package com.appiumproj.test;
import io.appium.java_client.AppiumDriver;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.remote.MobileCapabilityType;
import java.net.MalformedURLException;
import java.net.URL;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.testng.annotations.*;
public class Appium {
AppiumDriver driver;
#BeforeClass
public void setUp() throws MalformedURLException{
//Set up desired capabilities and pass the Android app-activity and app-package to Appium
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(MobileCapabilityType.VERSION, "5.0.2");
capabilities.setCapability(MobileCapabilityType.PLATFORM_NAME, "Android");
capabilities.setCapability(MobileCapabilityType.DEVICE_NAME,"ZX1D62FPVQ");
capabilities.setCapability(MobileCapabilityType.APP_PACKAGE, "com.android.calculatord");
capabilities.setCapability(MobileCapabilityType.APP_ACTIVITY, "com.android.calculator2.Calculator");
driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
}
#Test
public void testCal(){
WebElement two=driver.findElement(By.name("2"));
two.click();
WebElement plus=driver.findElement(By.name("+"));
plus.click();
WebElement four=driver.findElement(By.name("4"));
four.click();
WebElement equalTo=driver.findElement(By.name("="));
equalTo.click();
WebElement results=driver.findElement(By.className("android.widget.EditText"));
assert results.getText().equals("6"):"Actual value is : "+results.getText()+" did not match with expected value: 6";
System.out.println("Inside Test Function");
terClass
public void teardown(){
driver.closeApp();
}
}
package com.appiumproj.test;
import io.appium.java_client.AppiumDriver;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.remote.MobileCapabilityType;
import java.net.MalformedURLException;
import java.net.URL;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.testng.annotations.*;
public class Appium {
AppiumDriver driver;
#BeforeClass
public void setUp() throws MalformedURLException{
//Set up desired capabilities and pass the Android app-activity and app-package to Appium
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(MobileCapabilityType.VERSION, "5.0.2");
capabilities.setCapability(MobileCapabilityType.PLATFORM_NAME, "Android");
capabilities.setCapability(MobileCapabilityType.DEVICE_NAME,"ZX1D62FPVQ");
capabilities.setCapability(MobileCapabilityType.APP_PACKAGE, "com.android.calculatord"); // This is package name of your app (you can get it from apk info app
capabilities.setCapability(MobileCapabilityType.APP_ACTIVITY, "com.android.calculator2.Calculator"); // This is Launcher activity of your app (you can get it from apk info app)
//Create AndroidDriver instance and connect to the Appium server.
//It will launch the Calculator App in Android Device using the configurations specified in Desired Capabilities
driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
}
#Test
public void testCal(){
//locate the Text on the calculator by using By.name()
WebElement two=driver.findElement(By.name("2"));
two.click();
WebElement plus=driver.findElement(By.name("+"));
plus.click();
WebElement four=driver.findElement(By.name("4"));
four.click();
WebElement equalTo=driver.findElement(By.name("="));
equalTo.click();
//locate the edit box of the calculator by using By.className()
WebElement results=driver.findElement(By.className("android.widget.EditText"));
//Check the calculated value on the edit box
assert results.getText().equals("6"):"Actual value is : "+results.getText()+" did not match with expected value: 6";
/*
System.out.println("Inside Test Function");
driver.findElement(By.partialLinkText("More")).click();
driver.findElement(By.xpath("//EditText[#text='Email Address']")).sendKeys("tester#gmail.com");
driver.findElement(By.xpath("//LinearLayout/EditText[2]")).sendKeys("Testerpwd");
driver.findElement(By.xpath("//CheckBox")).click();
driver.findElement(By.xpath("//Button[#text='Login']")).click();
WebDriverWait wait = new WebDriverWait(driver,80);
wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath("//Button[#text='Logout']")));
driver.findElement(By.xpath("//Button[#text='Logout']")).click();
*/
}
#AfterClass
public void teardown(){
//close the app
driver.closeApp();
}
}
Give the exact Ip address on the Appium Instance running on Machine 2. By default it is 127.0.0.1, remove this and give its own IP address explicitly in Appium settings. This will work. Let me know if not.
Related
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);
}
}
This question already exists:
How to run a Java Selenium test on an incognito Google Chrome profile
Closed 2 years ago.
I hope that you're fine. I'm new at Java Selenium automation, what I want to do is I want to run a test on a certain website but not in a clean session of ChromeDriver I would like to use a certain profile of mine I name it "test" its shortcut in the Desktop is "test.lnk", here what I did:
import static org.testng.Assert.assertEquals;
import org.openqa.selenium.By;
import org.openqa.selenium.By.ByXPath;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
//import org.openqa.selenium.edge.EdgeDriver;
import org.testng.annotations.Test;
public class AutomationTest {
WebDriver driver;
#BeforeTest
public void setUp() {
ChromeOptions options = new ChromeOptions();
options.addArguments("user-data-dir=C:/Users/user_name/AppData/Local/Google/Chrome/User Data/test");
options.addArguments("--start-maximized");
driver = new ChromeDriver(options);
// driver = new ChromeDriver();
driver.get("https://www.rapidtables.com/tools/click-counter.html");
driver.manage().window().maximize();
}
#Test
public void testRegister() throws InterruptedException {
do {
Thread.sleep(3000);
driver.findElement(By.id("addbtn")).click();
} while(true);
}
#AfterTest
public void tearDown() {
// driver.close();
}
}
```
chrom_options.add_argument("user-data-dir=C:/Users/user_name/AppData/Local/Google/Chrome/User Data")
chrom_options.add_argument("profile-directory=test)
specify only the user data folder in userdata dir argument
Pass profile directory separately
I am beginner to Apium and java, i was looking for a solution to driver.scrollTo("Views"), i tried the below code , while running i was getting the following error:
A new session could not be created. (Original error: Activity used to start app doesn't exist or cannot be launched! Make sure it exists and is a launchable activity) (WARNING: The server did not provide any stacktrace information)
package Android;
import static org.junit.Assert.assertNotNull;
import io.appium.java_client.android.AndroidDriver;
import java.net.URL;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
public class ScrollingToText {
AndroidDriver driver;
#BeforeTest
public void setUp() throws Exception {
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("deviceName", "0123456789ABCDEF");
capabilities.setCapability("browserName", "Android");
capabilities.setCapability("platformVersion", "5.0");
capabilities.setCapability("platformName", "Android");
capabilities.setCapability("appPackage", "com.hmh.api");
capabilities.setCapability("appActivity","com.hmh.ApiDemos");
driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);
}
#Test
public void findScrollable() throws InterruptedException {
//Scroll till element which contains "Views" text If It Is not visible on screen.
// driver.scrollTo("Views");
driver.findElementByAccessibilityId("Views").click();
WebElement radioGroup = driver.findElementByAndroidUIAutomator("new UiScrollable(new UiSelector()"+ ".resourceId(\"android:id/list\")).scrollIntoView("
+ "new UiSelector().text(\"Radio Group\"));");
assertNotNull(radioGroup.getLocation());
// Click on Views/.
driver.findElement(By.name("Views")).click();
System.out.println("Scrolling has been started to find text -> Tabs.");
// Scroll till element which contains Tabs text.
// driver.scrollTo("Tabs");
driver.findElementByAccessibilityId("Tabs").click();
System.out.println("Tabs text has been found and now clicking on It.");
// Click on Tabs.
driver.findElement(By.name("Tabs")).click();
}
#AfterTest
public void End() {
driver.quit();
}
}
(Original error: Activity used to start app doesn't exist or cannot be launched! Make sure it exists and is a launchable activity)
Above error come when you don't have application installed on your device.
Please install it first and then run your test script it should run.
Hope these help you.
I need help with following combination,
OS: Windows 10
Browser used :Firefox 45.0.1
Java version:Java 8 update 51( 64 bit)
Selenium : library 2.47.1
Our code is simple.
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.LogManager;
import org.testng.annotations.Test;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.AfterClass;
import java.util.List;
import java.util.concurrent.TimeUnit;
import org.testng.Assert;
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.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
public class TestClass01
{
static final Logger logger1 = LogManager.getLogger(TestClass01.class.getName());
WebDriver driver ;
String baseUrl ;
static int testCount = 0 ;
String[] content_heading ;
List<WebElement> temp_list ;
WebDriverWait wait;
boolean exists;
#BeforeClass
public void beforeClass()
{
logger1.entry();
logger1.info("Entering the class : " + this.getClass().getSimpleName() );
driver = new FirefoxDriver();
baseUrl = "http://www.google.com";
logger1.info("Maximizing the browser window and setting up the implicit timeout for element/page loading....");
driver.manage().window().maximize();
//Specifies the amount of time the driver should wait when searching for an element
driver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);
logger1.info("Fetching the Homepage for Jacuzzi");
// launch Firefox and direct it to the Base URL
driver.get(baseUrl+"/");
}
}
However, it throws following error,
org.openqa.selenium.firefox.NotConnectedException: Unable to connect
to host 127.0.0.1 on port 7055 after 45000 ms. Firefox console output:
DEBUG Updating XPIState for
{"id":"{972ce4c6-7e08-4474-a285-3208198ce6fd}","syncGUID":"BbZlO30v46U7","location":"app-global","version":"45.0.1","type":"theme","internalName":"classic/1.0","updateURL":null,"updateKey":null,"optionsURL":null,"optionsType":null,"aboutURL":null,"icons":{"32":"icon.png","48":"icon.png"},"iconURL":null,"icon64URL":null,"defaultLocale":{"name":"Default","description":"The
default
theme.","creator":"Mozilla","homepageURL":null,"contributors":["Mozilla
Contributors"]},"visible":true,"active":true,"userDisabled":false,"appDisabled":false,"descriptor":"C:\Program
Files (x86)\Mozilla
Firefox\browser\extensions\{972ce4c6-7e08-4474-a285-3208198ce6fd}.xpi","installDate":1458533973089,"updateDate":1458533973089,"applyBackgroundUpdates":1,"skinnable":true,"size":22012,"sourceURI":null,"releaseNotesURI":null,"softDisabled":false,"foreignInstall":false,"hasBinaryComponents":false,"strictCompatibility":true,"locales":[],"targetApplications":[{"id":"{ec8030f7-c20a-464f-9b0e-13a3a9e97384}","minVersion":"45.0.1","maxVersion":"45.0.1"}],"targetPlatforms":[],"seen":true}
This was happening because of new issue in latest browser of firefox.
Update your selenium jars. The new version of firefox(Or different browser) is not supporting old jars of selenium.
Download both Selenium Server (formerly the Selenium RC Server) Selenium Client & WebDriver Language Bindings
Replace them with old jars you are using. Update your mozilla also so you can get the updated results
source :- http://docs.seleniumhq.org/download/
To overcome from this issue you also need to setPreference as xpinstall.signatures.required", false to firefox Profile and then pass it to driver object
firefoxProfile.setPreference("xpinstall.signatures.required", false);
Below code is working fine for me.
static WebDriver driver=null;
public static void main(String[] args) {
final FirefoxProfile firefoxProfile = new FirefoxProfile();
firefoxProfile.setPreference("xpinstall.signatures.required", false);
driver = new FirefoxDriver(firefoxProfile);
driver.get("https://www.google.de/");
Hope it will help you :)
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