Отображает related problem при подставлении переменной вместо стрингового значения в аннотации Appium @AndroidFindBy ( переменная)
Изучаю Аппиум. Столкнулся с такой проблемой: в IDEA отобажает Related problem над переменной, которую я использую для сохранения части ID. Дело в том, что первая часть ID элемента состоит из appPackagе, а вторая -это id элемента на экране аппиум. Мне нужно, чтоб первая часть была изменяемая. Я ее поместил в String переменную. И во всех классах моей программы это работате, кроме одного.
public class BaseSetup < //обьявление переменных private DesiredCapabilities cb =new DesiredCapabilities(); private static AndroidDriver ad =null; private String port = "4723"; private String server = "127.0.0.1"; **//тут я объявляю эту переменную, которая имеет значение для appPackage** protected String myapp = "com.covantex.mediker"; @BeforeClass //публичный класс для вызова приватного класса public void setUp() throws MalformedURLException < initDriver(); >/* метод который будет возвращать драйвер для передачи его следующим страницам при переходе на другие активити а так же получения драйвера в пределах текущего активити */ public AndroidDriver getDriver() < return ad; >//приватный класс с данными для запуска сессии private void initDriver() throws MalformedURLException < //создание экземпляра класа для передачи парамеров запуска приложения на устройстве DesiredCapabilities ds =new DesiredCapabilities(); ds.setCapability(MobileCapabilityType.DEVICE_NAME,"374c3291"); ds.setCapability("platformName", "Android"); ds.setCapability( "appPackage", myapp); ds.setCapability( "appActivity", "com.meetMyDoc.ui.activity.LoginActivity"); ds.setCapability("noReset",true ); String url = "http://"+server+":"+port+"/wd/hub"; //инициализация андроид райвера + ексепшин для отлова ошибок try< System.out.println("Драйвер проинициализирован с такими данными: " + url); ad = new AndroidDriver(new URL(url), ds); >catch (NullPointerException|MalformedURLException ex) < throw new RuntimeException("Андроид драйвер не может быть проинициализирован :("); >System.out.println("Не инициализирован: " +ad); > >
// наследование от BaseSetup public class Driver extends BaseSetup < protected AndroidDriver ad; //это конструктор, где происходит инициализация драйвера родителя protected Driver()< this.ad = super.getDriver(); >>
От драйвера наследуется MainPage, в котором я тоже использую переменную myapp как части id для нахождения элемента на экране.
public class MainPage extends Driver < public void clickBtn() throws InterruptedException < Thread.sleep(3000); MobileElement el3 = (MobileElement) ad.findElementById(myapp + ":id/btnLogin"); el3.click(); >public void sendCredentials() throws InterruptedException < Thread.sleep(2500); //тут работает MobileElement el1 = (MobileElement) ad.findElementById( myapp + ":id/etUserName"); el1.sendKeys("admin"); // и тут работает MobileElement el2 = (MobileElement) ad.findElementById( myapp + ":id/etPassword"); el2.sendKeys("admin"); >
Дальше я использую класс ScreenFormPF. Именно в нем я пытаюсь использовать myapp переменную. Именно в аннотации. И тут эта переменная подчеркивается красным. И пишет Related problem.
public class ScreenFormPF extends MainPage < public ScreenFormPF( )< PageFactory.initElements(new AppiumFieldDecorator(ad), this); >// тут уже не работает и подчеркивает красным @AndroidFindBy(id = "com.covantex.mediker:id/etUserName") private AndroidElement login; // тут тоже не работает @AndroidFindBy(id = "com.covantex.mediker:id/etPassword") private AndroidElement password; >
Java related problems and their possible solutions
In this page you will see the common java related problems you face during your day to day activity. We are listing out all common problems and its solutions here. If you have come across any java related issues, please let us know, we will update here. It will be very helpful for others to resolve it very quickly.
Java problems and solutions
Unable to install Java 7 in Eclipse on Mac — Java 7 Mac OS issues
How to change Java (JVM) version in Mac OS? — Java version Mac OS issues
SunCertPathBuilderException: Unable To Find Valid Certification Path To Requested Target
How to merge two jssecacerts files? — Merge key store files
How to write Micro-Benchmark for java Hotspot?
servlet-api-2.5.jar — jar not loaded — tomcat error
How to exclude property files in a jar using Maven
ServletOutputStream: ServletResponse.getOutputStream() returns a ServletOutputStream suitable for writing binary data in the response. The servlet container does not encode the binary data, it sends the raw data as it is.
PrintWriter: ServletResponse.getWriter() returns PrintWriter object which sends character text to the client. The PrintWriter uses the character encoding returned by getCharacterEncoding(). If the response’s character encoding has not been specified then it does default character encoding.
About Author
I’m Nataraja Gootooru, programmer by profession and passionate about technologies. All examples given here are as simple as possible to help beginners. The source code is compiled and tested in my dev environment.
If you come across any mistakes or bugs, please email me to [email protected] .
3. Console News: Property ‘Datasource’ Is Required
Java.lang.illegalargumentException: Property 'DataSource' Is Required is that DataSource is required Dataource is empty when using DAO. Check the JDBCUTILS tool class, find that the class loader loads the druid.properties file, then use the class loader if it is obtained from classpath. So don't need to be added /
4. Console notes: org.springframework.dao.emptyResultDataAccessException: IncorRect Result Size: Expected 1, Actual 0
Error message org.springframework.dao.EmptyResultDataAccessException: Incorrect result size: expected 1, actual 0 at org.springframework.dao.support.DataAccessUtils.requiredSingleResult(DataAccessUtils.java:71) at org.springframework.jdbc.core.JdbcTemplate.queryForObject(JdbcTemplate.java:812)
plan queryForObject is not recorded when there is no record, and this exception will not throw this exception for the type of Query () LIST. The solution is to capture this exception and then return NULL in catch. The modification code is as follows:
@Override public User findByUsername(String username) < User user=null; try< // 1. Define SQL String sql="select * from tab_user where username= ?"; // 2. Execute SQL user= template.queryForObject(sql, new BeanPropertyRowMapper(User.class), username); >catch (Exception e) < return null; >>
5.java.lang.NoSuchMethodException
problem java.lang.NoSuchMethodException: cn.itcast.travel.web.servlet.UserServlet.add(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse) at java.base/java.lang.Class.getMethod(Class.java:2113) at cn.itcast.travel.web.servlet.BaseServlet.service(BaseServlet.java:31) at javax.servlet.http.HttpServlet.service(HttpServlet.java:728) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210) at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:51) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210) at cn.itcast.travel.web.filter.CharchaterFilter.doFilter(CharchaterFilter.java:30) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100) at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408) at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1041) at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:603) at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310) at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128) at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628) at java.base/java.lang.Thread.run(Thread.java:835) Request path / travel // user / find Method name FIND [email protected] java.lang.NoSuchMethodException: cn.itcast.travel.web.servlet.UserServlet.find(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse) at java.base/java.lang.Class.getMethod(Class.java:2113) at cn.itcast.travel.web.servlet.BaseServlet.service(BaseServlet.java:31)
8. Interellij IDEA Settings a single line of travel Release Remove extra spaces
Question: When the Java code uses shortcuts «Ctrl + /» to add a line comment, it is found to have extra spaces:
Solve: Open IDEA: File> Settings> Editor> Code Style> Java> Checking Use Tab Character Indicates that Tab indent does not use a space to use tab, and the above excess space problem occurs if you use spaces. Finally, formatted the following code: «Ctrl + Alt + L»
problem:
Solution:
problem:
solution:
9mAven Since his agreement is greater than the configuration, we can experience the profile we write, unable to be exported or taken effect,
Default is false true filtering> This configuration means that the placeholder in the specified properties file is filtered, the placeholder is the form of $ , and Maven will automatically read the configuration file, then resolve the placeholder, use the above POM file. Defined attributes replace ->