简体   繁体   English

如何使用Selenium Web驱动程序和groovy脚本在chrome中运行测试用例?

[英]How to run my test case in chrome using selenium web driver and groovy script?

Here is my code for Firefox. 这是我的Firefox代码。 How to customize it for Chrome and IE? 如何针对Chrome和IE对其进行自定义?

can any oneplease let me know.. I am using groovy and selenium web driver only. 任何人都可以让我知道吗。我仅使用groovy和Selenium Web驱动程序。 Since Soap UI supports groovy only, i am trying to do this in Groovy and Web drivers only.. 由于Soap UI仅支持groovy,所以我试图仅在Groovy和Web驱动程序中做到这一点。

import org.openqa.selenium.By
import org.openqa.selenium.WebDriver
import org.openqa.selenium.WebElement
import org.openqa.selenium.firefox.FirefoxDriver
import org.openqa.selenium.support.ui.ExpectedCondition
import org.openqa.selenium.support.ui.WebDriverWait

         // Create a new instance of the Firefox driver
         WebDriver driver = new FirefoxDriver()

        // Extract URL for stdcheckout
       def link = context.expand( 'url' )

        // And now use this to visit stdcheckout
        driver.get(link)
        //driver.get("https://xxx-ft25.test.xxxx.eu/xxxx/login?partnerCode=xxx&paymentToken=4bbf8ee5-f102-424f-8a6f-28a8e26e0292")

        // Find the text input element by its name
        WebElement element = driver.findElement(By.name("email"))

        // Enter username
        element.sendKeys("1204@yahoo.com")


        //  Find the password element by its name
        WebElement element1 = driver.findElement(By.name("password"))

        // Enter password
        element1.sendKeys("asdfghjkl")

       // Click the Login button    
        driver.findElement(By.name("sbutton")).click();

       // Enter CVV2
       driver.findElement(By.id("cvv")).sendKeys("672");

      //WebElement element2 = driver.findElement(By.name("termsAndConditionsAccepted"))
      //element2.click();

      //click Paynow
      driver.findElement(By.cssSelector("input[type=\"button\"]")).click();


       log.info("Page title is: " + driver.getTitle())

        // Google's search is rendered dynamically with JavaScript.
        // Wait for the page to load, timeout after 10 seconds
        /*(new WebDriverWait(driver, 10)).until(new ExpectedCondition() {
            public Boolean apply(WebDriver d) {
             return d.getTitle().toLowerCase().startsWith("cheese!")
           }
        });*/

        // Should see: "cheese! - Google Search"
        //log.info("Page title is: " + driver.getTitle())

        //Close the browser
        driver.quit()

Download chrome driver and put it in any location and give the path while set the property.... 下载chrome驱动程序并将其放在任何位置,并在设置属性时提供路径。

package korporation.test.SampleTestGroup

import java.util.concurrent.TimeUnit

import org.openqa.selenium.By
import org.openqa.selenium.WebDriver
import org.openqa.selenium.chrome.ChromeDriver


    // set up the driver
    System.setProperty("webdriver.chrome.driver", "c:/chromedriver/chromedriver.exe")

    //Define the driver
    def WebDriver driver = new ChromeDriver()
    driver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS)

     // And now use this to visit Google
    def link = context.expand( 'url'); 

     driver.get(link)

     def username = context.expand( '${#Project#username}' )

     // Find the text input element by its name
     driver.findElement(By.name("email")).sendKeys(username)



     //  Find the password element by its name
     driver.findElement(By.name("password")).sendKeys("asdfghjkl")

     // Click the Login button  
     driver.findElement(By.name("sbutton")).click();

    // Enter CVV2
    driver.findElement(By.id("cvv")).sendKeys("672");

    driver.findElement(By.name("termsAndConditionsAccepted")).click();

    driver.findElement(By.xpath("//*[@id=\"pay-now\"]")).click();


   //log.info("Page title is: " + driver.getTitle())

   assert (driver.getTitle()=="Mobile Phones | Contract Phones | Cheap Mobile Phone Deals & SIMs")
   //Close the browser
   driver.quit()

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在python中顺序运行多个Selenium Web驱动程序测试用例方法 - How to run multiple selenium web driver test case methods sequentially in python 如何在Ruby的Selenium Web驱动程序中获得测试用例名称? - how to get the test case name in selenium web driver in ruby? 如何使用 Selenium Chrome 驱动程序在 chrome 中打开多个 web 页面 - How to open multiple web pages in chrome using Selenium Chrome Driver 如何 24/7 全天候运行 selenium Web 驱动程序脚本 - How do I run a selenium web driver script 24/7 使用 selenium web 驱动程序运行测试 - NoClassDefFoundError - run test with selenium web driver - NoClassDefFoundError 如何在Ruby中使用Selenium Web驱动程序加载自定义Chrome扩展程序? - How to load custom chrome extension using selenium web driver in ruby? 如何使用Selenium Web驱动程序设置Google chrome偏好设置? - How to set Google chrome preference using Selenium web driver? 如何在Mac OSx的Ruby中使用Selenium在后台运行chrome驱动程序? - How to run chrome driver in background using selenium with Ruby for Mac OSx? 如何在 Z23EEEB4347BDD755BFC6B7EE9A 中使用 selenium firefox 和 chrome 驱动程序翻译 web 页面? - How to translate a web page using selenium firefox and chrome driver in python? 每次chrome更新最新版本时如何运行selenium脚本而不添加chrome web驱动程序属性 - How to run selenium scripts without adding chrome web driver properties every time chrome updates with latest versions
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM