예제 #1
0
 @Override
 public List<String> getWebPaths(final Resource<?> r) {
   if (r != null) {
     WebResourceFacet web = project.getFacet(WebResourceFacet.class);
     List<DirectoryResource> webRootDirectories = web.getWebRootDirectories();
     for (DirectoryResource d : webRootDirectories) {
       if (r.getFullyQualifiedName().startsWith(d.getFullyQualifiedName())) {
         String path = r.getFullyQualifiedName().substring(d.getFullyQualifiedName().length());
         return getWebPaths(path);
       }
     }
   }
   return new ArrayList<String>();
 }
예제 #2
0
  @Override
  public Resource<?> getCurrentResource() {
    Resource<?> result = this.projectContext.getCurrentResource();
    if (result == null) {
      result = this.resourceFactory.getResourceFrom(Files.getWorkingDirectory());
      environment.setProperty("CWD", result.getFullyQualifiedName());
    }

    return result;
  }
예제 #3
0
  @Override
  public List<String> getWebPaths(Resource<?> r) {
    List<String> results = new ArrayList<String>();

    if (r != null) {
      WebResourceFacet web = project.getFacet(WebResourceFacet.class);
      List<DirectoryResource> webRootDirectories = web.getWebRootDirectories();
      for (DirectoryResource d : webRootDirectories) {
        if (r.getFullyQualifiedName().startsWith(d.getFullyQualifiedName())) {
          String path = r.getFullyQualifiedName().substring(d.getFullyQualifiedName().length());

          for (String p : getWebPaths(path)) {
            if (!results.contains(p)) results.add(p);
          }
          break;
        }
      }
    }
    return results;
  }
  @Command(value = "new-element", help = "Create a new WebElement in the current class")
  public void newElement(
      @Option(required = true, name = "named", help = "the element name") String name,
      @Option(required = true, name = "findby", help = "the locator name") FindByType findBy,
      @Option(required = true, name = "value", help = "the locator value") String value,
      @Option(required = false, name = "fragmentClass", help = "the Page Fragment class")
          Resource<?> fragmentClass,
      final PipeOut out)
      throws Exception {
    final JavaSourceFacet java = project.getFacet(JavaSourceFacet.class);

    JavaClass javaClass = getJavaClass();

    if (javaClass.hasField(name)) {
      throw new IllegalStateException("Class already has a field named [" + name + "]");
    }

    Field<JavaClass> field = javaClass.addField();
    field.setName(name).setPrivate();
    if (fragmentClass != null) {

      JavaClass javaFragment =
          JavaParser.parse(JavaClass.class, fragmentClass.getResourceInputStream());
      if (javaFragment == null) {
        throw new IllegalStateException(
            "Class notfound in test resources [" + fragmentClass.getFullyQualifiedName() + "]");
      }
      field.setType(javaFragment.getQualifiedName());
    } else {
      field.setType("org.openqa.selenium.WebElement");
    }
    Annotation<JavaClass> annotation =
        field.addAnnotation("org.jboss.arquillian.graphene.enricher.findby.FindBy");
    annotation.setStringValue(findBy.name(), value);
    javaClass
        .addMethod()
        .setReturnType(field.getTypeInspector().toString())
        .setName("get" + Strings.capitalize(name))
        .setPublic()
        .setBody("return this." + name + ";");

    java.saveTestJavaSource(javaClass);

    shell.println("Created element  [" + field.getName() + "]");
  }
예제 #5
0
 @Override
 public void setCurrentResource(final Resource<?> resource) {
   lastResource = getCurrentResource();
   projectContext.setCurrentResource(resource);
   environment.setProperty("CWD", resource.getFullyQualifiedName());
 }