Today wrote a simple upward swipe, performing to the upward slide operation, reported Nullpoint exception, after a variety of disorderly touch finally solved, now record the process, for future reference!
Environmental background: Java+testng+appium
The @test is lowered with direct_slide_f ("Up"); This method, the initial member variable up I was not initialized, but simply declared a bit, and then in the call of the time, did not pass "up", incredibly passed the variable up;
And if (Direct.equals (This.getup ())) {This code is preceded by an if (direct.equals (UP)) {This is written, so the Nullpoint is reported.
The reason is that direct_slide_f should receive a specific string parameter, and I passed an uninitialized variable up, so the program does not know what to compare with the up, of course, this time the up itself has no value,
Actually is equal to take oneself and oneself do contrast, then report Nullpoint!
Modify the scenario: The variable up is initialized, and then call the method Direct_slide_f, the string "Up", and not the variable up, execution will not be reported Nullpoint!
Summary: If the code is nullpoint after adding a new piece of code, first check the relationship of variables and methods in the newly added code!
public class Login extends Keyclass implements baseexecuteinterface{
Public Login () {}
Private Boolean isinstall = false;
public static Androiddriver driver;
Public final String up = "Up";
@Test
public void Login_f_tmp () throws exception{
String username= "18576816231";
String passwd= "123456";
Driver.findelement (By.id ("Com.jiubei.shop:id/telephoneet")). SendKeys (username);
Thread.Sleep (2000);
Driver.findelement (By.id ("Com.jiubei.shop:id/ed_pwd")). SendKeys (passwd);
Thread.Sleep (2000);
SYSTEM.OUT.PRINTLN ("test");
Key ();
Driver.findelement (By.id ("Com.jiubei.shop:id/submittv")). Click ();
System.out.println ("Test2");
Has entered the app home page
Thread.Sleep (4000);
Driver.findelement (By.name ("my")). Click ();
Sleep (1);
Direct_slide_f ("Up");
}
Call out null pointer, now fixed
public void Direct_slide_f (String direct) {
touchaction touchaction =new touchaction (driver);
if (Direct.equals (This.getup ())) {
touchaction.longpress (720). MoveTo (+). Release (). perform ();
System.out.println (UP);
sleep (3);
}else if (Direct.equals ((This.getdown ())) {
touchaction.longpress (MoveTo, 720). Release (). perform ();
sleep (3);
}else {
SYSTEM.OUT.PRINTLN ("parameter Error");
sleep (3);
}
}
Alas, the ability to test code in general, always out of all kinds of cabbage errors, please casually spray! haha haha!
Appium Test Code Nullpoint