This is a BeforeClass that I was creating (Java, Appium, TestNG)
private AndroidDriver driver;
#BeforeClass
public void setUp() throws MalformedURLException{
DesiredCapabilities desiredCapabilities = new DesiredCapabilities();
desiredCapabilities.setCapability(MobileCapabilityType.APPIUM_VERSION, "1.7.1");
desiredCapabilities.setCapability(MobileCapabilityType.PLATFORM_NAME,"Android");
desiredCapabilities.setCapability("deviceName", "9NLJA17619012618");
desiredCapabilities.setCapability("appActivity", ".activity.LaunchActivity");
desiredCapabilities.setCapability("appPackage", "com.aaa.app");
desiredCapabilities.setCapability("platformVersion", "7.1.2");
URL url = new URL("http://localhost:4723/wd/hub");
driver = new AndroidDriver(url,desiredCapabilities);
}
(I know there is a mix of MobileCapabilityType and others without that format, but that i not the point I think)
And then a bunch of #Test
This error appeared:
Failed tests: setUp(tests.TestShop):
class io.appium.java_client.android.AndroidDriver has interface io.appium.java_client.AppiumDriver as super class
Any Clue?
add MobileElement or WebElement while initializing appium driver.
driver = new AndroidDriver<MobileElement>(url,desiredCapabilities);
Also change your deviceName to udid. Also make sure your appActivity is correct.
Your code must be like following:
#BeforeClass
public void setUp() throws MalformedURLException{
DesiredCapabilities desiredCapabilities = new DesiredCapabilities();
desiredCapabilities.setCapability("platformName","Android");
desiredCapabilities.setCapability("deviceName", "Any name");
desiredCapabilities.setCapability("udid", "9NLJA17619012618");
desiredCapabilities.setCapability("appActivity", ".activity.LaunchActivity");
desiredCapabilities.setCapability("appPackage", "com.aaa.app");
desiredCapabilities.setCapability("platformVersion", "7.1.2");
URL url = new URL("http://localhost:4723/wd/hub");
driver = new AndroidDriver<MobileElement>(url,desiredCapabilities);
}
Related
I am getting so many unnecessary logs in red color while performing headless testing using phantom js.
How to remove all those red color logs
public class Utility
{
private static WebDriver driver=new PhantomJSDriver();
public static WebDriver getDriver()
{
return driver;
}
}
Here is what you need to do to suppress the INFO logs:
File src = new File("C:\\Utility\\phantomjs-2.1.1-windows\\bin\\phantomjs.exe");
System.setProperty("phantomjs.binary.path", src.getAbsolutePath());
DesiredCapabilities dcap = new DesiredCapabilities();
String[] phantomArgs = new String[] {
"--webdriver-loglevel=NONE"
};
dcap.setCapability(PhantomJSDriverService.PHANTOMJS_CLI_ARGS, phantomArgs);
PhantomJSDriver driver = new PhantomJSDriver(dcap);
driver.get("https://www.facebook.com/");
Let me know if it works for you.
I can't connect my BrowserFactory to Selenium Grid. Any ideas why the following code won't work?
public static WebDriver getDriver() throws Exception {
try {
// Load the driver selected by user
Properties p = new Properties();
FileInputStream fi = new FileInputStream(Constant.CONFIG_PROPERTIES_DIRECTORY);
p.load(fi);
if(p.getProperty("use_grid").equalsIgnoreCase("true")) {
DesiredCapabilities desiredCapabilities = new DesiredCapabilities();
desiredCapabilities.getBrowserName();
desiredCapabilities.setPlatform(Platform.WINDOWS);
return new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), desiredCapabilities);
}
String browserName = p.getProperty("browser");
switch (browserName) {
case "firefox":
if (null == webdriver) {
System.setProperty("webdriver.gecko.driver", Constant.GECKO_DRIVER_DIRECTORY);
webdriver = new FirefoxDriver();
}
break;
I have the node and grid up and running successfully.
Thanks.
It looks like you're not setting the browser when using selenium grid. Try changing this line:
desiredCapabilities.getBrowserName();
to this:
desiredCapabilities.setBrowserName("firefox");
or this if you're properties are in the correct format and that code is working correctly:
desiredCapabilities.setBrowserName(p.getProperty("browser"));
I am trying to run Selenium Webdriver script in Chrome, have added following lines in my existing script
System.setProperty("webdriver.chrome.driver", "C:\\Users\\Garimaari\\IdeaProjects\\Webdriver testing\\Chromedriver\chromedriver.exe");
private WebDriver driver = new ChromeDriver();
I am building my script in Intellij using Java. Not sure why i am getting "can not resolve symbol setProperty". I tried changing JRE and JDK files but nothing has worked. Any help would be appreciated.
Adding code
public class StartCaseJava extends TestCase {
private boolean acceptNextAlert = true;
private StringBuffer verificationErrors = new StringBuffer();
// Getting Date and Timestamp for Last Name
Date d = new Date();
SimpleDateFormat dateFormat = new SimpleDateFormat("MMddyyHHmmss");
public void setUp() throws Exception {
System.setProperty("webdriver.chrome.driver", "C:\\Users\\Garimaari\\IdeaProjects\\Webdriver testing\\Chromedriver\\chromedriver.exe");
// private WebDriver driver = new ChromeDriver();
// driver = new FirefoxDriver();
// driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
}
private WebDriver driver = new ChromeDriver();
public void testStartCaseJava() throws Exception {
// System.setProperty("webdriver.chrome.driver", "C:\\Users\\Garimaari\\IdeaProjects\\Webdriver testing\\Chromedriver\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
It's a long shot but should this
C:\Users\Garimaari\IdeaProjects\Webdriver testing\Chromedriver\chromedriver.exe")
maybe be renamed to C:\Users\Garimaari\IdeaProjects\Webdriver testing\Chromedriver\chromedriver.exe")
or are the double back slashes actually a necessary feature?
This might be because of one missing '\' before chromedriver.exe in your setProperty string.
Try using :
System.setProperty("webdriver.chrome.driver", "C:\\Users\\Garimaari\\IdeaProjects\\Webdriver testing\\Chromedriver\\chromedriver.exe");
I am able to run my script using Chrome now. Here is the small sample declaration I used:
class StartCaseJAva {
static WebDriver driver;
public void testcasejava()) {
System.setProperty(path);
driver = new ChromeDriver();
}
}
public class FooTest {
WebDriver driver;
#Before
public void beforeTest() {
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setJavascriptEnabled(true);
capabilities.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
driver = new PhantomJSDriver(capabilities);
driver.manage().timeouts().pageLoadTimeout(10, TimeUnit.SECONDS);
}
#Test
public void test() {
driver.get("http://www.example.com");
WebElement e = driver.findElement(By.tagName("h1"));
System.out.println("TEXT" + e.getAttribute("innerHTML"));
assertNotNull(e);
driver.quit();
}
}
Hi, I'm just simply trying get the h1 tag in www.example.com which says "Example Domain." The code works for http://www.example.com but not for https://www.exmaple.com. How can I fix this problem? Thanks
PhantomJSDriver does not support (all) DesiredCapabilities.
You will need:
caps = new DesiredCapabilities();
caps.setJavascriptEnabled(true);
caps.setCapability(PhantomJSDriverService.PHANTOMJS_CLI_ARGS, new String[] {"--web-security=no", "--ignore-ssl-errors=yes"});
driver = new PhantomJSDriver(caps);
Documented here: https://github.com/detro/ghostdriver/issues/233
Am new to this PhantomjsDriver in selenium webdriver.I need to run my selenium scripts in server without GUI. Please can anybody tell me how to achieve this. I need a head's up from the start of how to configure Phantomjs Driver,usage in server and rest.Below is my selenium code which i run through GUI , now i have to run these cases in server without GUI. What modifications i have to do so hat i can achieve the above task.
public static void main(String[] args) throws IOException{
login =args[0];
user = args[1];
pwd = args[2];
TestListenerAdapter tla = new TestListenerAdapter();
TestNG testng = new TestNG();
testng.setOutputDirectory(args[3]);
testng.setTestClasses(new Class[] {
CreateMultiRecordTest.class, UpdateMultiRecordTest.class,
DeleteMultiRecordTest.class
});
testng.addListener(tla);
testng.run();
Finally after a weeks time i found a solution to configure PhantomJs for my framework.Here's the solution.
DesiredCapabilities cap = new DesiredCapabilities();
java.io.File f = new java.io.File("");
String path = f.getAbsolutePath()+"\\ghostdriver-master\\src\\main.js";
cap.setCapability(PhantomJSDriverService.PHANTOMJS_GHOSTDRIVER_PATH_PROPERTY,path);
driver = new PhantomJSDriver(cap);
This worked for me:
DesiredCapabilities dCaps = new DesiredCapabilities();
dCaps.setJavascriptEnabled(true);
dCaps.setCapability("takesScreenshot", false);
dCaps.setCapability(PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY,"C:\\phantomjs-1.9.7-windows\\phantomjs.exe");
PhantomJSDriver driver = new PhantomJSDriver(dCaps);
...