forked from cucumber/cucumber-java-skeleton
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathHooks.java
68 lines (56 loc) · 1.99 KB
/
Hooks.java
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
61
62
63
64
65
66
67
68
/**
* ownCloud Android Scenario Tests
*
* @author Jesús Recio Rincón (@jesmrec)
*/
package io.cucumber;
import android.AndroidManager;
import org.xml.sax.SAXException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.logging.Level;
import javax.xml.parsers.ParserConfigurationException;
import io.cucumber.java.After;
import io.cucumber.java.Before;
import io.cucumber.java.Scenario;
import utils.LocProperties;
import utils.entities.OCFile;
import utils.log.Log;
public class Hooks {
private World world;
public Hooks(World world) {
this.world = world;
}
@Before
public void setup(Scenario scenario) {
Log.log(Level.FINE, "START SCENARIO EXECUTION: " + scenario.getName());
AndroidManager.getDriver().activateApp(
LocProperties.getProperties().getProperty("appPackage"));
}
@After
public void tearDown(Scenario scenario)
throws IOException, ParserConfigurationException, SAXException {
AndroidManager.getDriver().terminateApp(
LocProperties.getProperties().getProperty("appPackage"));
cleanUp();
Log.log(Level.FINE, "END SCENARIO EXECUTION: " + scenario.getName() + "\n\n");
}
private void cleanUp()
throws IOException, ParserConfigurationException, SAXException {
//First, remove leftovers in root folder for every user
ArrayList<String> userNames = new ArrayList<>(Arrays.asList("Alice", "Bob"));
for (String userToClean: userNames) {
ArrayList<OCFile> filesRoot = world.filesAPI.listItems("", userToClean);
for (OCFile iterator : filesRoot) {
world.filesAPI.removeItem(iterator.getName(), userToClean);
}
//Empty trashbins
world.trashbinAPI.emptyTrashbin(userToClean);
}
//Remove spaces
if (world.authAPI.isOidc()) { //remove spaces
world.graphAPI.removeSpacesOfUser();
}
}
}