-
Notifications
You must be signed in to change notification settings - Fork 1
/
SwitchViews(Web and Native)
60 lines (52 loc) · 1.79 KB
/
SwitchViews(Web and Native)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import java.util.Set;
import org.openqa.selenium.WebDriver;
import com.testsigma.customfunc.common.CustomTestStep;
import com.testsigma.customfunc.common.TestsigmaCustomFunctions;
import com.testsigma.customfunc.result.ResultConstants;
import com.testsigma.customfunc.result.TestStepResult;
import io.appium.java_client.AppiumDriver;
public class Switchview extends TestsigmaCustomFunctions {
@CustomTestStep
public TestStepResult SwitchtoNative() throws InterruptedException {
AppiumDriver ad = (AppiumDriver) driver;
try {
@SuppressWarnings("unchecked")
Set<String> contexts = ad.getContextHandles();
for (String contextName : contexts) {
System.out.println(contextName);
}
ad.context((String) contexts.toArray()[0]);
TestStepResult result=new TestStepResult();
result.setStatus(ResultConstants.SUCCESS);
result.setMessage("Switched to Context" +contexts.toArray()[0]);
return result;
}
catch(Exception e) {
TestStepResult result=new TestStepResult();
result.setStatus(ResultConstants.FAILURE);
result.setMessage("Exception Occured!");
return result;
}
}
@CustomTestStep
public TestStepResult SwitchtoWebView() throws InterruptedException {
AppiumDriver ad = (AppiumDriver) driver;
try {
@SuppressWarnings("unchecked")
Set<String> contexts = ad.getContextHandles();
for (String contextName : contexts) {
System.out.println(contextName);
}
ad.context((String) contexts.toArray()[1]);
TestStepResult result=new TestStepResult();
result.setStatus(ResultConstants.SUCCESS);
result.setMessage("Switched to Context"+contexts.toArray()[1]);
return result;
}
catch(Exception e) {
TestStepResult result=new TestStepResult();
result.setStatus(ResultConstants.FAILURE);
result.setMessage("Exception Occured!");
return result;
}
}}