Skip to content

Commit

Permalink
Added keyword ElementShouldContainType.
Browse files Browse the repository at this point in the history
  • Loading branch information
badong2210 committed Mar 5, 2013
1 parent 5301c33 commit 961b75b
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
@@ -0,0 +1,34 @@
/*
* Copyright (c) 2012. JSpringBot. All Rights Reserved.
*
* See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The JSpringBot licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.jspringbot.keyword.selenium;

import org.jspringbot.KeywordInfo;
import org.springframework.stereotype.Component;

@Component
@KeywordInfo(name = "Element Should Contain Type", description = "Verifies element identified by locator contains expected type.", parameters = {"locator", "type name"})
public class ElementShouldContainType extends AbstractSeleniumKeyword {

@Override
public Object execute(Object[] params) {
helper.elementShouldContainType(String.valueOf(params[0]),String.valueOf(params[1]));

return null;
}
}
Expand Up @@ -464,6 +464,27 @@ public void elementShouldContainClass(String locator, String expectedClassName)
throw new AssertionError("Element should have contained class.");
}

public void elementShouldContainType(String locator, String expectedTypeName) {
WebElement el = finder.find(locator, true);

String typeNames = el.getAttribute("type");

LOG.createAppender()
.appendBold("Element Should Contain Class:")
.appendCss(locator)
.appendProperty("Class Names", typeNames)
.appendProperty("Expected Type Name", expectedTypeName)
.log();

if(StringUtils.isNotEmpty(typeNames)) {
if(Arrays.asList(StringUtils.split(typeNames, " ")).contains(expectedTypeName)) {
return;
}
}

throw new AssertionError("Element should have contained type.");
}

public void elementShouldNotContainClass(String locator, String expectedClassName) {
WebElement el = finder.find(locator, true);

Expand Down

0 comments on commit 961b75b

Please sign in to comment.