Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用Java和TestNG在不同的操作系统和浏览器上使用WebDriver并发执行测试_Java_Selenium_Selenium Grid - Fatal编程技术网

使用Java和TestNG在不同的操作系统和浏览器上使用WebDriver并发执行测试

使用Java和TestNG在不同的操作系统和浏览器上使用WebDriver并发执行测试,java,selenium,selenium-grid,Java,Selenium,Selenium Grid,我已经在我的系统中配置了网格并编写了测试脚本。我可以在任何指定的操作系统和任何浏览器上运行测试,但一次只能在一个操作系统和一个浏览器上运行,而不是同时在所有操作系统和所有浏览器上运行测试。这就是我所做的。请告诉我如何配置它,以便它可以在一次配置的操作系统中运行 我使用Java编写的脚本如下: import java.net.MalformedURLException; import java.net.URL; import org.junit.AfterClass; import org.ope

我已经在我的系统中配置了网格并编写了测试脚本。我可以在任何指定的操作系统和任何浏览器上运行测试,但一次只能在一个操作系统和一个浏览器上运行,而不是同时在所有操作系统和所有浏览器上运行测试。这就是我所做的。请告诉我如何配置它,以便它可以在一次配置的操作系统中运行

我使用Java编写的脚本如下:

import java.net.MalformedURLException;
import java.net.URL;
import org.junit.AfterClass;
import org.openqa.selenium.*;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.testng.annotations.*;

public class GridWithWebdriver {

    public WebDriver driver;

    @Parameters({"browser"})
    @BeforeClass
    public void setup(String browser) throws MalformedURLException {
        DesiredCapabilities capability=null;

        if(browser.equalsIgnoreCase("firefox")){
            System.out.println("firefox");
            capability= DesiredCapabilities.firefox();
            capability.setBrowserName("firefox"); 
            capability.setPlatform(org.openqa.selenium.Platform.ANY);
            //capability.setVersion("");
        }

        if(browser.equalsIgnoreCase("iexplore")){
            System.out.println("iexplore");
            capability= DesiredCapabilities.internetExplorer();
            capability.setBrowserName("iexplore"); 
            capability.setPlatform(org.openqa.selenium.Platform.WINDOWS);
            //capability.setVersion("");
        }

        driver = new RemoteWebDriver(<span class="IL_AD" id="IL_AD11">new URL</span>("http://localhost:4444/wd/hub"), capability);
        driver.navigate().to("http://google.com");

    }

    @Test
    public void test_first() throws InterruptedException{
        Thread.sleep(3000);
        WebElement search_editbox   =   driver.findElement(By.name("q"));
        WebElement search_button    =   driver.findElement(By.name("btnG"));
        search_editbox.clear();
        search_editbox.sendKeys("first");
        search_button.click();
    }

    @Test
    public void test_second(){
        WebElement search_editbox   =   driver.findElement(By.name("q"));
        WebElement search_button    =   driver.findElement(By.name("btnG"));
        search_editbox.clear();
        search_editbox.sendKeys("second");
        search_button.click();
    }

    @AfterClass
    public void tearDown(){
        driver.quit();
    }
}
import java.net.MalformedURLException;
导入java.net.URL;
导入org.junit.AfterClass;
导入org.openqa.selenium.*;
导入org.openqa.selenium.remote.DesiredCapabilities;
导入org.openqa.selenium.remote.RemoteWebDriver;
导入org.testng.annotations.*;
公共类GridWithWebdriver{
公共网络驱动程序;
@参数({“浏览器”})
@课前
public void安装程序(字符串浏览器)引发错误的DurLexException{
DesiredCapabilities=null;
if(browser.equalsIgnoreCase(“firefox”)){
System.out.println(“firefox”);
capability=DesiredCapabilities.firefox();
setBrowserName(“firefox”);
setPlatform(org.openqa.selenium.Platform.ANY);
//capability.setVersion(“”);
}
if(browser.equalsIgnoreCase(“iexplore”)){
System.out.println(“iexplore”);
capability=DesiredCapabilities.internetExplorer();
能力。setBrowserName(“iexplore”);
setPlatform(org.openqa.selenium.Platform.WINDOWS);
//capability.setVersion(“”);
}
驱动程序=新的RemoteWebDriver(新URL(“http://localhost:4444/wd/hub(能力),;
驱动程序。导航()。到(“http://google.com");
}
@试验
public void test_first()抛出InterruptedException{
睡眠(3000);
WebElement search_editbox=driver.findElement(By.name(“q”));
WebElement search_button=driver.findElement(By.name(“btnG”));
搜索_editbox.clear();
search_editbox.sendKeys(“第一”);
搜索按钮。单击();
}
@试验
第二次公开无效测试(){
WebElement search_editbox=driver.findElement(By.name(“q”));
WebElement search_button=driver.findElement(By.name(“btnG”));
搜索_editbox.clear();
search_editbox.sendKeys(“第二个”);
搜索按钮。单击();
}
@下课
公共无效拆卸(){
driver.quit();
}
}
Testng.xml:

<suite name="Selenium <span class="IL_AD" id="IL_AD7">Grid with</span> webdriver" verbose="3"  parallel="classes" thread-count="2">   
  <test name="Selenium Grid Demo">
  <parameter name="browser" value="iexplore"/>
    <classes>
      <class name="tests.GridWithWebdriver"/>
      <class name="tests.GridWithWebdriver1"/>
    </classes>
 </test>
 </suite>

测试仪方法:

  • 使您的测试能够作为独立的
    .jar
    文件运行。这意味着测试实际上不是
    @test
    ,而是
    main
    方法中的某个方法或代码段
  • 专业提示:如果可以,请针对同一中心运行节点。如果计算机位于同一网络中,并且您可以访问这些计算机,则可以执行此操作
  • 如果可以这样做,您只需运行
    .jar
    文件两次,告诉它huib在哪里,节点就会自动分配
  • 如果无法做到这一点,您必须在每台计算机(节点)上部署这些
    .jar
    文件并运行它们(大多数情况下需要两个人)
例如:

我自己的电脑在本地网络中有IP
10.131.7.11
。因此,我将运行hub,每个节点只需执行以下操作:

java -jar selenium-server-standalone-2.32.0.jar -role webdriver -hub http://10.131.7.11:4444/grid/register -port 7575 -browser browserName=firefox,version=18,platform=WINDOWS
一旦节点运行,我将运行测试两次。然后,中心将自动为具体节点分配浏览器

开发人员方法:

  • 您可以使用多线程并在两个线程中运行测试一次

但是因为我是测试人员,所以我使用了第一种方法:)并且我确实与帮助我创建防白痴的多线程测试套件的开发人员进行了交流(在我自己身上测试:)

好吧,创建另一个
标记,并将另一个浏览器作为第二个测试的参数传递。您可能希望更改并行测试或继续使用类。另外,如果您想要拥有不同的OSs,那么您也需要有平台参数,以便从xml发送。

Aditya

在不同或相同系统上运行并行测试的代码(testng.xml)应如下所示:

Testng.xml

 <!DOCTYPE suite SYSTEM "Http://testng.org/testng-1.0.dtd">
    <suite name="My Sample Suite" verbose="3"  parallel="tests" thread-count="2">   


      <test name="Run on Firefox">
        <parameter name="mybrowser"  value="firefox"/>
        <parameter name="myip"  value="http://172.16.10.119:5566/wd/hub"/>
        <classes>
          <class name="testcases.Login"/>
        </classes>
     </test>  
    <test name="Run on Chrome">
        <parameter name="mybrowser"  value="chrome"/>
        <parameter name="myip"  value="http://172.16.10.106:5567/wd/hub"/>
        <classes>
          <class name="testcases.Login"/>
        </classes>
     </test> 
     </suite>

here i am trying to acess one linux(ttp://172.16.10.119:5566) and one mac(http://172.16.10.106:5567) and sending its ip and browser as a parameter. To run it parallel i have mentioned in my <testsuite> tag as parallel="tests" thread-count="2"

在这里,我试图访问一个linux(ttp://172.16.10.119:5566)还有一个苹果(http://172.16.10.106:5567)并将其ip和浏览器作为参数发送。为了并行运行,我在标签中提到了parallel=“tests”thread count=“2”
我希望你现在已经很清楚了。

package concore;
package concore;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.net.InetAddress;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.List;

import net.sourceforge.htmlunit.corejs.javascript.ast.WithStatement;

import org.apache.commons.io.FileUtils;
import org.openqa.selenium.By;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.net.INetAddress;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.openqa.selenium.support.ui.Select;

public class ConcurrentTestSMS {
    public WebDriver dri = null;
    private File file;
    private FileOutputStream fos;
    String error = "http://ip/sspjuly08/Errorpage.aspx";
    public long timeBefore;
    public long timeAfter;
    public long cal;
    public int drive;

    public ConcurrentTestSMS() {
        // Initializing file object
        file = new File("D:\\concorentTestingsmsLog.xls");

        try {
            // Creating new file if it doesn't exist
            if (!file.exists()) {
                file.createNewFile();
            }
            // Initializing file writer object
            fos = new FileOutputStream(file);
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public static String captureScreenshot(RemoteWebDriver drivers,
            String folder, String fileName) {
        File screenshotFile = ((TakesScreenshot) drivers)
                .getScreenshotAs(OutputType.FILE);
        File targetFile = new File(folder, fileName + ".png");
        // File targetFile=new File("D:\\alagar.png");
        try {
            FileUtils.copyFile(screenshotFile, targetFile);
        } catch (IOException e) {
            // logger.error ("Error while writing file ",e);
        }

        return targetFile.getAbsolutePath();
    }

    // method to write the error file
    protected void writeToFile(String logMsg) {
        try {
            fos.write(logMsg.getBytes());
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    int num = 100903;
    int loaddata = 01;

    private WebDriver getDriver(String url, DesiredCapabilities caps) {
        WebDriver webDriver = null;
        try {
            webDriver = new RemoteWebDriver(new URL(url), caps);
        } catch (MalformedURLException e) {
            e.printStackTrace();
        }
        return webDriver;
    }

    public void setup(String platform, String browser, String version,
            String url) throws MalformedURLException, InterruptedException, UnknownHostException {
        DesiredCapabilities caps = new DesiredCapabilities();
        // Platforms
        if (platform.equalsIgnoreCase("WINDOWS"))
            caps.setPlatform(org.openqa.selenium.Platform.WINDOWS);
        System.out.println(org.openqa.selenium.Platform.WINDOWS);
        // Browsers
        if (browser.equalsIgnoreCase("Internet Explorer"))
            caps = DesiredCapabilities.internetExplorer();
        if (browser.equalsIgnoreCase("Firefox"))
            caps = DesiredCapabilities.firefox();
        if (browser.equalsIgnoreCase("iPad"))
            caps = DesiredCapabilities.ipad();
        if (browser.equalsIgnoreCase("Android")) {
            caps = DesiredCapabilities.android();
        }
        writeToFile("Client\tEvent Page\tTaken Time\n");
        // Version
        caps.setVersion("18.0.1");
        String[] urls = { "http://ipip:8989/wd/hub",
                "http://ip:8989/wd/hub" };
        System.out.println(InetAddress.getLocalHost().getHostAddress());

        // Remote systemS
         timeBefore = System.currentTimeMillis();
        WebDriver driver1 = getDriver("http://172.21.1.89:8989/wd/hub", caps);
         timeAfter = System.currentTimeMillis();
         cal = timeAfter - timeBefore;
         currectpage(driver1, "driver1 in http://172.21.1.89","connecting client system", cal);
         timeBefore = System.currentTimeMillis();
        WebDriver driver2 = getDriver("http://172.21.1.4:8989/wd/hub", caps);
        System.out.println(InetAddress.getLocalHost().getHostAddress());
        timeAfter = System.currentTimeMillis();
         cal = timeAfter - timeBefore;
         currectpage(driver2, "driver2 in http://172.21.1.4","connecting client system", cal);
         timeBefore = System.currentTimeMillis();
        WebDriver driver3 = getDriver("http://172.21.1.89:8989/wd/hub", caps);
        timeAfter = System.currentTimeMillis();
         cal = timeAfter - timeBefore;
         currectpage(driver3, "driver3 in http://172.21.1.89","connecting client system", cal);
         timeBefore = System.currentTimeMillis();
        WebDriver driver4 = getDriver("http://172.21.1.4:8989/wd/hub", caps);
        timeAfter = System.currentTimeMillis();
         cal = timeAfter - timeBefore;
         currectpage(driver4, "driver4 in http://172.21.1.4","connecting client system", cal);
         timeBefore = System.currentTimeMillis();
        WebDriver driver5 = getDriver("http://172.21.1.89:8989/wd/hub", caps);
        timeAfter = System.currentTimeMillis();
         cal = timeAfter - timeBefore;
         currectpage(driver5, "driver5 in http://172.21.1.89","connecting client system", cal);
         timeBefore = System.currentTimeMillis();
        WebDriver driver6 = getDriver("http://172.21.1.4:8989/wd/hub", caps);
        timeAfter = System.currentTimeMillis();
         cal = timeAfter - timeBefore;
         currectpage(driver6, "driver6 in http://172.21.1.4","connecting client system", cal);
         timeBefore = System.currentTimeMillis();
        WebDriver driver7 = getDriver("http://172.21.1.89:8989/wd/hub", caps);
        timeAfter = System.currentTimeMillis();
         cal = timeAfter - timeBefore;
         currectpage(driver7, "driver7 in http://172.21.1.89","connecting client system", cal);
         timeBefore = System.currentTimeMillis();
        WebDriver driver8 = getDriver("http://172.21.1.4:8989/wd/hub", caps);
        timeAfter = System.currentTimeMillis();
         cal = timeAfter - timeBefore;
         currectpage(driver8, "driver8 in http://172.21.1.4","connecting client system", cal);
         timeBefore = System.currentTimeMillis();
        WebDriver driver9 = getDriver("http://172.21.1.89:8989/wd/hub", caps);
        timeAfter = System.currentTimeMillis();
         cal = timeAfter - timeBefore;
         currectpage(driver9, "driver9 in http://172.21.1.89","connecting client system", cal);
         timeBefore = System.currentTimeMillis();
        WebDriver driver10 = getDriver("http://172.21.1.4:8989/wd/hub", caps);
        timeAfter = System.currentTimeMillis();
         cal = timeAfter - timeBefore;
         currectpage(driver10, "driver10 in http://172.21.1.89","connecting client system", cal);
        List<WebDriver> drivers = new ArrayList<WebDriver>();
        List<String> usernames = new ArrayList<String>();
        List<String> passwords = new ArrayList<String>();
        if (driver1 != null) {
            drivers.add(driver1);
            usernames.add("test");
            passwords.add("test1");
        }
        if (driver2 != null) {
            drivers.add(driver2);
            usernames.add("user1");
            passwords.add("user1");
        }
        if (driver3 != null) {
            drivers.add(driver3);
            usernames.add("user2");
            passwords.add("user2");
        }
        if (driver4 != null) {
            drivers.add(driver4);
            usernames.add("user3");
            passwords.add("user3");
        }
        if (driver5 != null) {
            drivers.add(driver5);
            usernames.add("user4");
            passwords.add("user4");
        }
        if (driver6 != null) {
            drivers.add(driver6);
            usernames.add("user5");
            passwords.add("user5");
        }
        if (driver7 != null) {
            drivers.add(driver7);
            usernames.add("user6");
            passwords.add("user6");
        }
        if (driver8 != null) {
            drivers.add(driver8);
            usernames.add("user7");
            passwords.add("user7");
        }
        if (driver9 != null) {
            drivers.add(driver9);
            usernames.add("user8");
            passwords.add("user8");
        }
        if (driver10 != null) {
            drivers.add(driver10);
            usernames.add("test");
            passwords.add("test");
        }

        for (WebDriver driver : drivers) {
            driver.get("http://172.21.1.4/sspjuly08/");

        }
        System.out.println("OPENED ALL");
        // Sending the UserName
             drive=0;
        for (int i = 0; i < drivers.size(); i++) {
            drive++;
            timeBefore = System.currentTimeMillis();
            executeUsernameForAllURLs(urls, By.xpath("//*[@id='txtUserName']"),
                    caps, drivers.get(i), usernames.get(i));
            timeAfter = System.currentTimeMillis();
             cal = timeAfter - timeBefore;
             currectpage(drivers.get(i), "driver"+drive+".... in "+drivers.get(i).getCurrentUrl().toString(),"Passing the username", cal);

        }
         drive=0;
        for (int i = 0; i < drivers.size(); i++) {
            drive++;
            timeBefore = System.currentTimeMillis();
            executePasswordForAllURLs(urls, By.xpath("//*[@id='txtPassword']"),
                    caps, drivers.get(i), usernames.get(i));
            timeAfter = System.currentTimeMillis();
             cal = timeAfter - timeBefore;
             currectpage(drivers.get(i), "driver"+drive+".... in "+drivers.get(i).getCurrentUrl().toString(),"Passing the password", cal);
        }
        drive=0;
        for (WebDriver driver : drivers) {
            drive++;
            try {
                timeBefore = System.currentTimeMillis();
                executeClickForAllURLs(urls, By.xpath("//*[@id='imgLogin']"), caps,
                        driver);
                timeAfter = System.currentTimeMillis();
                 cal = timeAfter - timeBefore;
                 currectpage(driver, "driver"+drive+".... in "+driver.getCurrentUrl().toString(),"Clicking the Login button", cal);
            } catch (Exception e) {
                e.printStackTrace();
                writeToFile("Error has been accured in client "+drive+"\n");
            }
        }
        drive=0;
        for (WebDriver driver : drivers) {
            drive++;
            try {
                timeBefore = System.currentTimeMillis();
                executeClickForAllURLs(
                        urls,
                        By.xpath("//*[@id='ctl00_ContentPlaceHolder1_idImage']/table/tbody/tr[7]/td[1]/a/img"),
                        caps, driver);
                timeAfter = System.currentTimeMillis();
                 cal = timeAfter - timeBefore;
                 currectpage(driver, "driver"+drive+".... in "+driver.getCurrentUrl().toString(),"Clicking the SMS module", cal);
            } catch (Exception e) {
                e.printStackTrace();
                writeToFile("Error has been accured in client "+drive+"\n");
            }
        }
        drive=0;
        for (WebDriver driver : drivers) {
            drive++;
            try {
                timeBefore = System.currentTimeMillis();
                driver.get("http://172.21.1.4/sspjuly08/Module/SMS/SMSBrowse.aspx");
                timeAfter = System.currentTimeMillis();
                 cal = timeAfter - timeBefore;
                 currectpage(driver, "driver"+drive+".... in "+driver.getCurrentUrl().toString(),"Open the SendSMS page", cal);
            } catch (Exception e) {
                e.printStackTrace();
                writeToFile("Error has been accured in client "+drive+"\n");
            }
        }

        drive=0;
        for (WebDriver driver : drivers) {
            drive++;
            // Click the homework tab to send sms 
            try {
                timeBefore = System.currentTimeMillis();
                executeClickForAllURLs(
                        urls,
                        By.xpath("//*[@id='__tab_ctl00_ContentPlaceHolder1_tcPnlView_Homework']"),
                        caps, driver);
                timeAfter = System.currentTimeMillis();
                 cal = timeAfter - timeBefore;
                 currectpage(driver, "driver"+drive+".... in "+driver.getCurrentUrl().toString(),"click the HOmework tab to send the sms", cal);
            } catch (Exception e) {
                e.printStackTrace();
                writeToFile("Error has been accured in client "+drive+"\n");
            }
        }

        drive=0;
        for (WebDriver driver : drivers) {
            // sending the value of Homework date
            drive++;
            try {
                timeBefore = System.currentTimeMillis();
                SendHomeworkdateForAllURLs(urls,
                        By.name("txtDate"), caps,
                        driver);
                timeAfter = System.currentTimeMillis();
                 cal = timeAfter - timeBefore;
                 currectpage(driver, "driver"+drive+".... in "+driver.getCurrentUrl().toString(),"Sending the Homework date", cal);

            } catch (Exception e) {
                e.printStackTrace();
                writeToFile("Error has been accured in client "+drive+"\n");
            }
        }
        drive=0;
        for (WebDriver driver : drivers) {
            drive++;
            // Click the class from the list
            try {
                timeBefore = System.currentTimeMillis();
                executeClickForAllURLs(
                        urls,
                        By.xpath("//*[@id='txtDisplayClass']"),
                        caps, driver);
                executeClickForAllURLs(
                        urls,
                        By.xpath("//*[@id='chkClass_0']"),
                        caps, driver);
                timeAfter = System.currentTimeMillis();
                 cal = timeAfter - timeBefore;
                 currectpage(driver, "driver"+drive+".... in "+driver.getCurrentUrl().toString(),"click the class from the combo", cal);
            } catch (Exception e) {
                e.printStackTrace();
                writeToFile("Error has been accured in client "+drive+"\n");
            }
        }


        drive=0;
        for (WebDriver driver : drivers) {
            drive++;
            // Click the go Button
            try {
                timeBefore = System.currentTimeMillis();
                executeClickForAllURLs(
                        urls,
                        By.xpath("//*[@id='btnGo_B']"),
                        caps, driver);
                timeAfter = System.currentTimeMillis();
                 cal = timeAfter - timeBefore;
                 currectpage(driver, "driver"+drive+".... in "+driver.getCurrentUrl().toString(),"click the Go button", cal);
            } catch (Exception e) {
                e.printStackTrace();
                writeToFile("Error has been accured in client "+drive+"\n");
            }
        }
        drive=0;
        for (WebDriver driver : drivers) {
            drive++;
            // Sending the homework through sms
            try {
                timeBefore = System.currentTimeMillis();
                SendHomeworkDescriptionForAllURLs(
                        urls,
                        By.xpath("//*[@id='gvHomework_ctl02_txtHomework']"),
                        caps, driver);
                timeAfter = System.currentTimeMillis();
                 cal = timeAfter - timeBefore;
                 currectpage(driver, "driver"+drive+".... in "+driver.getCurrentUrl().toString(),"Send the sms for the home work", cal);

            } catch (Exception e) {
                e.printStackTrace();
                writeToFile("Error has been accured in client "+drive+"\n");
            }
        }

        drive=0;
        for (WebDriver driver : drivers) {
            drive++;
            // Sending the homework through sms
            try {
                timeBefore = System.currentTimeMillis();
                SendHomeworkDescriptionForAllURLs(
                        urls,
                        By.xpath("//*[@id='gvHomework_ctl03_txtHomework']"),
                        caps, driver);
                timeAfter = System.currentTimeMillis();
                 cal = timeAfter - timeBefore;
                 currectpage(driver, "driver"+drive+".... in "+driver.getCurrentUrl().toString(),"Send the sms for the home work", cal);

            } catch (Exception e) {
                e.printStackTrace();
                writeToFile("Error has been accured in client "+drive+"\n");
            }
        }
        drive=0;
        for (WebDriver driver : drivers) {
            drive++;
            // Sending the homework through sms
            try {
                timeBefore = System.currentTimeMillis();
                SendHomeworkDescriptionForAllURLs(
                        urls,
                        By.xpath("//*[@id='gvHomework_ctl04_txtHomework']"),
                        caps, driver);
                timeAfter = System.currentTimeMillis();
                 cal = timeAfter - timeBefore;
                 currectpage(driver, "driver"+drive+".... in "+driver.getCurrentUrl().toString(),"Send the sms for the home work", cal);

            } catch (Exception e) {
                e.printStackTrace();
                writeToFile("Error has been accured in client "+drive+"\n");
            }
        }
        drive=0;
        for (WebDriver driver : drivers) {
            drive++;
            // Sending the homework through sms
            try {
                timeBefore = System.currentTimeMillis();
                SendHomeworkDescriptionForAllURLs(
                        urls,
                        By.xpath("//*[@id='gvHomework_ctl05_txtHomework']"),
                        caps, driver);
                timeAfter = System.currentTimeMillis();
                 cal = timeAfter - timeBefore;
                 currectpage(driver, "driver"+drive+".... in "+driver.getCurrentUrl().toString(),"Send the sms for the home work", cal);

            } catch (Exception e) {
                e.printStackTrace();
                writeToFile("Error has been accured in client "+drive+"\n");
            }
        }
        drive=0;
        for (WebDriver driver : drivers) {
            drive++;
            // Sending the homework through sms
            try {
                timeBefore = System.currentTimeMillis();
                SendHomeworkDescriptionForAllURLs(
                        urls,
                        By.xpath("//*[@id='gvHomework_ctl06_txtHomework']"),
                        caps, driver);
                timeAfter = System.currentTimeMillis();
                 cal = timeAfter - timeBefore;
                 currectpage(driver, "driver"+drive+".... in "+driver.getCurrentUrl().toString(),"Send the sms for the home work", cal);

            } catch (Exception e) {
                e.printStackTrace();
                writeToFile("Error has been accured in client "+drive+"\n");
            }
        }
        drive=0;
        for (WebDriver driver : drivers) {
            drive++;
            // Sending the homework through sms
            try {
                timeBefore = System.currentTimeMillis();
                SendHomeworkDescriptionForAllURLs(
                        urls,
                        By.xpath("//*[@id='gvHomework_ctl07_txtHomework']"),
                        caps, driver);
                timeAfter = System.currentTimeMillis();
                 cal = timeAfter - timeBefore;
                 currectpage(driver, "driver"+drive+".... in "+driver.getCurrentUrl().toString(),"Send the sms for the home work", cal);

            } catch (Exception e) {
                e.printStackTrace();
                writeToFile("Error has been accured in client "+drive+"\n");
            }
        }
        drive=0;
        for (WebDriver driver : drivers) {
            drive++;
            // Sending the homework through sms
            try {
                timeBefore = System.currentTimeMillis();
                SendHomeworkDescriptionForAllURLs(
                        urls,
                        By.xpath("/*[@id='gvHomework_ctl08_txtHomework']"),
                        caps, driver);
                timeAfter = System.currentTimeMillis();
                 cal = timeAfter - timeBefore;
                 currectpage(driver, "driver"+drive+".... in "+driver.getCurrentUrl().toString(),"Send the sms for the home work", cal);

            } catch (Exception e) {
                e.printStackTrace();
                writeToFile("Error has been accured in client "+drive+"\n");
            }
        }
        drive=0;
        for (WebDriver driver : drivers) {
            drive++;
            // Sending the homework through sms
            try {
                timeBefore = System.currentTimeMillis();
                SendHomeworkDescriptionForAllURLs(
                        urls,
                        By.xpath("//*[@id='gvHomework_ctl09_txtHomework']"),
                        caps, driver);
                timeAfter = System.currentTimeMillis();
                 cal = timeAfter - timeBefore;
                 currectpage(driver, "driver"+drive+".... in "+driver.getCurrentUrl().toString(),"Send the sms for the home work", cal);

            } catch (Exception e) {
                e.printStackTrace();
                writeToFile("Error has been accured in client "+drive+"\n");
            }
        }
        drive=0;
        for (WebDriver driver : drivers) {
            drive++;
            // Sending the homework through sms
            try {
                timeBefore = System.currentTimeMillis();
                SendHomeworkDescriptionForAllURLs(
                        urls,
                        By.xpath("//*[@id='gvHomework_ctl10_txtHomework']"),
                        caps, driver);
                timeAfter = System.currentTimeMillis();
                 cal = timeAfter - timeBefore;
                 currectpage(driver, "driver"+drive+".... in "+driver.getCurrentUrl().toString(),"Send the sms for the home work", cal);

            } catch (Exception e) {
                e.printStackTrace();
                writeToFile("Error has been accured in client "+drive+"\n");
            }
        }
        drive=0;
        for (WebDriver driver : drivers) {
            drive++;
            // Sending the homework through sms
            try {
                timeBefore = System.currentTimeMillis();
                SendHomeworkDescriptionForAllURLs(
                        urls,
                        By.xpath("//*[@id='gvHomework_ctl11_txtHomework']"),
                        caps, driver);
                timeAfter = System.currentTimeMillis();
                 cal = timeAfter - timeBefore;
                 currectpage(driver, "driver"+drive+".... in "+driver.getCurrentUrl().toString(),"Send the sms for the home work", cal);

            } catch (Exception e) {
                e.printStackTrace();
                writeToFile("Error has been accured in client "+drive+"\n");
            }
        }

        drive=0;
        for(WebDriver driver:drivers){
            drive++;
            //capturing the message
            try {
                String message="The Record has been successfully saved";
                WebElement successmessage=dri.findElement(By.xpath("//*[@id='ctl00_ContentPlaceHolder1_lblMessage']"));
                if(successmessage.getText().toString().equalsIgnoreCase(message)){
                    currectpage(driver, "driver"+drive+".... in "+driver.getCurrentUrl().toString(),"The Record has been successfully saved", cal);
                }
                else{
                    writeToFile("The saved message is not shown "+drive+"\n");
                }
            } catch (Exception e) {
                e.printStackTrace();
                writeToFile("Error has been accured in client "+drive+"\n");
            }

        }


    }

    public void executeUsernameForAllURLs(String[] urls, By by,
            DesiredCapabilities caps, WebDriver driver, String username)
            throws MalformedURLException {

        driver.findElement(by).sendKeys(username);

    }

    public void executePasswordForAllURLs(String[] urls, By by,
            DesiredCapabilities caps, WebDriver driver, String password)
            throws MalformedURLException {

        driver.findElement(by).sendKeys(password);

    }

    public void executeClickForAllURLs(String[] urls, By by,
            DesiredCapabilities caps, WebDriver driver)
            throws MalformedURLException {

        driver.findElement(by).click();

    }

    public void ExcuteStudentClearValueForAllURLs(String[] urls, By by,
            DesiredCapabilities caps, WebDriver driver)
            throws MalformedURLException {

        driver.findElement(by).clear();

    }

    public void SendHomeworkdateForAllURLs(String[] urls, By by,
            DesiredCapabilities caps, WebDriver driver)
            throws MalformedURLException {

        driver.findElement(by).sendKeys("01/08/2013");

    }

    public void SendHomeworkDescriptionForAllURLs(String[] urls, By by,
            DesiredCapabilities caps, WebDriver driver)
            throws MalformedURLException {

        driver.findElement(by).sendKeys("test" + new Integer(num++).toString());

    }

    public void SelectingthesubjectForAllURLs(String[] urls, By by,
            DesiredCapabilities caps, WebDriver driver)
            throws MalformedURLException {

        new Select(driver.findElement(by)).selectByVisibleText("ENGLISH");

    }

    public void SendingtheClassForAllURLs(String[] urls, By by,
            DesiredCapabilities caps, WebDriver driver)
            throws MalformedURLException {

        new Select(driver.findElement(by)).selectByVisibleText("VI A");

    }

    public void currectpage(WebDriver driver, String clintname,
            String EventPage, long timeTaken) {
        String page = driver.getCurrentUrl();
        if (page.toString().equalsIgnoreCase(error.toString())) {

            errorpage(clintname);
        } else {
            writeToFile(clintname + "\t" + EventPage + "\t" + timeTaken+"\n");
        }
    }

    public void errorpage(String clintname) {
        writeToFile(clintname + "\tShowing the runtime error\n");
    }

    public static void main(String[] args) throws MalformedURLException,
            InterruptedException, UnknownHostException {
        ConcurrentTestSMS te = new ConcurrentTestSMS();
        te.setup("WINDOWS", "Firefox", "18.0.1",
                "http://172.21.1.89:8989/wd/hub");
    }
}
导入java.io.File; 导入java.io.FileNotFoundException; 导入java.io.FileOutputStream; 导入java.io.IOException; 导入java.net.InetAddress; 导入java.net.MalformedURLException; 导入java.net.URL; 导入java.net.UnknownHostException; 导入java.util.ArrayList; 导入java.util.List; 导入net.sourceforge.htmlunit.corejs.javascript.ast.with语句; 导入org.apache.commons.io.FileUtils; 导入org.openqa.selenium.By; 导入org.openqa.selenium.OutputType; 导入org.openqa.selenium.TakesScreenshot; 导入org.openqa.selenium.WebDriver; 导入org.openqa.selenium.WebElement; 导入org.openqa.selenium.net.INetAddress; 导入org.openqa.selenium.remote.DesiredCapabilities; 导入org.openqa.selenium.remote.RemoteWebDriver; 导入org.openqa.selenium.support.ui.Select; 公共类ConcurrentTestSMS{ 公共WebDriver dri=null; 私有文件; 私有文件输出流; 字符串错误=”http://ip/sspjuly08/Errorpage.aspx"; 很久以前的公众; 公众长期关注; 公共长cal; 公共int驱动; 公共ConcurrentTestSMS(){ //初始化文件对象 file=新文件(“D:\\concorentTestingsmsLog.xls”); 试一试{ //创造新的