SampleTest.java 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. package org.jeecg;
  2. import cn.com.ctop.common.module.utils.HttpUtils2;
  3. import cn.com.ctop.crawler.modules.appium.service.IAppiumJobService;
  4. import cn.com.ctop.crawler.modules.appium.service.IAppiumTaskService;
  5. import cn.com.ctop.kuaishou.modules.batch.service.IAccountWarningService;
  6. import cn.com.ctop.kuaishou.modules.batch.service.IKuaishouInterfaceService;
  7. import lombok.extern.slf4j.Slf4j;
  8. import org.apache.http.impl.client.BasicCookieStore;
  9. import org.jeecg.modules.ctop.service.IBidWarningService;
  10. import org.jeecg.modules.ctop.service.ICreateInternalService;
  11. import org.jeecg.modules.mq.Sender;
  12. import org.junit.Test;
  13. import org.junit.runner.RunWith;
  14. import org.openqa.selenium.By;
  15. import org.openqa.selenium.JavascriptExecutor;
  16. import org.openqa.selenium.WebDriver;
  17. import org.openqa.selenium.WebElement;
  18. import org.openqa.selenium.chrome.ChromeDriver;
  19. import org.openqa.selenium.chrome.ChromeOptions;
  20. import org.springframework.beans.factory.annotation.Autowired;
  21. import org.springframework.beans.factory.annotation.Value;
  22. import org.springframework.boot.test.context.SpringBootTest;
  23. import org.springframework.test.context.junit4.SpringRunner;
  24. import java.util.List;
  25. @RunWith(SpringRunner.class)
  26. @SpringBootTest
  27. @Slf4j
  28. public class SampleTest {
  29. @Value("${jeecg.path.chrome-driver}")
  30. private String chromeDriver;
  31. @Autowired
  32. private IAppiumJobService jobService;
  33. @Autowired
  34. private ICreateInternalService createInternalService;
  35. @Autowired
  36. private IAppiumTaskService appiumTaskService;
  37. @Test
  38. public void testKs() throws InterruptedException {
  39. String url = "https://ad.e.kuaishou.com/#/welcome?redirectUrl=https%3A%2F%2Fad.e.kuaishou.com%2F%23%2Findex";
  40. System.getProperties().setProperty("webdriver.chrome.driver", chromeDriver);
  41. ChromeOptions chromeOptions = new ChromeOptions();
  42. // chromeOptions.addArguments("--headless");
  43. chromeOptions.addArguments("--incognito");
  44. chromeOptions.addArguments("--disable-gpu");
  45. // chromeOptions.addArguments("--no-sandbox");
  46. chromeOptions.addArguments("--window-size=1920,1080");
  47. chromeOptions.addArguments("--user-agent=" + HttpUtils2.USER_AGENT);
  48. chromeOptions.setAcceptInsecureCerts(true);
  49. WebDriver webDriver = new ChromeDriver(chromeOptions);
  50. try {
  51. Thread.sleep(3000L);
  52. HttpUtils2.cookieStore = new BasicCookieStore();
  53. webDriver.manage().deleteAllCookies();
  54. //获取登录页面
  55. webDriver.get(url);
  56. Thread.sleep(3000L);
  57. WebElement accountElement = webDriver.findElement(By.xpath("//div[@class='phone ']/input[@type='text']"));
  58. accountElement.sendKeys("19845004383");
  59. Thread.sleep(3000L);
  60. WebElement passwordElement = webDriver.findElement(By.xpath("//div[@class='password ']/input[@type='password']"));
  61. passwordElement.sendKeys("a123456");
  62. WebElement loginElement = webDriver.findElement(By.xpath("//div[@class='foot']"));
  63. Thread.sleep(3000L);
  64. //点击登录
  65. loginElement.click();
  66. Thread.sleep(3000L);
  67. //获取推广按钮
  68. WebElement spreadElement = webDriver.findElement(By.linkText("推广"));
  69. spreadElement.click();
  70. Thread.sleep(3000L);
  71. //选择广告创意
  72. WebElement creativeElement = webDriver.findElement(By.xpath("//div[text()='广告创意']"));
  73. creativeElement.click();
  74. Thread.sleep(3000L);
  75. //输入创意名称,点击搜索
  76. WebElement searchElement = webDriver.findElement(By.xpath("//input[@type='text']"));
  77. searchElement.sendKeys("2-这个是你画的吗-设计-11.19");
  78. Thread.sleep(3000L);
  79. WebElement searchButton = webDriver.findElement(By.xpath("//button[@class='ant-btn ant-input-search-button ant-btn-primary']"));
  80. searchButton.click();
  81. Thread.sleep(3000L);
  82. WebElement tiyanElement = webDriver.findElement(By.linkText("体验"));
  83. tiyanElement.click();
  84. Thread.sleep(2000L);
  85. WebElement inputKsIdElement = webDriver.findElement(By.xpath("//textarea[@placeholder='请输入快手账号…']"));
  86. inputKsIdElement.sendKeys("123456765");
  87. Thread.sleep(2000L);
  88. WebElement chufaElement = webDriver.findElement(By.xpath("//button[@class='creative-experience-btn-enable']"));
  89. chufaElement.click();
  90. } catch (Exception e) {
  91. e.printStackTrace();
  92. webDriver.manage().deleteAllCookies();
  93. webDriver.close();
  94. }
  95. }
  96. @Test
  97. public void test() {
  98. jobService.refreshWebPhone();
  99. }
  100. @Test
  101. public void testMq() {
  102. Sender sender = new Sender();
  103. sender.send();
  104. }
  105. @Test
  106. public void loadKuaishouDataSingle() throws Exception {
  107. String url = "https://a201903112120030590198943.szwego.com/static/index.html#/shop_detail/A201903112120030590198943";
  108. System.getProperties().setProperty("webdriver.chrome.driver", chromeDriver);
  109. ChromeOptions chromeOptions = new ChromeOptions();
  110. // chromeOptions.addArguments("--headless");
  111. chromeOptions.addArguments("--incognito");
  112. chromeOptions.addArguments("--disable-gpu");
  113. // chromeOptions.addArguments("--no-sandbox");
  114. chromeOptions.addArguments("--window-size=1920,1080");
  115. chromeOptions.addArguments("--user-agent=" + HttpUtils2.USER_AGENT);
  116. chromeOptions.setAcceptInsecureCerts(true);
  117. WebDriver webDriver = new ChromeDriver(chromeOptions);
  118. webDriver.get(url);
  119. Thread.sleep(3000L);
  120. ((JavascriptExecutor) webDriver).executeScript("window.scrollTo(0,document.body.scrollHeight)");
  121. Thread.sleep(3000L);
  122. List<WebElement> elementList = webDriver.findElements(By.xpath("//div[@class='word-break ellipsis-two f14 g3']"));
  123. for (WebElement element : elementList) {
  124. System.out.println(element.getText());
  125. }
  126. }
  127. @Autowired
  128. private IKuaishouInterfaceService kuaishouInterfaceService;
  129. @Test
  130. public void testMail() throws Exception {
  131. // String accessToken, Long advertiserId, Date startDate, Date endDate, Integer page
  132. kuaishouInterfaceService.getGroupList("adf659b9b43e8952f9a3f0c5269505ca", 35675L, null, null, 1);
  133. }
  134. @Autowired
  135. private IBidWarningService bidWarningService;
  136. @Autowired
  137. private IAccountWarningService accountWarningService;
  138. @Test
  139. public void testMa() throws Exception {
  140. // accountWarningService.accountWarning(23212L);
  141. }
  142. }