2020年web应用测试省赛功能测试答案

网友投稿 925 2022-08-28

2020年web应用测试省赛功能测试答案

2020年web应用测试省赛功能测试答案

2020年web应用测试省赛功能测试答案

​​# 答案​​

# 答案

我找不到试题,只找到答案。此答案由全国软件测试大赛官方提供。

import org.openqa.selenium.chrome.ChromeDriver;import org.openqa.selenium.interactions.Actions;import org.openqa.selenium.WebDriver;import org.openqa.selenium.WebElement;import java.util.Set;import org.openqa.selenium.By;public class Example { // Mooctest Selenium Example // Check if selenium-standalone.jar is added to build path. public static void test(WebDriver driver) throws InterruptedException { // TODO Test script // eg:driver.get(" // eg:driver.findElement(By.id("wd")); driver.get(" Thread.sleep(2000); driver.findElement(By.xpath("//*[@id=\"g_nav2\"]/div/ul/li[5]/a/em")).click(); Thread.sleep(2000); driver.switchTo().defaultContent(); driver.switchTo().frame("g_iframe"); driver.findElement(By.xpath("//*[@id=\"singer-cat-nav\"]/div[1]/ul/li[2]/a")).click(); Thread.sleep(2000); driver.findElement(By.xpath("//*[@id=\"initial-selector\"]/li[5]/a")).click(); //D Thread.sleep(2000); driver.findElement(By.xpath("//*[@id=\"m-artist-box\"]/li[1]/div/a")).click();//第1张图 Thread.sleep(5000); Actions builder=new Actions(driver); builder.moveToElement(driver.findElement(By.xpath("//*[@id=\"song-list-pre-cache\"]/div[1]/div[1]/table/tbody/tr[3]"))).perform(); Thread.sleep(2000); driver.findElement(By.xpath("//*[@id=\"song-list-pre-cache\"]/div[1]/div[1]/table/tbody/tr[3]/td[3]/div/a[1]")).click(); Thread.sleep(5000);// driver.findElement(By.xpath("//*[@id=\"song-list-pre-cache\"]/div[1]/div[1]/table/tbody/tr[1]/td[1]/div/span[1]")).click();// Thread.sleep(2000);//第一首歌// driver.findElement(By.xpath("//*[@id=\"song-list-pre-cache\"]/div[1]/div[1]/table/tbody/tr[1]/td[1]/div/span[1]")).click();// Thread.sleep(2000);//第一首歌// driver.switchTo().defaultContent(); driver.findElement(By.xpath("/html/body/div[2]/div[1]/div[1]/div[1]/a")).click(); Thread.sleep(2000); driver.findElement(By.xpath("//*[@id=\"g_player\"]/div[5]/a[2]")).click();//更改播放模式 Thread.sleep(2000); driver.findElement(By.xpath("//*[@id=\"g_player\"]/div[5]/span/a")).click(); Thread.sleep(2000); driver.findElement(By.xpath("//*[@id=\"g_playlist\"]/div[1]/div/a[1]")).click();//收藏全部 Thread.sleep(20000); //手动登录,什么方式都可以 driver.findElement(By.xpath("//*[@id=\"g_player\"]/div[4]/a[1]")).click(); Thread.sleep(2000); driver.switchTo().defaultContent(); driver.switchTo().frame("g_iframe"); driver.findElement(By.xpath("/html/body/div[9]/div[2]/div[1]/div[1]")).click(); Thread.sleep(2000); driver.findElement(By.xpath("/html/body/div[9]/div[2]/div[1]/p[1]/input[1]")).sendKeys("我喜欢的歌曲"); Thread.sleep(2000); driver.findElement(By.xpath("/html/body/div[9]/div[2]/div[1]/div[2]/a[1]")).click(); Thread.sleep(2000); driver.switchTo().defaultContent(); driver.switchTo().frame("g_iframe"); driver.findElement(By.xpath("//*[@id=\"m_tabs\"]/li[2]/a/em")).click(); Thread.sleep(2000); driver.findElement(By.xpath("//*[@id=\"m_tabs\"]/li[3]/a/em")).click(); Thread.sleep(2000); driver.findElement(By.xpath("//*[@id=\"m_tabs\"]/li[4]/a/em")).click(); Thread.sleep(2000); driver.switchTo().defaultContent(); driver.findElement(By.xpath("//*[@id=\"srch\"]")).sendKeys("李荣浩\n"); driver.switchTo().defaultContent(); driver.switchTo().frame("g_iframe"); driver.findElement(By.xpath("/html/body/div[3]/div/div[2]/ul[1]/li[3]")).click(); Thread.sleep(2000); driver.findElement(By.xpath("//a[contains(text(),'模特')]")).click(); Thread.sleep(2000); driver.findElement(By.xpath("//textarea[@placeholder='评论']")).sendKeys("非常好听"); Thread.sleep(3000); driver.findElement(By.xpath("//*[@id=\"comment-box\"]/div[1]/div[2]/div[1]/div[2]/div[1]/div[1]/div[2]/a[1]")).click(); Thread.sleep(10000); driver.switchTo().defaultContent(); driver.findElement(By.xpath("//*[@id=\"g-topbar\"]/div[1]/div/ul/li[4]/span/a/em")).click(); Set windows=driver.getWindowHandles(); String current_handle=driver.getWindowHandle(); String store_handle=""; for(String window:windows) { if(window.equals(current_handle)) { continue; } else { driver.switchTo().window(window); store_handle=new String(window); break; } } driver.findElement(By.xpath("//*[@id=\"m-search\"]/div/div[1]/form/input")).sendKeys("耳机\n"); Thread.sleep(5000); driver.findElement(By.xpath("//*[@id=\"search-list\"]/div[1]/div/div/ul/li[3]/a/em")).click(); Thread.sleep(2000); driver.findElement(By.xpath("//*[@id=\"search-list\"]/div[1]/ul/li[1]/div/a/img")).click(); Thread.sleep(2000); windows=driver.getWindowHandles(); String product_handle=""; for(String window:windows) { if(window.equals(current_handle)) { continue; } else if(window.equals(store_handle)) { continue; } else { driver.switchTo().window(window); product_handle=new String(window); break; } } driver.findElement(By.xpath("//*[@id=\"digital-counter-new\"]/div[1]/a[2]/i")).click(); Thread.sleep(2000); driver.findElement(By.xpath("//*[@id=\"digital-counter-new\"]/div[1]/span/input[1]")).sendKeys("5"); Thread.sleep(2000); driver.findElement(By.xpath("//*[@id=\"buyFlag\"]/a[2]")).click(); Thread.sleep(2000); driver.findElement(By.xpath("//*[@id=\"g_top\"]/div[1]/div[3]/a")).click(); Thread.sleep(2000); windows=driver.getWindowHandles(); String pay_handle=""; for(String window:windows) { if(window.equals(current_handle)) { continue; } else if(window.equals(store_handle)) { continue; } else if(window.equals(product_handle)) { continue; } else { driver.switchTo().window(window); pay_handle=new String(window); break; } } driver.findElement(By.xpath("//*[@id=\"bottom\"]/div/div[3]")).click(); Thread.sleep(2000); driver.findElement(By.xpath("//*[@id=\"module-root\"]/div[2]/div[2]/div[3]/div[1]/span")).click(); Thread.sleep(2000); //结束 } public static void main(String[] args) { // Run main function to test your script. WebDriver driver = new ChromeDriver(); try { test(driver); } catch(Exception e) { e.printStackTrace(); } finally { driver.quit(); } }}

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:1271Color
下一篇:Oracle数据库常用基本语句(oracle数据库常用sql)
相关文章

 发表评论

暂时没有评论,来抢沙发吧~