iOS driver is not visible


#1

Hi I am facing this issue where while initializing the driver via PageFactory in one class is not recognizing the driver of the Base Class.

Please help me out!

TestBaseClass:
package com.myLexiaTest.qa.base;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.net.URL;
import java.util.Properties;

import org.openqa.selenium.remote.DesiredCapabilities;

import io.appium.java_client.MobileElement;
import io.appium.java_client.ios.IOSDriver;
import io.appium.java_client.remote.MobileCapabilityType;
import io.appium.java_client.service.local.AppiumDriverLocalService;
import io.appium.java_client.service.local.AppiumServiceBuilder;

public class TestBase {
public static IOSDriver driver;
public static Properties prop;
public static AppiumDriverLocalService server;

public TestBase() {
	
	
	prop= new Properties();
	try {
		FileInputStream fis= new FileInputStream("/MobilemyLexiaTest/src/main/java/com/myLexiaTest/qa/config/config.properties");
	    try {
			prop.load(fis);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
			} catch (FileNotFoundException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
	
	
	
}

public void StartAppiumServer() {
	server =AppiumDriverLocalService
	   		  .buildService(new AppiumServiceBuilder().usingDriverExecutable(new File ("/usr/local/bin/node"))
	   		  .withAppiumJS(new File ("/Applications/Appium.app/Contents/Resources/app/node_modules/appium/build/lib/main.js"))
	   	  .withLogFile(new File("/Users/admin/Desktop/AppiumLog/log.txt")));
	   
	     server.start();
}

public void StopAppiumServer() {
	
	server.stop();
}

public void initialization() throws Exception 
{
	DesiredCapabilities cap = new DesiredCapabilities();
	File f= new File("/Users/admin/Library/Developer/Xcode/DerivedData/myLexia-1-evmhciyjkfapmhcjqcdjufczofys/Build/Products/Debug-iphonesimulator/myLexia.app");
	cap.setCapability(MobileCapabilityType.PLATFORM_NAME, prop.getProperty("PlatformName"));	
	cap.setCapability(MobileCapabilityType.PLATFORM_VERSION,prop.getProperty("PlatformVersion"));
	cap.setCapability(MobileCapabilityType.DEVICE_NAME, prop.getProperty("DeviceName"));
	cap.setCapability(MobileCapabilityType.BROWSER_NAME,prop.getProperty("BrowserName"));
	cap.setCapability(MobileCapabilityType.AUTOMATION_NAME, prop.getProperty("AutomationName"));
	cap.setCapability(MobileCapabilityType.NEW_COMMAND_TIMEOUT,prop.getProperty("TimeOut"));
	cap.setCapability(MobileCapabilityType.APP,f.getAbsolutePath());
	
		driver = new IOSDriver<MobileElement>(new URL("http://127.0.0.1:4723/wd/hub"),cap);
		try {
			Thread.sleep(5000);
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		driver.switchTo().alert().dismiss();
	
	
	
	
	

}

}

LoginPageClass:

package com.myLexiaTest.qa.pages;

import org.openqa.selenium.support.PageFactory;
import com.myLexiaTest.qa.base.TestBase;

import io.appium.java_client.MobileElement;
import io.appium.java_client.pagefactory.iOSFindBy;

public class LoginPage extends TestBase{

//Page Factory -OR
@iOSFindBy(id="Email")
MobileElement email;

@iOSFindBy(id="Password")
MobileElement password;


@iOSFindBy(id="Log in")
MobileElement LoginBtn;



public LoginPage() {
	
PageFactory.initElements(driver,this);  // Here error is coming showing "The field TestBase.driver is not visible"
}

public HomePage login(String un,String pwd) {
	email.sendKeys(un);
	password.sendKeys(pwd);
	LoginBtn.click();
	return new HomePage();
	
}

}


#2

I think you should use TestBase.driver, instead of driver