How to use ElementEvent class of com.testsigma.event package

Best Testsigma code snippet using com.testsigma.event.ElementEvent

Source:ElementService.java Github

copy

Full Screen

...8 */9package com.testsigma.service;10import com.testsigma.dto.BackupDTO;11import com.testsigma.dto.export.ElementXMLDTO;12import com.testsigma.event.ElementEvent;13import com.testsigma.event.EventType;14import com.testsigma.exception.ResourceNotFoundException;15import com.testsigma.mapper.ElementMapper;16import com.testsigma.model.*;17import com.testsigma.repository.ElementRepository;18import com.testsigma.specification.ElementSpecificationsBuilder;19import com.testsigma.specification.SearchCriteria;20import com.testsigma.specification.SearchOperation;21import com.testsigma.specification.TestCaseSpecificationsBuilder;22import com.testsigma.web.request.ElementRequest;23import com.testsigma.web.request.ElementScreenNameRequest;24import lombok.RequiredArgsConstructor;25import lombok.extern.log4j.Log4j2;26import org.springframework.beans.factory.annotation.Autowired;27import org.springframework.context.ApplicationEventPublisher;28import org.springframework.dao.DataIntegrityViolationException;29import org.springframework.data.domain.Page;30import org.springframework.data.domain.PageRequest;31import org.springframework.data.domain.Pageable;32import org.springframework.data.jpa.domain.Specification;33import org.springframework.stereotype.Service;34import java.io.IOException;35import java.util.ArrayList;36import java.util.Arrays;37import java.util.List;38import java.util.Objects;39@Service("elementService")40@Log4j241@RequiredArgsConstructor(onConstructor = @__(@Autowired))42public class ElementService extends XMLExportService<Element> {43 private final ElementRepository elementRepository;44 private final TestCaseService testCaseService;45 private final TagService tagService;46 private final TestStepService testStepService;47 private final ElementMapper elementMapper;48 private final ElementScreenService screenNameService;49 private final ApplicationEventPublisher applicationEventPublisher;50 public List<Element> findByNameInAndWorkspaceVersionId(List<String> elementNames, Long workspaceVersionId) {51 return elementRepository.findByNameInAndWorkspaceVersionId(elementNames, workspaceVersionId);52 }53 public Element findByNameAndVersionId(String name, Long versionId) {54 return elementRepository.findFirstElementByNameAndWorkspaceVersionId(name,55 versionId);56 }57 public Element find(Long id) throws ResourceNotFoundException {58 return elementRepository.findById(id)59 .orElseThrow(() -> new ResourceNotFoundException("Element is not found with id: " + id));60 }61 public Page<Element> findAll(Specification<Element> specification, Pageable pageable) {62 return elementRepository.findAll(specification, pageable);63 }64 public Element save(Element element) {65 return elementRepository.save(element);66 }67 public Element create(Element element) {68 element = this.save(element);69 this.markAsDuplicated(element);70 publishEvent(element, EventType.CREATE);71 return element;72 }73 public Element update(Element element, String oldName, String previousLocatorValue, LocatorType previousLocatorType, Long previousScreenNameId)74 throws ResourceNotFoundException {75 element = this.save(element);76 if (!Objects.equals(element.getLocatorValue(), previousLocatorValue) || element.getLocatorType() != previousLocatorType77 || !Objects.equals(element.getScreenNameId(), previousScreenNameId)) {78 this.markAsDuplicated(element);79 this.resetDuplicate(element.getWorkspaceVersionId(), previousLocatorValue, previousLocatorType, previousScreenNameId);80 }81 this.eventCallForUpdate(oldName, element);82 return element;83 }84 public Element update(Element element, String oldName) {85 element = this.save(element);86 this.eventCallForUpdate(oldName, element);87 return element;88 }89 public void delete(Element element) {90 elementRepository.delete(element);91 this.resetDuplicate(element.getWorkspaceVersionId(), element.getLocatorValue(), element.getLocatorType(), element.getScreenNameId());92 publishEvent(element, EventType.DELETE);93 }94 public void bulkDelete(Long[] ids, Long workspaceVersionId) throws Exception {95 Boolean allIdsDeleted = true;96 TestCaseSpecificationsBuilder builder = new TestCaseSpecificationsBuilder();97 for (Long id : ids) {98 List<SearchCriteria> params = new ArrayList<>();99 Element element = this.find(id);100 params.add(new SearchCriteria("element", SearchOperation.EQUALITY, element.getName()));101 params.add(new SearchCriteria("workspaceVersionId", SearchOperation.EQUALITY, workspaceVersionId));102 builder.setParams(params);103 Specification<TestCase> spec = builder.build();104 Page<TestCase> linkedTestCases = testCaseService.findAll(spec, PageRequest.of(0, 1));105 if (linkedTestCases.getTotalElements() == 0) {106 this.delete(element);107 } else {108 allIdsDeleted = false;109 }110 }111 if (!allIdsDeleted) {112 throw new DataIntegrityViolationException("dataIntegrityViolationException: Failed to delete some of the Elements " +113 "since they are already associated to some Test Cases.");114 }115 }116 public void bulkUpdateScreenNameAndTags(Long[] ids, String screenName, String[] tags) throws ResourceNotFoundException {117 for (Long id : ids) {118 Element element = find(id);119 if (screenName.length() > 0) {120 ElementScreenNameRequest elementScreenNameRequest = new ElementScreenNameRequest();121 elementScreenNameRequest.setName(screenName);122 elementScreenNameRequest.setWorkspaceVersionId(element.getWorkspaceVersionId());123 ElementScreenName elementScreenName = screenNameService.save(elementScreenNameRequest);124 element.setScreenNameId(elementScreenName.getId());125 }126 update(element, element.getName(), element.getLocatorValue(), element.getLocatorType(), element.getScreenNameId());127 tagService.updateTags(Arrays.asList(tags), TagType.ELEMENT, id);128 }129 }130 public void updateByName(String name, ElementRequest elementRequest) {131 Element element = findByNameAndVersionId(name, elementRequest.getWorkspaceVersionId());132 String oldName = element.getName();133 elementMapper.merge(elementRequest, element);134 update(element, oldName);135 }136 public void publishEvent(Element element, EventType eventType) {137 ElementEvent<Element> event = createEvent(element, eventType);138 log.info("Publishing event - " + event.toString());139 applicationEventPublisher.publishEvent(event);140 }141 public ElementEvent<Element> createEvent(Element element, EventType eventType) {142 ElementEvent<Element> event = new ElementEvent<>();143 event.setEventData(element);144 event.setEventType(eventType);145 return event;146 }147 public void export(BackupDTO backupDTO) throws IOException, ResourceNotFoundException {148 if (!backupDTO.getIsElementEnabled()) return;149 log.debug("backup process for element initiated");150 writeXML("elements", backupDTO, PageRequest.of(0, 25));151 log.debug("backup process for element completed");152 }153 public Specification<Element> getExportXmlSpecification(BackupDTO backupDTO) {154 SearchCriteria criteria = new SearchCriteria("workspaceVersionId", SearchOperation.EQUALITY, backupDTO.getWorkspaceVersionId());155 List<SearchCriteria> params = new ArrayList<>();156 params.add(criteria);...

Full Screen

Full Screen

Source:ElementEventListener.java Github

copy

Full Screen

1package com.testsigma.os.stats.listener;2import com.testsigma.event.ElementEvent;3import com.testsigma.event.EventType;4import com.testsigma.exception.TestsigmaException;5import com.testsigma.model.Element;6import com.testsigma.os.stats.service.TestsigmaOsStatsService;7import lombok.RequiredArgsConstructor;8import lombok.extern.log4j.Log4j2;9import org.springframework.beans.factory.annotation.Autowired;10import org.springframework.context.event.EventListener;11import org.springframework.stereotype.Component;12@Log4j213@Component14@RequiredArgsConstructor(onConstructor = @__(@Autowired))15public class ElementEventListener {16 private final TestsigmaOsStatsService testsigmaOsStatsService;17 @EventListener(classes = ElementEvent.class)18 public void OnElementEvent(ElementEvent<Element> event) {19 log.info("Caught ElementEvent - " + event);20 try {21 if (event.getEventType() == EventType.CREATE) {22 testsigmaOsStatsService.sendElementStats(event.getEventData(), com.testsigma.os.stats.event.EventType.CREATE);23 } else if (event.getEventType() == EventType.DELETE) {24 testsigmaOsStatsService.sendElementStats(event.getEventData(), com.testsigma.os.stats.event.EventType.DELETE);25 }26 } catch (TestsigmaException e) {27 log.error(e.getMessage(), e);28 }29 }30}...

Full Screen

Full Screen

ElementEvent

Using AI Code Generation

copy

Full Screen

1import com.testsigma.event.ElementEvent;2import org.openqa.selenium.WebDriver;3import org.openqa.selenium.WebElement;4import org.openqa.selenium.chrome.ChromeDriver;5import org.openqa.selenium.By;6import org.openqa.selenium.support.ui.ExpectedConditions;7import org.openqa.selenium.support.ui.WebDriverWait;8import org.openqa.selenium.support.ui.Select;9import org.openqa.selenium.JavascriptExecutor;10import org.openqa.selenium.Keys;11import org.openqa.selenium.interactions.Actions;12import org.openqa.selenium.support.ui.FluentWait;13import org.openqa.selenium.support.ui.Wait;14import java.util.concurrent.TimeUnit;15import java.util.function.Function;16import org.openqa.selenium.support.ui.ExpectedConditions;17import org.openqa.selenium.support.ui.WebDriverWait;18import org.openqa.selenium.support.ui.Select;19import org.openqa.selenium.JavascriptExecutor;20import org.openqa.selenium.Keys;21import org.openqa.selenium.interactions.Actions;22import org.openqa.selenium.support.ui.FluentWait;23import org.openqa.selenium.support.ui.Wait;24import java.util.concurrent.TimeUnit;25import java.util.function.Function;26import org.openqa.selenium.support.ui.ExpectedConditions;27import org.openqa.selenium.support.ui.WebDriverWait;28import org.openqa.selenium.support.ui.Select;29import org.openqa.selenium.JavascriptExecutor;30import org.openqa.selenium.Keys;31import org.openqa.selenium.interactions.Actions;32import org.openqa.selenium.support.ui.FluentWait;33import org.openqa.selenium.support.ui.Wait;34import java.util.concurrent.TimeUnit;35import java.util.function.Function;36import org.openqa.selenium.support.ui.ExpectedConditions;37import org.openqa.selenium.support.ui.WebDriverWait;38import org.openqa.selenium.support.ui.Select;39import org.openqa.selenium.JavascriptExecutor;40import org.openqa.selenium.Keys;41import org.openqa.selenium.interactions.Actions;42import org.openqa.selenium.support.ui.FluentWait;43import org.openqa.selenium.support.ui.Wait;44import java.util.concurrent.TimeUnit;45import java.util.function.Function;46import org.openqa.selenium.support.ui.ExpectedConditions;47import org.openqa.selenium.support.ui.WebDriverWait;48import org.openqa.selenium.support.ui.Select;49import org.openqa.selenium.JavascriptExecutor;50import org.openqa.selenium.Keys;51import org.openqa.selenium.interactions.Actions;52import org.openqa.selenium.support.ui.FluentWait;53import org.openqa.selenium.support.ui.Wait;54import java.util.concurrent.TimeUnit;55import java.util.function.Function;56import org.openqa.selenium.support.ui.ExpectedConditions;57import org.openqa.selenium.support.ui.WebDriverWait;58import org.openqa.selenium.support.ui.Select;59import org.openqa.selenium.JavascriptExecutor;60import org.openqa.selenium.Keys;61import org.openqa.selenium.interactions.Actions;62import org.openqa.selenium.support.ui.FluentWait;63import org.openqa.selenium.support.ui.Wait;64import java

Full Screen

Full Screen

ElementEvent

Using AI Code Generation

copy

Full Screen

1import com.testsigma.event.ElementEvent;2import org.openqa.selenium.By;3import org.openqa.selenium.WebDriver;4import org.openqa.selenium.chrome.ChromeDriver;5import org.openqa.selenium.WebElement;6import org.openqa.selenium.interactions.Actions;7import org.openqa.selenium.support.ui.ExpectedConditions;8import org.openqa.selenium.support.ui.WebDriverWait;9public class TestElementEvent {10 public static void main(String[] args) {11 System.setProperty("webdriver.chrome.driver", "C:\\Users\\Downloads\\chromedriver.exe");12 WebDriver driver = new ChromeDriver();13 driver.manage().window().maximize();14 ElementEvent elementEvent = new ElementEvent(driver, element);15 elementEvent.sendText("test");16 elementEvent.click();17 elementEvent.waitUntilVisible(5);18 elementEvent.waitUntilClickable(5);19 driver.quit();20 }21}22import com.testsigma.event.ElementEvent;23import org.openqa.selenium.By;24import org.openqa.selenium.WebDriver;25import org.openqa.selenium.chrome.ChromeDriver;26import org.openqa.selenium.WebElement;27import org.openqa.selenium.interactions.Actions;28import org.openqa.selenium.support.ui.ExpectedConditions;29import org.openqa.selenium.support.ui.WebDriverWait;30public class TestElementEvent {31 public static void main(String[] args) {32 System.setProperty("webdriver.chrome.driver", "C:\\Users\\Downloads\\chromedriver.exe");33 WebDriver driver = new ChromeDriver();34 driver.manage().window().maximize();35 ElementEvent elementEvent = new ElementEvent(driver, element);36 elementEvent.sendText("test");37 elementEvent.click();38 elementEvent.waitUntilVisible(5);39 elementEvent.waitUntilClickable(5);40 driver.quit();41 }42}43import com.testsigma.event.ElementEvent;44import org.openqa.selenium.By;45import org.openqa.selenium.WebDriver;46import org.openqa.selenium.chrome.ChromeDriver;47import org.openqa.selenium.WebElement;48import org.openqa.selenium.interactions.Actions;

Full Screen

Full Screen

ElementEvent

Using AI Code Generation

copy

Full Screen

1import com.testsigma.event.ElementEvent;2import com.testsigma.event.Event;3import com.testsigma.event.EventListener;4import com.testsigma.event.EventManager;5import org.openqa.selenium.By;6import org.openqa.selenium.WebDriver;7import org.openqa.selenium.WebElement;8import org.openqa.selenium.chrome.ChromeDriver;9import java.util.concurrent.TimeUnit;10public class ElementEventExample {11 public static void main(String[] args) {12 System.setProperty("webdriver.chrome.driver", "C:\\Users\\user\\Downloads\\chromedriver_win32\\chromedriver.exe");13 WebDriver driver = new ChromeDriver();14 driver.manage().window().maximize();15 driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);16 EventManager eventManager = new EventManager();17 eventManager.addEventListener(new EventListener() {18 public void handleEvent(Event event) {19 if (event instanceof ElementEvent) {20 ElementEvent elementEvent = (ElementEvent) event;21 WebElement element = elementEvent.getElement();22 System.out.println("Element found: " + element.getTagName());23 }24 }25 });26 WebElement element = driver.findElement(By.name("q"));27 eventManager.fireEvent(new ElementEvent(element));28 driver.close();29 }30}31import com.testsigma.event.Event;32import com.testsigma.event.EventListener;33import com.testsigma.event.EventManager;34import org.openqa.selenium.By;35import org.openqa.selenium.WebDriver;36import org.openqa.selenium.WebElement;37import org.openqa.selenium.chrome.ChromeDriver;38import java.util.concurrent.TimeUnit;39public class EventManagerExample {40 public static void main(String[] args) {41 System.setProperty("webdriver.chrome.driver", "C:\\Users\\user\\Downloads\\chromedriver_win32\\chromedriver.exe");42 WebDriver driver = new ChromeDriver();43 driver.manage().window().maximize();44 driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);45 EventManager eventManager = new EventManager();46 eventManager.addEventListener(new EventListener() {47 public void handleEvent(Event event) {48 System.out.println("Event received: " + event.getClass().getSimpleName());49 }50 });51 WebElement element = driver.findElement(By.name("q"));52 eventManager.fireEvent(new Event() {53 });

Full Screen

Full Screen

ElementEvent

Using AI Code Generation

copy

Full Screen

1import com.testsigma.event.ElementEvent;2import com.testsigma.event.Event;3import com.testsigma.event.EventManager;4import com.testsigma.event.EventManagerImpl;5import com.testsigma.event.EventPublisher;6public class ElementEventTest {7 public static void main(String[] args) {8 EventPublisher publisher = new EventPublisher();9 publisher.register(new EventManagerImpl());10 publisher.publish(new ElementEvent("ElementEventTest", "element", Event.EventType.CLICK));11 }12}13import com.testsigma.event.ElementEvent;14import com.testsigma.event.Event;15import com.testsigma.event.EventManager;16import com.testsigma.event.EventManagerImpl;17import com.testsigma.event.EventPublisher;18public class ElementEventTest {19 public static void main(String[] args) {20 EventPublisher publisher = new EventPublisher();21 publisher.register(new EventManagerImpl());22 publisher.publish(new ElementEvent("ElementEventTest", "element", Event.EventType.CLICK));23 }24}25import com.testsigma.event.ElementEvent;26import com.testsigma.event.Event;27import com.testsigma.event.EventManager;28import com.testsigma.event.EventManagerImpl;29import com.testsigma.event.EventPublisher;30public class ElementEventTest {31 public static void main(String[] args) {32 EventPublisher publisher = new EventPublisher();33 publisher.register(new EventManagerImpl());34 publisher.publish(new ElementEvent("ElementEventTest", "element", Event.EventType.CLICK));35 }36}37import com.testsigma.event.ElementEvent;38import com.testsigma.event.Event;39import com.testsigma.event.EventManager;40import com.testsigma.event.EventManagerImpl;41import com.testsigma.event.EventPublisher;42public class ElementEventTest {43 public static void main(String[] args) {44 EventPublisher publisher = new EventPublisher();45 publisher.register(new EventManagerImpl());46 publisher.publish(new ElementEvent("ElementEventTest", "element", Event.EventType.CLICK));47 }48}49import com.testsigma.event.ElementEvent;50import com.testsigma.event.Event;51import com.testsigma.event.EventManager;52import com.testsigma.event.EventManagerImpl;53import com

Full Screen

Full Screen

ElementEvent

Using AI Code Generation

copy

Full Screen

1import com.testsigma.event.*;2import com.testsigma.event.Event;3import com.testsigma.event.ElementEvent;4import com.testsigma.event.EventFactory;5import com.testsigma.event.EventFactory;6public class ElementEventTest {7 public static void main(String[] args) {8 EventFactory eventFactory = new EventFactory();9 Event event = eventFactory.getEvent("ElementEvent");10 ElementEvent elementEvent = (ElementEvent) event;11 elementEvent.setElementName("username");12 elementEvent.setElementId("username");13 elementEvent.setElementType("text");14 elementEvent.setElementValue("admin");15 elementEvent.setElementTag("input");16 elementEvent.setElementClass("form-control");17 elementEvent.setElementScreenShot("screenshot.png");18 elementEvent.setElementCss("color:red");19 elementEvent.setElementTitle("title");20 elementEvent.setElementAlt("alt");21 elementEvent.setElementRole("role");22 elementEvent.setElementInnerHtml("inner html");23 elementEvent.setElementOuterHtml("outer html");24 elementEvent.setElementText("text");25 elementEvent.setElementHref("href");26 elementEvent.setElementSrc("src");27 elementEvent.setElementAction("action");28 elementEvent.setElementMethod("method");29 elementEvent.setElementName("name");30 elementEvent.setElementId("id");31 elementEvent.setElementType("type");32 elementEvent.setElementValue("value");33 elementEvent.setElementXpath("xpath");34 elementEvent.setElementTag("tag");35 elementEvent.setElementClass("class");36 elementEvent.setElementScreenShot("screenshot.png");37 elementEvent.setElementCss("css");38 elementEvent.setElementTitle("title");39 elementEvent.setElementAlt("alt");40 elementEvent.setElementRole("role");41 elementEvent.setElementInnerHtml("inner html");42 elementEvent.setElementOuterHtml("outer html");43 elementEvent.setElementText("text");44 elementEvent.setElementHref("href");45 elementEvent.setElementSrc("src");46 elementEvent.setElementAction("action");47 elementEvent.setElementMethod("method");48 elementEvent.setElementName("name");49 elementEvent.setElementId("id");50 elementEvent.setElementType("type");51 elementEvent.setElementValue("value");52 elementEvent.setElementXpath("xpath");

Full Screen

Full Screen

ElementEvent

Using AI Code Generation

copy

Full Screen

1import com.testsigma.event.ElementEvent;2import com.testsigma.event.Event;3import com.testsigma.event.EventManager;4import com.testsigma.event.EventManagerFactory;5import com.testsigma.event.EventSubscriber;6import com.testsigma.event.EventType;7import com.testsigma.event.EventManagerFactory.EventManagerType;8import com.testsigma.event.EventManagerFactory.SubscriptionType;9import com.testsigma.event.EventPublisher;10import com.testsigma.event.EventSubscriber;11import com.testsigma.event.EventType;12import com.testsigma.event.EventManagerFactory;13import com.testsigma.event.EventManagerFactory.EventManagerType;14import com.testsigma.event.EventManagerFactory.SubscriptionType;15public class 2 {16 public static void main(String[] args) {17 EventManager eventManager = EventManagerFactory.getEventManager(EventManagerType.SINGLE_THREAD);18 EventPublisher eventPublisher = eventManager.getEventPublisher();19 EventSubscriber eventSubscriber = eventManager.getEventSubscriber();20 eventSubscriber.subscribeToEvent(ElementEvent.class, new EventSubscriber() {21 public void onEvent(Event event) {22 ElementEvent elementEvent = (ElementEvent) event;23 System.out.println("Element ID: " + elementEvent.getElementId());24 System.out.println("Element Name: " + elementEvent.getElementName());25 System.out.println("Element Type: " + elementEvent.getElementType());26 System.out.println("Element Value: " + elementEvent.getElementValue());27 System.out.println("Event Type: " + elementEvent.getEventType());28 }29 }, SubscriptionType.ONCE);30 eventPublisher.publishEvent(new ElementEvent("elementId", "elementName", "elementType", "elementValue", EventType.CLICK));31 }32}33import com.testsigma.event.EventManager;34import com.testsigma.event.EventManagerFactory;35import com.testsigma.event.EventManagerFactory.EventManagerType;36public class 3 {37 public static void main(String[] args) {38 EventManager eventManager = EventManagerFactory.getEventManager(EventManagerType.SINGLE_THREAD);39 }40}41import com.testsigma.event.EventManager;42import com.testsigma.event.EventManagerFactory;43import com.testsigma.event.EventManagerFactory.EventManagerType

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Testsigma automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Most used methods in ElementEvent

Test Your Web Or Mobile Apps On 3000+ Browsers

Signup for free

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful